I created these images way back in 2019 before I learned programming:
Now I am trying to programmatically generate images like them using Python.
Basically, I want to make something like this:
In short, you start off with a regular polygon with n sides, then you create new regular polygon of the same number of sides such that the vertices of the new polygon are on the sides of the original polygon, and each of the sides of the new polygon and the corresponding side in the original polygon form an angle of x degrees.
Then you create a new regular polygon with n sides whose vertices are on the second polygon and the pairs of corresponding sides also form an angle of x degrees. And then you recursively do this until a certain number of iterations is reached.
I want to know given the number of sides of the polygon, and the angle of rotation, how to calculate the corresponding distance the vertices need to be displaced along its sides.
For example, I have calculated the cases of squares and equilateral triangles:
For the square, let its side be s, the angle be a, it is easy to see the two legs of the right triangle formed by the rotated side and the original sides add together to s.
let x be the distance needed, let y be s - x.
It is easy to see y = x / tan(a)
x+y=s
y=x/tan(a)
x+x/tan(a)=s
x = s*tan(a)/(tan(a)+1)
So the vertices need to be displaced along the sides by s*tan(a)/(tan(a)+1)
For the equilateral triangle it is harder to calculate the distance needed, but if you draw a line from one of the rotated vertices perpendicular to its corresponding side in the original triangle, the right triangle formed by the operation will always contain a 30° angle.
Let x be the amount of displacement needed, and let y be s - x, x can be calculated with the following:
x + y = s
y = x/2 + x*cos(30°)/tan(a)
x + x/2 + x*cos(30°)/tan(a) = s
3x/2 + x*cos(30°)/tan(a) = s
x*(3/2+cos(30°)/tan(a))=s
x=s/(3/2+cos(30°)/tan(a))
Unfortunately my knowledge of geometry stops here, I can't calculate the amount of displacement of the vertices along the sides needed for regular polygons with more sides.
I know how to calculate the coordinates of vertices of regular polygon of given number of sides, I just don't know the amount of displacement corresponding to angles. Can anyone generalize the calculations I used?
Fixed logical reasoning errors in the question body, I was busy with other things so I didn't notice the error until now.