2
$\begingroup$

I have two triangles that are not similar. The Only thing that I know is that AB and C points from triangle 1 are related to $A^1 B^1$ and $C^1$ points from triangle 2.

Based on these inputs I want to find $K^1$ point related to Triangle 2 based on K point related to triangle 1.

In my problem, these triangles have nothing in common. But by rotating, scaling and moving them I reach the level where:

  • both of these triangles have the same border AB ( $AB = A^1B^1$ ) (border d from the image)

  • A point is located at the origin of XY coordinate system ( $A = A^1 = [0, 0]$ )

  • but coordinates of C and $C^1$ are different.

It looks like this:

enter image description here

This image tells it better. I need to find coordinates for K1.

I tried following equalities based on a feeling of a ratio between C, K and C1, K1 points:

  • for X Coordinate: $\frac{C_x}{K_x} = \frac{C_x^1}{K_x^1}$

  • same for Y Coordinate $\frac{C_y}{K_y} = \frac{C_y^1}{K_y^1}$

From here i could easily find out X and Y coordinates for K1:

  • $ K_x^1 = \frac{K_x * C_x^1}{C_x} $

  • $ K_y^1 = \frac{K_y * C_y^1}{C_y} $

I tested this for multiple points programmatically and it seems correct, but i couldn't find mathematical proof for this equality.

I wonder if there is any method for it already? Unfortunately, I couldn't find anything related.

please correct me if I'm using the wrong terminology

$\endgroup$
6
  • 1
    $\begingroup$ Perhaps points $K$ and $K^1$ have the same barycentric coordinates? $\endgroup$ Commented Jun 6, 2018 at 9:44
  • $\begingroup$ I think this is exactly what i was looking for and couldn't find the term itself. I also need this to work for the point that is outside of the triangle but i think it is easily achievable. Thank you. $\endgroup$
    – DDRamone
    Commented Jun 6, 2018 at 10:55
  • $\begingroup$ @Nominal Animal Btw, if you will post it as an answer i have all reasons to accept it as a "Best Answer". $\endgroup$
    – DDRamone
    Commented Jun 6, 2018 at 11:05
  • $\begingroup$ Well, it does not exactly match your definitions, although the results are quite close. (The red dot should be on the vertical line to its left, i.e. slightly left of where it is shown in the diagram.) I do not do "short and simple answers" (I'd want to, but I just don't know how), and tend to explain it down to the underlying issue. $\endgroup$ Commented Jun 6, 2018 at 12:54
  • $\begingroup$ Image is not precise since i created it manually, and yes K and K1 have the same barycentric coordinates. Thank you for your answer. First i have to read it carefully and implement the solution, after i will mark it. :) $\endgroup$
    – DDRamone
    Commented Jun 6, 2018 at 13:03

1 Answer 1

1
+50
$\begingroup$

Let's assume points $K$ and $K_1$ have the same barycentric coordinates.

Since beyond OP, this may be of use to others encountering a similar situation, let us look at how to define barycentric coordinates with respect to an arbitrary triangle.

Let's say the vertices of the triangle are $$\vec{p}_1 = \left [ \begin{matrix} x_1 \\ y_1 \end{matrix} \right ], \quad \vec{p}_2 = \left [ \begin{matrix} x_2 \\ y_2 \end{matrix} \right ], \quad \vec{p}_3 = \left [ \begin{matrix} x_3 \\ y_3 \end{matrix} \right ] \tag{1}\label{NA1}$$ In barycentric coordinates, the coordinate axes are $$\hat{u} = \vec{p}_2 - \vec{p}_1, \quad \hat{v} = \vec{p}_3 - \vec{p}_1 \tag{2}\label{NA2}$$ so that point $\underline{p} = (u, v)$ in barycentric coordinates corresponds to point $\vec{p} = (x, y)$ in Cartesian coordinates: $$\vec{p} = \vec{p}_1 + u \hat{u} + v \hat{v} \quad \iff \quad \left\lbrace\begin{aligned} x &= (1 - u - v) x_1 + u x_2 + v x_3 \\ y &= (1 - u - v) y_1 + u y_2 + v y_3 \end{aligned} \right. \tag{3}\label{NA3}$$ Barycentric coordinates $(u, v)$ are within the triangle, if and only if $0 \le u \le 1$, $0 \le v \le 1$, $0 \le u + v \le 1$, but you can use barycentric coordinates to describe any point on the plane. Conversely, $$\left\lbrace\begin{aligned} u &= \frac{ x_1 (y - y_3) + x (y_3 - y_1) + x_3 (y_1 - y) }{x_1 (y_2 - y_3) + x_2 (y_3 - y_1) + x_3 (y_1 - y_2) } \\ v &= \frac{ x_1 (y_2 - y) + x_2 (y - y_1) + x (y_1 - y_2) }{x_1 (y_2 - y_3) + x_2 (y_3 - y_1) + x_3 (y_1 - y_2) } \\ \end{aligned}\right.\tag{4}\label{NA4}$$


