4
$\begingroup$

I have $2$ triangles ($6$ dots) on a $2D$ plane. The points of the triangles are: a, b, c and x, y, z

I would like to find a matrix, using I can transform every point in the 2D space. If I transform a, then the result is x. For b the result is y, and for c the result is z

And if there is a given d point, which is halfway from a to b, then after the transformation the result should be between x and y halfway.


I've tried to solve it according to NovaDenizen's solution, But the result is wrong.

The original triangle:

$$ a = \left[ \begin{array}{ccc} -3\\ 0\\ \end{array} \right] $$

$$ b = \left[ \begin{array}{ccc} 0\\ 3\\ \end{array} \right] $$

$$ c = \left[ \begin{array}{ccc} 3\\ 0\\ \end{array} \right] $$

The x, y, z dots:

$$ x = \left[ \begin{array}{ccc} 2\\ 3\\ \end{array} \right] $$

$$ y = \left[ \begin{array}{ccc} 3\\ 2\\ \end{array} \right] $$

$$ z = \left[ \begin{array}{ccc} 4\\ 3\\ \end{array} \right] $$

I've created a figure:

enter image description here

I tried to transform the (0, 0) point, which is halfway between a and b, but the result was (3, 3.5) instead of (3, 3)

The T matrix is:

$$\left[ \begin{array}{ccc} 1/3 & 1/6 & 0\\ 0 & -1/2 & 0\\ 3 & 3,5 & 1\\ \end{array} \right]$$

$\endgroup$
4
$\begingroup$

The transformation you're looking for has this form:

$$\left[ \begin{array}{ccc} t_1 & t_2 & t_3\\ t_4 & t_5 & t_6\\ 0 & 0 & 1\\ \end{array} \right] \left[ \begin{array}{ccc} a_1 & b_1 & c_1\\ a_2 & b_2 & c_2 \\ 1 & 1 & 1 \\ \end{array} \right] = \left[\begin{array}{ccc} x_1 & y_1 & z_1\\ x_2 & y_2 & z_2\\ 1 & 1 & 1 \end{array} \right] $$

or

$${\bf T A} = {\bf X}$$ so $${\bf T} = {\bf X}{\bf A}^{-1}$$

Now $\bf T$ is a transformation matrix you can use on any point, like $${\bf T}\left[\begin{array}{c}a_1\\a_2\\1\end{array}\right] = \left[\begin{array}{c}x_1\\x_2\\1\end{array}\right]$$

It's linear, so it has the halfway point property you were looking for.

$$ {\bf A} = \left[\begin{array}{ccc} -3 & 0 & 3\\ 0 & 3 & 0\\ 1 & 1 & 1\\ \end{array}\right] $$ $$ \left[\begin{array}{ccc|ccc} -3 & 0 & 3 & 1 & 0 & 0\\ 0 & 3 & 0 & 0 & 1 & 0\\ 1 & 1 & 1 & 0 & 0 & 1\\ \end{array}\right] $$ $$ \left[\begin{array}{ccc|ccc} 1 & 0 & -1 & -\frac13 & 0 & 0\\ 0 & 3 & 0 & 0 & 1 & 0\\ 0 & 1 & 2 & \frac13 & 0 & 1\\ \end{array}\right] $$

$$ \left[\begin{array}{ccc|ccc} 1 & 0 & -1 & -\frac13 & 0 & 0\\ 0 & 1 & 0 & 0 & \frac13 & 0\\ 0 & 0 & 2 & \frac13 & -\frac13 & 1\\ \end{array}\right] $$

$$ \left[\begin{array}{ccc|ccc} 1 & 0 & 0 & -\frac16 & -\frac16 & \frac12\\ 0 & 1 & 0 & 0 & \frac13 & 0\\ 0 & 0 & 1 & \frac16 & -\frac16 & \frac12\\ \end{array}\right]\\ \text{so } {\bf A}^{-1} = \left[\begin{array}{ccc} -\frac16 & -\frac16 & \frac12\\ 0 & \frac13 & 0\\ \frac16 & -\frac16 & \frac12\\ \end{array}\right]$$

$${\bf XA}^{-1} = \left[\begin{array}{ccc} 2 & 3 & 4\\ 3 & 2 & 3\\ 1 & 1 & 1\\ \end{array}\right] \left[\begin{array}{ccc} -\frac16 & -\frac16 & \frac12\\ 0 & \frac13 & 0\\ \frac16 & -\frac16 & \frac12\\ \end{array}\right] = \left[\begin{array}{ccc} \frac13 & 0 & 3\\ 0 & -\frac13 & 3\\ 0 & 0 & 1\\ \end{array}\right] $$

