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