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 }
.
1 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
-
1\$\begingroup\$ Keep in mind that the angle should be in radians. \$\endgroup\$– bummzackOct 10, 2011 at 11:21
-
\$\begingroup\$ Depends on the math library, but good point, XNA/.Net uses radians. \$\endgroup\$ Oct 10, 2011 at 11:27
-
\$\begingroup\$ Why the old Arab was to howl? Here we are not all English speakers so a conceptual memonic rule is far better than a mnemonic sentence \$\endgroup\$– FxIIIOct 10, 2011 at 12:38
-
1\$\begingroup\$ @FxIII: True, it's not the most popular memonic, however i've always found it easy to remember than SOHCAHTOA as it's unusual. \$\endgroup\$ Oct 10, 2011 at 13:01
-
\$\begingroup\$ Or you could just look it up, once you are familiar with the concept, the once or twice a year that you need it. \$\endgroup\$– TetradOct 10, 2011 at 15:29