home/ atoms/ processing-trigonometry-sin-cos

sin() and cos() convert angles to unit-circle coordinates, enabling circular motion and oscillation

For an angle in radians, cos() gives the x-component and sin() gives the y-component on a unit circle. Multiplying by a radius r and offsetting by a centre point gives x = cx + cos(angle)*r, y = cy + sin(angle)*r. This pattern produces circles, arcs, spirals, and wave patterns. Processing’s PI, HALF_PI, QUARTER_PI, and TWO_PI constants simplify radian arithmetic. The radians() and degrees() functions convert between units. Iterating angle from 0 to TWO_PI at small steps traces a full circle; stopping partway draws an arc.

Examples

int radius = 38; for (int deg = 0; deg < 360; deg += 12) { float angle = radians(deg); float x = 50 + (sin(angle) * radius); float y = 50 + (cos(angle) * radius); ellipse(x, y, 6, 6); }

Assessment

Write code that positions 8 equally spaced circles around a centre point at radius 40; then modify it to animate a single circle orbiting that centre.

“Because sin() and cos() return numbers between -1.0 and 1.0, the result is multiplied by the radius variable to draw a circle with radius 38.”
corpus · processing-handbook-no-login-mirror-pdf-reas-and-fry · chunk 33