$\endgroup$
  • $\begingroup$ I've edited the question, according to your answer $\endgroup$ – Iter Ator Jan 5 '15 at 19:15
  • $\begingroup$ What are your $\bf A$ and ${\bf A}^{-1}$ matrices? Are they inverses? $\endgroup$ – NovaDenizen Jan 6 '15 at 2:55
  • $\begingroup$ I updated the question, with my $ T = X*A^-1 $ matrix $\endgroup$ – Iter Ator Jan 7 '15 at 0:56
  • 1
    $\begingroup$ Your matrix is wrong. The x and y transformations should be independent, but you have a $\frac16$ entry. $\endgroup$ – NovaDenizen Jan 8 '15 at 1:30
  • 1
    $\begingroup$ @IterAtor I've edited my answer explicitly calculating ${\bf XA}^{-1}$ $\endgroup$ – NovaDenizen Jan 8 '15 at 1:57
2
$\begingroup$

The form of the affine transformation will be

$$\vec{p}' = \left( \begin{array}{cc} A_{11} & A_{12} \\ A_{21} & A_{22}\end{array} \right) \vec{p} + \vec{d}$$.

This transformation is characterized by six parameters (four for the matrix, two for the displacement vector), and the requirement that $a$ transforms to $x$ and similaryly for $b$ and $c$ going to $y$ and $z$ gives six equations. Assuming no three of the points are co-linear, these can be solved. An easy approach is:

Eliminate the $\vec{d}$ by transforming the difference $(\vec{b}-\vec{a})$; this gives two equations, the first of which looks like $$ A_{11} (b_1 - a_1) + A_{12} (b_2 - a_2) = y_1 - x_1 $$ Then eliminate the $\vec{d}$ agian, this time by transforming the difference $(\vec{c}-\vec{a})$; this gives two equations, the first of which looks like $$ A_{11} (c_1 - a_1) + A_{12} (c_2 - a_2) = z_1 - x_1 $$ These two equations can be solved to determine $A_{11}$ and $A_{12}$. Similarly, the second equation in each elemination can be solved to determine $A_{21}$ and $A_{22}$.

Finally, now that $A$ is known, you can easily find $\vec{d}$.

$\endgroup$
0
$\begingroup$

There is a neat formula for your case $$ \vec{P}(p_1; p_2) = (-1) \frac{ \det \begin{pmatrix} 0 & \vec{x} & \vec{y} & \vec{z} \\ p_1 & a_1 & b_1 & c_1 \\ p_2 & a_2 & b_2 & c_2 \\ 1 & 1 & 1 & 1 \\ \end{pmatrix} }{ \det \begin{pmatrix} a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2 \\ 1 & 1 & 1 \\ \end{pmatrix} }, $$ where $p_1$ and $p_2$ are coordinates of the point you are mapping.

Here's how it works (plugging in initial points) $$ \vec{P}(p_1; p_2) = (-1) \frac{ \det \begin{pmatrix} 0 & \vec{x} & \vec{y} & \vec{z} \\ p_1 & -3 & 0 & 3 \\ p_2 & 0 & 3 & 0 \\ 1 & 1 & 1 & 1 \\ \end{pmatrix} }{ \det \begin{pmatrix} -3 & 0 & 3 \\ 0 & 3 & 0 \\ 1 & 1 & 1 \\ \end{pmatrix} } = \frac{\vec{z} - \vec{x}}{6} p_1 + \frac{2 \vec{y} - \vec{x} - \vec{z}}{6} p_2 + \frac{\vec{x} + \vec{z}}{2} = $$ now I plug in the final points $$ = \frac{1}{6} \left[ \begin{pmatrix} 4 \\ 3 \end{pmatrix} - \begin{pmatrix} 2 \\ 3 \end{pmatrix} \right] p_1 + \frac{1}{6} \left[ 2 \begin{pmatrix} 3 \\ 2 \end{pmatrix} - \begin{pmatrix} 2 \\ 3 \end{pmatrix} - \begin{pmatrix} 4 \\ 3 \end{pmatrix} \right] p_2 + \frac{1}{2} \left[ \begin{pmatrix} 2 \\ 3 \end{pmatrix} + \begin{pmatrix} 4 \\ 3 \end{pmatrix} \right] $$ Simplification yields $$ \vec{P}(p_1; p_2) = \begin{pmatrix} 1/3 \\ 0 \end{pmatrix} p_1 + \begin{pmatrix} 0 \\ -1/3 \end{pmatrix} p_2 + \begin{pmatrix} 3 \\ 3 \end{pmatrix} $$ Or you can write that in canonical form $$ \vec{P}(p_1; p_2) = \begin{pmatrix} 1/3 & 0 \\ 0 & -1/3 \end{pmatrix} \begin{pmatrix} p_1 \\ p_2 \end{pmatrix} + \begin{pmatrix} 3 \\ 3 \end{pmatrix} $$

For more details on how this all works you may check "Beginner's guide to mapping simplexes affinely", where authors of the equation elaborate on theory behind it. In the guide there is exactly the same 2D example solved as the one you are interested in. The same authors recently published "Workbook on mapping simplexes affinely" (ResearchGate as well). They discuss many practical examples there, e.g. show that the same equation may be used for color interpolation or Phong shading. You may want to check it if you want to see this equation in action.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.