Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Updated 9-Jan-13 2:19am
v2
Comments
ZurdoDev 9-Jan-13 8:10am    
So, what exactly is your issue? What do you have so far?
rumailamalik 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#...
ZurdoDev 9-Jan-13 8:41am    
We can't see what code you have; therefore, we can't help you.
rumailamalik 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 9-Jan-13 15:37pm    
whats the starting point of the line? from center of the circle?

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[^]
 
Share this answer
 
v2
http://go4answers.webhost4life.com/Example/circle-center-angle-points-circle-167588.aspx[^]
C#
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;
}
 
Share this answer
 
v2
C#
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)
        {
            
        }

    }
}
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900