How do I write a Matlab function to draw a regular polygon.
Show older comments
Using the heading function drawPolygon(n, r, colstyle)
where n=no of sides
r= is the radius of the circle that would be large enough to enclose the polygon
colstyle=is the colour and line style to be used for the plotting
Answers (1)
Walter Roberson
on 14 May 2013
0 votes
If you think about following along the circle, if you do not start at a vertex, then after passing "n" vertices, you return to the starting point. The polygon is regular, so the sides must be equal, so the angles must be equal. So then, at what fraction of the circle must the angle between one vertex and the next cover?
Now, how would you find the list of points that are (for example) all Pi/17 radian apart on a circle of radius "r" ?
Categories
Find more on Elementary Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!