Potentially useful code snippets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

16 lines
750 B

Cartesian coordinates for regular polygons:
https://stackoverflow.com/questions/7198144/how-to-draw-a-n-sided-regular-polygon-in-cartesian-coordinates
Let's assume you want to draw an N-sided polygon of radius r, centred at (0,0). Then the n vertices are given by:
x[n] = r * cos(2*pi*n/N)
y[n] = r * sin(2*pi*n/N)
where 0 <= n < N. Note that cos and sin here are working in radians, not degrees (this is pretty common in most programming languages).
If you want a different centre, then just add the coordinates of the centre point to each (x[n], y[n]). If you want a different orientation, you just need to add a constant angle. So the general form is:
x[n] = r * cos(2*pi*n/N + theta) + x_centre
y[n] = r * sin(2*pi*n/N + theta) + y_centre