The code below creates a MATLAB function that takes the number of sides n
and the length of each side l
as input and returns the location of the polygon vertices in a matrix vertices
.
main.m354 chars13 lines
To use this function in MATLAB, simply pass in the number of sides and the length of each side as arguments. For example, to create the vertices of a regular pentagon with side length 2:
main.m153 chars8 lines
The output vertices
is a 5x2 matrix, where each row represents the x and y coordinates of a vertex.
gistlibby LogSnag