Click here to Skip to main content
12,952,215 members (61,506 online)
Rate this:
 
Please Sign up or sign in to 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 9-Jan-13 2:09am
Updated 9-Jan-13 2:19am
v2
Comments
ryanb31 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#...
ryanb31 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?
   
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 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
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

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2017
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