How to find the rotational angle of triangle $DEF$ which is as close as possible to relative angle of triangle $ABC$?

62 Views Asked by At

I would center two triangles to the origo and find out three different positions of triangle $ΔDEF$, and select the one of those, that differs as little as possible from the orientation of triangle $ΔABC$.

1.

$ΔABC$ has a $Centroid_a = (A+B+C) / 3$

$ΔDEF$ has a $Centroid_b = (D+E+F) / 3$

From $Centroid_a$ we get vectors to $vA$, $vB$ and $vC$.

From $Centroid_b$ we get vectors to $vD$, $vE$ and $vF$.

2.

Then we translate both triangles to origo (without losing shape or size).

3a.

Next we rotate triangle $ΔDEF$ so that vectors $vA$ and $vD$ match each others. Calculate absolute difference of rotation of $∠vB - ∠vE + ∠vC - ∠vF$.

3bc.

Repeat by matching $vA$ and $vE$, and finally by matching $vA$ and $vF$.

4.

Finally find out the smallest rotation and rotate triangle $ΔDEF$ accordingly.

Is this the way to find out the minimal orientation difference between two triangles and/or what is the optimal algorithm to find it out?

Addition

Reflection / flipping discussion could be part of the optimization. Picture below shows the case, when rotation in Procrustes analysis is often unrecognizing reflections of the plane objects.

enter image description here

Further testing the case according to excellent answer given by @JeanMarie can be done in: https://www.geogebra.org/m/h2V7xZ9j

1

There are 1 best solutions below

8
On BEST ANSWER

Let us denote by $z_1,z_2,z_3$ (resp. $z'_1,z'_2,z'_3$) the complex numbers associated with the first (resp. second) triangle $T$ (resp. $T'$).

We look for the angle $\theta$ that has to be applied to the first triangle in order that its rotated image $R_{\theta}T$, i.e., $e^{i\theta}z_1,e^{i\theta}z_2,e^{i\theta}z_3$, is the closest possible to triangle $T'$.

The most classical minimization criterion is in the sense of least squares, i.e., we look for an angle $\theta$ such as the sum of the squares or the resp. distances:

$$|e^{i\theta}z_1-z'_1|^2+|e^{i\theta}z_2-z'_2|^2+|e^{i\theta}z_3-z'_3|^2$$

is minimal. In short the objective is to:

$$\tag{1} \text{Minimize} \ \ \ \sum_{k=1}^3|e^{i\theta}z_k-z'_k|^2$$

(for $\theta$). Using formula $|Z-Z'|^2=|Z|^2+|Z'|^2-2 \Re(\bar{Z}Z'),$ (1) becomes:

$$\text{Minimize} \ \ \ \sum_{k=1}^3|e^{i\theta}z_k|^2 + \sum_{k=1}^3|z'_k|^2 - 2 \sum_{k=1}^3 \Re (e^{-i \theta} \bar{z_k}z'_k)$$

But $|e^{-i\theta}z_k|=|z_k|$. Thus, the issue becomes:

$$\tag{2} \text{Minimize} \ \ \ \sum_{k=1}^3|z_k|^2 + \sum_{k=1}^3|z'_k|^2 - 2 \sum_{k=1}^3 \Re (e^{-i \theta} \bar{z_k}z'_k)$$

The first two sums are constant, reducing the problem to find $\theta$ such as

$$\sum_{k=1}^3 \Re (e^{-i \theta} \bar{z_k}z'_k)=\Re \left(e^{-i \theta} \sum_{k=1}^3 \bar{z_k}z'_k\right)=\Re \left(e^{-i \theta} Z \right) \ \ \text{with} \ \ Z:=\sum_{k=1}^3 \bar{z_k}z'_k$$

is maximized (due to the minus sign of coefficient $-2$ in (2)).

Consider the polar representation $Z=re^{i \alpha}$.

Maximization of $\Re \left(re^{-i\theta} Z \right)=\Re r\left(e^{i(\alpha-\theta)}\right)$ becomes extremely simple: take $\theta=\alpha$.

Summarizing, Procrustes' algorithm in this context is as follows:

  • convert the triangles' vertices into complex numbers $z_k$ and $z'_k \ (k=1,2,3)$,

  • compute the "hermitian dot product" $Z:=\sum_{k=1}^3 \bar{z_k}z'_k$,

  • convert $Z$ into polar coordinates $Z=re^{i \alpha}$,

  • the anwer is $\theta_{optimal}=\alpha$.

Edit: an example:

If the first (resp. 2nd) triangle has coordinates

$$A_1(-2,2), \ A_2=(-3,-2), \ A_3=(5,0) \ \ \text{and} \ \ A'_1(-3,0), \ A'_2=(1,-3), \ A'_3=(4,3).$$

(note that the centroid of each triangle is 0, a necessary condition for the method to be applied ; if this has not be done, you need to translate the two triangles in such a way that the new centroids are such).

$$z_1=-2+2i, \ z_2=-3-2i, \ z_3=5 \ \ \text{and} \ \ z'_1=-3, \ z'_2=1-3i, \ z'_3=4+3i$$

$$Z=\sum_{k=1}^3 \bar{z_k}z'_k=29+32i\approx43.19e^{0.8345i}$$

The rotation angle is thus $\approx 0.8345$ radians, i.e., $\approx 47.8$ (decimal) degrees.