Finding the change in position and angle after moving the rectangle

155 Views Asked by At

enter image description here

I am curious about how to approach the problem mathematically, so I write. There are 4 dots on the square and I know the location. The rectangle moves and the positions and angles of the four points change. I also know the location of the four points that have changed. I don't know the changed angle. How can I find the angle and value to move to the initial position? Please advise.

1

There are 1 best solutions below

2
On BEST ANSWER

Let us denote $$u_{12}=\binom{x_2-x_1}{y_2-y_1}, \ u'_{12}=\binom{x'_2-x'_1}{y'_2-y'_1},$$

Dot product $u_{12}.u'_{12}$ can be expressed in two ways:

$$u_{12}.u'_{12}=\|u_{12}\| \|u'_{12}\| \cos \theta=(x_2-x_1)(x'_2-x'_1)+(y_2-y_1)(y'_2-y'_1)$$

Therefore:

$$\cos \theta= \dfrac{(x_2-x_1)(x'_2-x'_1)+(y_2-y_1)(y'_2-y'_1)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\sqrt{(x'_2-x'_1)^2+(y'_2-y'_1)^2}}\tag{1}$$

from which you can extract $\theta$.

This works well for $0 \le \theta \le \pi$.

But the main problem when you have only the cosine is that you cannot distiguish for exemple a $+30°$ move from a $-30°$ move !

If you want to eliminate this ambiguity, i.e., work, say, in interval $[-180°;+180°]$, you have to determine $\sin \theta$ as well, by using this formula:

$$\sin \theta= \dfrac{(x_2-x_1)(y_2-y_1)-(x'_2-x'_1)(y'_2-y'_1)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\sqrt{(x'_2-x'_1)^2+(y'_2-y'_1)^2}}\tag{2}$$

[(2), with striking similarity with (1) can be justified in a similar manner by expressing the cross product $u \times u'$ in two ways.]

Once you have the value of $\theta$, the formula sending any point $\binom{x}{y}$ connected to the first rectangle onto its homologous points $\binom{x'}{y'}$ connected to the second rectangle.

$$\binom{x'}{y'}=\begin{pmatrix}\cos \theta & -\sin \theta\\\sin \theta & \ \ \ \cos \theta\\\end{pmatrix}\binom{x-x_1}{y-y_1}+\binom{x'_1}{y'_1}$$

Remark: The work done for indices $1$ and $2$ could have been done with any index "twinning", for example $1$ and $4$.

It is even a good idea to do it for all "twinings" and average the $\theta_{ij}$ values thus obtained ; the error will be less...