nsidedpoly
Regular polygon
Description
pgon = nsidedpoly(
returns a regular
polygon with n
)n
equal-length sides. The center of
pgon
is at the point (0,0), and the circumscribed circle of
the polygon has radius 1.
pgon = nsidedpoly(
specifies additional properties of the polygon using one or more name-value pair
arguments. For example, n
,Name,Value
)pgon = nsidedpoly(4,'SideLength',5)
creates a square centered at (0,0) with sides of length 5.
Examples
Hexagon
Create a hexagon with sides of length 1 centered at the point (0,0). Then, create a hexagon with sides of length 3 centered at (5,0).
pgon1 = nsidedpoly(6); pgon2 = nsidedpoly(6,'Center',[5 0],'SideLength',3); plot([pgon1 pgon2]) axis equal
Input Arguments
n
— Number of sides
positive scalar integer
Number of sides of the polygon, specified as a positive scalar integer greater than 2.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: pgon = nsidedpoly(3,'Radius',10)
Center
— Center point
1-by-2 row vector
Center point of the polygon, specified as the comma-separated pair
consisting of 'Center'
and a 1-by-2 row vector whose
first element is the x-coordinate of the point and
whose second element is the y-coordinate.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Radius
— Radius
positive scalar
Radius of the circumscribed circle of the polygon, specified as the
comma-separated pair consisting of 'Radius'
and a
positive scalar. This name-value pair cannot be combined with the
'SideLength'
name-value pair.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
SideLength
— Side length
positive scalar
Side length of polygon, specified as the comma-separated pair
consisting of 'SideLength'
and a positive scalar.
This name-value pair cannot be combined with the
'Radius'
name-value pair.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Names must be compile-time constant in name-value arguments.
Dynamic memory allocation must be enabled.
A
polyshape
object must not be an input or output of an entry-point function.A
polyshape
object outside a loop cannot refer to apolyshape
object allocated inside a loop. For more information, see Handle Object Limitations for Code Generation (MATLAB Coder).
Version History
Introduced in R2017b
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)