Alex Rivera | Logout

finding a dot on a circle by degree?

Asked 2011-06-08T14:06:15.767
9

Let's say we have a 100x100 coordinate system, like the one below. 0,0 is its left-top corner, 50,50 is its center point, 100,100 is its bottom right corner, etc.

Now we need to draw a line from the center outwards. We know the angle of the line, but need to calculate the coordinates of its end point. What do you think would be the best way to do it?

For example, if the angle of the line is 45 degrees, its end point coordinates would be roughly 75,15.

enter image description here

Edit
Report

1 Answer

13

You need to use the trigonometric functions sin and cos.

Something like this:

theta = 45
// theta = pi * theta / 180      // convert to radians.
radius = 50
centerX = 50
centerY = 50
p.x = centerX + radius * cos(theta)
p.y = centerY - radius * sin(theta)

Keep in mind that most implementations assume that you're working with radians and have positive y pointing upwards.

answered 2011-06-08T14:08:41.197

Your Answer