Drag the point around the circle. cos is how far right it is, sin is how far up it is, and tan is the slope of the line from the centre through it.
A circle of radius 1. Drag the point, click anywhere on the circle, or focus it and use the arrow keys. Hold Shift for 15° steps.
|
cos θ x position, adjacent / hypotenuse |
||
|
sin θ y position, opposite / hypotenuse |
||
|
tan θ slope, sin / cos |
Unroll the circle: sin and cos are the height and width of the point as the angle grows. Click or drag here too.
Turn a distance and an angle into x and y. Then the four places this usually goes wrong.
Math.sin(90) treats 90 as 90 radians, about 14.3 full
turns, and returns 0.894. Convert first:
Math.sin(90 * Math.PI / 180) is 1.
Math.cos returns about 6e-17, not 0,
because π/2 can’t be stored exactly. Compare with a
tolerance, never with ==. The
Float lab shows what’s really stored.
y = r * Math.sin(angle) draws your
circle upside down. Subtract instead:
y = centerY - r * Math.sin(angle), as this page does.