nsidedpoly
Creates a regular polygon with a given number of sides, as a polyshape.
Category: Mathematics > Computational Geometry
Syntax
pshape = nsidedpoly(n)
Regular n-gon centered at the origin with unit circumradius.
pshape = nsidedpoly(n, 'Center', c, 'Radius', r)
Sets the center c = [x y] and the circumradius r.
pshape = nsidedpoly(n, 'Center', c, 'SideLength', s)
Sets the side length instead of the radius.
Description
The vertices lie on a circle and are equally spaced. The area is n/2 * r^2 * sin(2*pi/n), so a hexagon with unit radius has area about 2.598. With a large n the polygon approaches a disc, which is a simple way to build a circular region as a polyshape.
Input arguments
n- Number of sides, an integer of at least 3.
'Center'- Two-element vector with the center. Default
[0 0]. 'Radius'- Distance from the center to each vertex. Default
1. 'SideLength'- Length of each side; cannot be combined with
'Radius'.
Output arguments
pshape- A
polyshapewithnvertices.
Example
Hexagon area and perimeter
H = nsidedpoly(6);
disp(numsides(H))
disp(area(H))
disp(perimeter(H))
Output
6
2.5981
6