Note that a direction vector $\underline{d} = (u, v)$ in barycentric coordinates corresponds to direction vector $\vec{d} = (x, y)$ in Cartesian coordinates via $$\vec{d} = u \hat{u} + v \hat{v} \quad \iff \quad \left\lbrace\begin{aligned} x &= ( - u - v) x_1 + u x_2 + v x_3 \\ y &= ( - u - v) y_1 + u y_2 + v y_3 \end{aligned} \right. \tag{5}\label{NA5}$$ and conversely, $$\left\lbrace\begin{aligned} u &= \frac{ x (y_3 - y_1) - y (x_3 - x_1) }{x_1 (y_2 - y_3) + x_2 (y_3 - y_1) + x_3 (y_1 - y_2) } \\ v &= \frac{ x (y_1 - y_2) - y (x_1 - x_2) }{x_1 (y_2 - y_3) + x_2 (y_3 - y_1) + x_3 (y_1 - y_2) } \\ \end{aligned}\right.\tag{6}\label{NA6}$$


Back to the topic at hand.

Let's investigate the case where $x_1 = 0$, $y_1 = 0$, $x_2 = B$, $y_2 = 0$.

If we apply $\eqref{NA4}$, we get $$\left\lbrace\begin{aligned} u &= \frac{x y_3 - x_3 y}{B y_3} \\ v &= \frac{y}{y_3} \end{aligned}\right .$$

Let's assume $x_3 \to X_3$ and $y_3 \to Y_3$, and see how $x \to X$, $y \to Y$ when barycentric coordinates $u$ and $v$ stay unchanged: $$\left\lbrace\begin{aligned} \frac{x y_3 - x_3 y}{B y_3} &= \frac{X Y_3 - X_3 Y}{B Y_3} \\ \frac{y}{y_3} &= \frac{Y}{Y_3} \\ \end{aligned}\right . \iff \left\lbrace\begin{aligned} x - x_3 \frac{y}{y_3} &= X - X_3 \frac{Y}{Y_3} \\ Y &= y \frac{Y_3}{y_3} \\ \end{aligned}\right .$$ which solving for $X$ and $Y$ yields $$\left\lbrace\begin{aligned} X &= x + (X_3 - x_3)\frac{y}{y_3} \\ Y &= y \frac{Y_3}{y_3} \\ \end{aligned}\right. \tag{7}\label{NA7}$$ So, this definitely fulfills OP's $y$ coordinate, but the $x$ coordinate is slightly different. Let's examine the shown diagram, and see how they differ.

In the diagram, $C = (x_3 , y_3) = (4.0, 8.0)$, $K = (x, y) = (4.0, 6.6)$, and $C1 = (X_3 , Y_3) = (7.9 , 7.0)$, and $K1 = (X , Y)$. Substituting into $\eqref{NA7}$ we get $K1 = (7.2, 5.8)$ which puts $K1$ slightly more left (on top of the vertical grid line immediately left of the red dot).


In the general case, we can calculate the direct mapping between point $(x,y)$ with respect to triangle $(x_1 , y_1)$, $(x_2 , y_2)$, $(x_3 , y_3)$, and point $(X,Y)$ with respect to triangle $(X_1 , Y_1)$, $(X_2 , Y_2)$, $(X_3 , Y_3)$, where both points have the same barycentric coordinates with respect to their own triangles, using $\eqref{NA4}$ and $\eqref{NA6}$.

By hand, that would be dull. But, if we construct the formulae in e.g. Maple, we get

$$\left\lbrace\begin{aligned} d &= x_1 (y_2 - y_3) + x_2 (y_3 - y_1) + x_3 (y_1 - y_2) \\ X_x &= ( X_1 (y_2 - y_3) + X_2 (y_3 - y_1) + X_3 (y_1 - y_2) ) \\ X_y &= ( x_1 (X_2 - X_3) + x_2 (X_3 - X_1) + x_3 (X_1 - X_2) ) \\ X_t &= X_1 (x_2 y_3 - x_3 y_2) + X_2 (x_3 y_1 - x_1 y_3) + X_3 (x_1 y_2 - x_2 y_1) \\ Y_x &= Y_1 (y_2 - y_3) + Y_2 (y_3 - y_1) + Y_3 (y_1 - y_2) \\ Y_y &= x_1 (Y_2 - Y_3) + x_2 (Y_3 - Y_1) + x_3 (Y_1 - Y_2) \\ Y_t &= Y_1 (x_2 y_3 - x_3 y_2) + Y_2 (x_3 y_1 - x_1 y_3) + Y_3 (x_1 y_2 - x_2 y_1) \end{aligned}\right .$$ so that $$\left\lbrace\begin{aligned} X &= \frac{x X_x + y X_y + X_t}{d} \\ Y &= \frac{x Y_x + y Y_y + Y_t}{d} \\ \end{aligned}\right.$$ Note that $d$ is twice the area of the first triangle, and can only be zero if the first triangle is a line or a point. The seven constants ($d$, $X_x$, $X_y$, $X_t$, $Y_x$, $Y_y$, and $Y_t$) only change when the coordinates of the first or second triangle change.

You can interpret the seven constants as a transformation, where $(X_t , Y_t)$ is the translation vector, $(X_x , X_y)$ is the new $x$ axis vector, and $(Y_x , Y_y)$ is the new $y$ axis vector, and $1/d$ is the scale factor.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .