# Points of Regular Polygon

hh hh at hyperhh.de
Tue Nov 29 13:46:39 EST 2016

```Why not simply computing the points by yourself?

Excerpt from the the main script of
Raspi stack #2: RegularPolygons3
(http://forums.livecode.com/viewtopic.php?p=98716#p98716)

-- N is the number of vertices
-- x0,y0 is the center of the polygon
-- r is the radius of the polygon
-- b is the angle of rotation in degrees
-- (positive b turns clockwise, negative b turns ccw)
function regularPoints n,r,x0,y0,b
put 2*pi/n into cn
-- n vertices --> n+1 points if 'closed' polygon
-- usually done by setting last=first
-- This is here true as sin(0)=sin(2*pi) and cos(0)=cos(2*pi)
put empty into pts
if b=0 or b is empty then
## compute unrotated n+1 vertices of the n-sided regular polygon
repeat with j=0 to n
put CR & (round(r*sin(j*cn)+x0),round(-r*cos(j*cn)+y0)) after pts
end repeat
else
## compute *rotated* n+1 vertices of the n-sided regular polygon
put sin(pi*b/180) into s; put cos(pi*b/180) into c
repeat with j=0 to n
put round( r*sin(j*cn)) into sx; put round(-r*cos(j*cn)) into sy
put CR & ( (round(x0+c*sx-s*sy),round(y0+c*sy+s*sx)) ) after pts
end repeat
end if
return char 2 to -1 of pts
end regularPoints

```

More information about the use-livecode mailing list