I would like to know how to get a specific point on the circumference of a circle, given an angle. The diameter of the circle is 1, and the center point of the circle is { X: 0.5, Y: 0.5 }
.
Answer
You can work this out using basic trigonometry. http://www.freehomeworkmathhelp.com/Trigonometry/Trigonometry_Introduction/trigonometry.html
Tan(angle) = Opposite / Adjacent
Sin(angle) = Opposite / Hypotenuse
Cos(angle) = Adjacent / Hypotenuse
I always remember the above as
The Old Arab
Sat On His
Camel And Howled
The above means if we have the angle and one length of a right-angled triangle we can work out the lengths of the other sides. Luckly your problem can be thought of as calculating the length of triangle sides:
Above, r is the hypotenuse, x is the adjacent and y is the opposite.
So for x:
Cos(a) = x / r
Cos(a) * r = x
x = Cos(a) * r
And for y:
Sin(a) = y / r
Sin(a) * r = y
y = Sin(a) * r
This is assuming a circle at (0, 0), so we just add on the circle's center.
radius = 1;
CenterX = 0.5;
CenterY = 0.5;
x = Cos(angle) * radius + CenterX;
Y = Sin(angle) * radius + CenterY;
Note: The C# Math functions use angles in radians, so if you have degrees convert them first:
radians = degrees * Math.PI / 180
No comments:
Post a Comment