Homework: Drawing a Pentagon

  1. Draw a pentagon like this.
  2. You may need to include <cmath> if you want to call the sin/cos functions.
    1. Note that in C library, the parameters passed to sin() and cos() are given in radians, rather than degrees.
    2. 180 ° (degree) is equal to π in radian, so 30 ° = π/6.
  3. If you want to use the constant M_PI, #define _USE_MATH_DEFINES before you include <cmath>.
  4. All you need to do is calculating the coordinates of the 5 vertices, and then connecting them by line segments.
    1. The rightmost vertex is (r cos 0, r sin 0).
    2. The (counterclockwise) second vertex is (r cos 2π/5, r sin 2π/5).
    3. The third vertex is (r cos 4π/5, r sin 4π/5).
    4. The fourth vertex is (r cos 6π/5, r sin 6π/5).
    5. The fifth vertex is (r cos 8π/5, r sin 8π/5).
ex-pentagon.png