Describe object geometry in 2D space

34 Views Asked by At

How would I describe geometry (position + orientation) of an object in 2 dimensions? I'm familiar with a certain method of describing an object's geometry in 3 dimensions, using a 4x4 matrix with its position Vector, look Vector, right Vector, and top Vector included, but I don't see a need to include anything more than position and look vector in the case of a 2d matrix, correct? If so, how would the orientation of that look? An explanation or link to additional resources on this topic would be greatly appreciated. Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

A 2D transformation matrix $\mathbf{R}$, $$\mathbf{R} = \left[ \begin{matrix} u_x & - u_y & t_x \\ u_y & u_x & t_y \\ 0 & 0 & 1 \\ \end{matrix} \right] \tag{1}\label{G1}$$ describes translation by $\vec{t} = ( t_x, t_y )$, rotation by $\theta$, and scaling by $\lambda \gt 0$, $$\left\lbrace \, \begin{aligned} u_x &= \lambda \cos \theta \\ u_y &= \lambda \sin \theta \\ \end{aligned} \right . \quad \iff \quad \left\lbrace \, \begin{aligned} a &= \sqrt{ u_x^2 + u_y^2 } \\ \theta &= \operatorname{atan2}\left( u_y, u_x \right) \\ \end{aligned} \right . \tag{2}\label{G2}$$ where $\operatorname{atan2}$ is the two-argument form of arcus tangent (covering all four quadrants).

Transforming vector $\vec{p} = (p_x, p_y)$ to vector $\vec{q} = (q_x , q_y)$ is done using $$\left[ \begin{matrix} q_x \\ q_y \\ 1 \end{matrix} \right] = \left[ \begin{matrix} u_x & -u_y & t_x \\ u_y & u_x & t_y \\ 0 & 0 & 1 \end{matrix} \right] \left[ \begin{matrix} p_x \\ p_y \\ 1 \end{matrix} \right]$$

Thus, for rotation, translation, and scaling, you need four scalars: $\theta$, $\lambda$, $t_x$, and $t_y$; or equivalently (through $\eqref{G2}$) $u_x$, $u_y$, $t_x$, and $t_y$. You can call $\vec{u} = (u_x, u_y)$ the "right" vector; then the "up" vector is that one rotated 90° counterclockwise, i.e. $\vec{v} = (-u_y, u_x)$.

Given a rotation matrix $$\mathbf{R} = \left[ \begin{matrix} r_{11} & r_{12} & r_{13} \\ r_{21} & r_{22} & r_{23} \\ 0 & 0 & 1 \\ \end{matrix} \right]$$ you can recover the four scalars (considering numerical stability) via $$\left\lbrace \, \begin{aligned} u_x &= \displaystyle \frac{r_{11} + r_{22} }{2} \\ u_y &= \displaystyle \frac{r_{21} - r_{12} }{2} \\ t_x &= r_{13} \\ t_y &= r_{23} \\ \end{aligned} \right.$$ and optionally apply $\eqref{G2}$ if you want the rotation angle $\theta$ and scale factor $\lambda$.