How to find smallest angle of rotation between two polygons

216 Views Asked by At

I have two polygons (e.g. two triangles) with mutual centre and I need to reconcile these polygons so that the sum of squares of distances between the vertices of one polygon and the other is minimal

I tried to do this by minimizing the sum of the squared distances of all combinations of vertices of two polygons using the polar coordinate system but it's not work

Distance in square between two points in polar coordinates is:

$$\rho_{1}^{2}\rho_{2}^{2}-2\rho_{1}\rho_{2}cos(\phi_{1}-\phi_{2})$$

Hence sum in square is $\phi$ is angle of the rotation second polygon):

$$\sum_{i,j}(\rho_{i}^{2}\rho_{j}^{2}-2\rho_{i}\rho_{j}\cos(\phi_{i}-\phi_{j}-\phi))\rightarrow min$$

Then (e.g. using golden-section search) I find unknow angle

For example:

Two triangles: Coordinates in polar sistem

First - (1;0), (1;135), (1,225)

Second - (1,45), (1;180), (1;315)

Sum of squares is:

9 - 2cos(0-45-x)-2cos(0-180-x)-2cos(0-315-x)-2cos(135-45-x)-2cos(135-180-x)-2cos(135-315-x)-2cos(225-45-x)-2cos(225-180-x)-2cos(225-315-x)

...golden-section...(a,b = -$\pi$,$\pi$)

Angle is -119.44...

But angle must be 180 (or -180)

1

There are 1 best solutions below

3
On

If you simply rotate the second triangle 45 degrees clockwise, it appears that the first two point sets will coincide and the third point sets will be only 45 degrees away from each other. Another 45 degrees would make the 3rd points coincide but then the first two would be off by 45 degrees each as they are now. I think the simplest solution is a single 45 degree rotation.