Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i have a crcle having line.i want to do that if we enter numaric value in txt box (0-360). line move to that angle enter in textbox.
issue is how to move circle line in c# code to show angle between 0-360 degree.
Posted 9-Jan-13 2:09am
Edited 9-Jan-13 2:19am
v2
Comments
ryanb31 at 9-Jan-13 8:10am
   
So, what exactly is your issue? What do you have so far?
rumailamalik at 9-Jan-13 8:23am
   
ma issue is how to move that line acording to input. to show that input 01-360 degree in c#...
ryanb31 at 9-Jan-13 8:41am
   
We can't see what code you have; therefore, we can't help you.
rumailamalik at 9-Jan-13 9:18am
   
public void Rotate(int degrees)
{
this.orientation += degrees;
 
if (this.orientation < 0)
{
while (this.orientation < 0)
{
this.orientation += 360;
}
}
else if (this.orientation >= 360)
{
while (this.orientation >= 360)
{
this.orientation -= 360;
}
}
}
jibesh at 9-Jan-13 15:37pm
   
whats the starting point of the line? from center of the circle?
Sergey Alexandrovich Kryukov at 9-Jan-13 10:02am
   
What is "circle having line"? "Numaric"? "Line move to angle". I understand English is not your native language, but this is not just language, more of a sloppiness. And everyone can use a spellcheck, so wrong spelling is simply impolite...
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

http://go4answers.webhost4life.com/Example/circle-center-angle-points-circle-167588.aspx[^]
public Texture2D CreateCircle(int radius)
{
    int outerRadius = radius*2 + 2; // So circle doesn't go out of bounds
    Texture2D texture = new Texture2D(GraphicsDevice, outerRadius, outerRadius);
 
    Color[] data = new Color[outerRadius * outerRadius];
 
    // Colour the entire texture transparent first.
    for (int i = 0; i < data.Length; i++)
        data[i] = Color.Transparent;
 
    // Work out the minimum step necessary using trigonometry + sine approximation.
    double angleStep = 1f/radius;
 
    for (double angle = 0; angle < Math.PI*2; angle += angleStep)
    {
        // Use the parametric definition of a circle: http://en.wikipedia.org/wiki/
        int x = (int)Math.Round(radius + radius * Math.Cos(angle));
        int y = (int)Math.Round(radius + radius * Math.Sin(angle));
 
        data[y * outerRadius + x + 1] = Color.White;
    }
 
    texture.SetData(data);
    return texture;
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers();
 

namespace WindowsForms
{
    public partial class Form1 : Form
    {
        int circleDiameter;
              public Form1()
        {
            InitializeComponent();
            circleDiameter = 100;
        }
        
 
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Point CenterPoint = new Point()
            {
                X = this.ClientRectangle.Width / 2,
                Y = this.ClientRectangle.Height / 2
            };
            Point topLeft = new Point()
            {
              
 
                X = (this.ClientRectangle.Width - circleDiameter) / 2,
                Y = (this.ClientRectangle.Height - circleDiameter) / 2
              
    
        };
 

            Point topRight = new Point()
            {
                X = (this.ClientRectangle.Width + circleDiameter) / 2,
                Y = (this.ClientRectangle.Height - circleDiameter) / 2
            };
            Point bottomLeft = new Point()
            {
                X = (this.ClientRectangle.Width - circleDiameter) / 2,
                Y = (this.ClientRectangle.Height + circleDiameter) / 2
            };
            Point bottomRight = new Point()
            {
                X = (this.ClientRectangle.Width + circleDiameter) / 2,
                Y = (this.ClientRectangle.Height + circleDiameter) / 2
            };
 
            e.Graphics.DrawEllipse(Pens.Red, topLeft.X, topLeft.Y, circleDiameter, circleDiameter);
           
           e.Graphics.DrawLine(Pens.Red, CenterPoint, topLeft);
         
         //  e.Graphics.DrawLine(Pens.Black, CenterPoint, topRight);
        
       //     e.Graphics.DrawLine(Pens.Brown, CenterPoint, bottomLeft);
            
         //   e.Graphics.DrawLine(Pens.Orange, CenterPoint, bottomRight); 
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            
        }
 
    }
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

So at this point you have code that ensures your degrees value remains between 0 and 360. Where is your drawing code for the circle? The calculation for deciding where on a circle is a simple parametric equation.
how-do-i-calculate-a-point-on-a-circles-circumference[^]
Circle Equations[^]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Gihan Liyanage 332
1 Sergey Alexandrovich Kryukov 290
2 ClimerChinna 222
3 vikinghunter 178
4 OriginalGriff 161
0 Sergey Alexandrovich Kryukov 8,363
1 OriginalGriff 7,112
2 CPallini 2,598
3 Richard MacCutchan 2,025
4 Abhinav S 1,788


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100