I have traced a set of triangles - windows on a curved building - and recorded them as a set of corner coordinates for each triangle. In reality, each triangle is an equally sized equilateral triangle, but in the photo each triangle is 'projected' differently based on the angle of the building. I'm trying to work out how to take the 'source triangle' shape and project it to match the triangle shape as seen in the photo.

Illustration of triangle transformation

Each triangle's orientation is the same (all 'up-pointing').

I imagine the solution will be something like a bounding box + a 'skew' amount (I'm imagining a +/- degrees of the length of the side) for each axis. Alternately, I believe skewing in two dimensions is the same as skew in one dimension + rotation of the whole shape.

So - I think this gives four values for the solution:

  • Scale X (%)
  • Scale Y (%)
  • Skew (°)
  • Rotation (°)

Is there a straightforward way to determine these four values given the corner coordinates for the target triangle?

  • $\begingroup$ I assume the projection of the camera point. You assume the triangle is in a plane and than I assume you look for a point from which to project the triangle into another plane. $\endgroup$
    – Moti
    Sep 25, 2020 at 3:58
  • $\begingroup$ The projection/rotation (if I understand it), is both from the camera point and due the angle of the building. Simple triangles are always in a plane, aren't they? (I think!). I'm not trying to find the projection point specifically - I want to take an instance of the 'master' triangle shape, and then perform some scaling/skewing operations on it to have it match the shape from the image. Does that make it any clearer? Sorry - I'm not an expert in this terminology! $\endgroup$
    – Beejamin
    Sep 28, 2020 at 6:01
  • $\begingroup$ Add a drawing and I will try to figure it out for you. $\endgroup$
    – Moti
    Sep 29, 2020 at 5:05
  • $\begingroup$ Thanks @Moti . Added a diagram - let me know if that makes it clearer. $\endgroup$
    – Beejamin
    Sep 29, 2020 at 5:55
  • $\begingroup$ It seems that you want to start with rotating the projected triangle to make it equilateral (though the one you show is not) - am I right? After rotating it around one of the corners you could scale it. Will this work for you? $\endgroup$
    – Moti
    Sep 29, 2020 at 6:25

1 Answer 1


Suppose the coordinates of the initial bounding box were (in order) $(x_1, y_1)$, $(x_2, y_1)$, $(x_2, y_2)$, $(x_1, y_2)$ with $(x_1, y_1)$ being the left lower corner. I will perform all operations relative to this and the new box will have the same lower left corner.
Also note that throughout these operations we will be have a parallelogram box so, given three corners one can always determine the last (by using the fact that midpoints of opposite corners must coincide). So I will not describe the mapping of the upper-right corner $(x_2, y_2)$ (since it will be deducible).

After scaling along $y$ by $\alpha_y$ and $x$ by $\alpha_x$ ($\alpha_x, \alpha_y>0$)
If the scales are in percentages, we divide by $100$ to get fractions which these $\alpha$s are. $$\begin{bmatrix}x_1& y_1\\ x_2& y_1\\ x_1& y_2\end{bmatrix}\longrightarrow \begin{bmatrix}x_1& y_1\\ x_1+\alpha_x(x_2-x_1)& y_1\\ x_1& y_1+\alpha_y(y_2-y_1)\end{bmatrix}$$

After skewing by $\omega$ ($-90^{\circ}<\omega<90^{\circ}$)
By this I mean, the angle at $(x_1, y_1)$ will now become $90^{\circ}+\omega$ while the lower-right vertex stays $$\begin{bmatrix}x_1& y_1\\ x_1+\alpha_x(x_2-x_1)& y_1\\ x_1& y_1+\alpha_y(y_2-y_1)\end{bmatrix}\longrightarrow\begin{bmatrix}x_1& y_1\\ x_1+\alpha_x(x_2-x_1)& y_1\\ x_1+\alpha_y(y_2-y_1)\cdot\cos(90^{\circ}+\omega)& y_1+\alpha_y(y_2-y_1)\cdot\sin(90^{\circ}+\omega)\end{bmatrix}$$

After rotating by $\theta$ ($-90^{\circ}<\theta<90^{\circ}$)
By this I mean rotating the whole parallelogram counter-clockwise by $\theta$. We are not considering the other angles because that would change the choice of lower-left vertex itself i.e. if we choose the mapping of the lower-left vertex correctly, this will be the domain
Simplifying using rotation matrix and using trigonometric identities, we get: $$\longrightarrow\begin{bmatrix}x_1& y_1\\ x_1+\alpha_x(x_2-x_1)\cdot\cos\theta& y_1+\alpha_x(x_2-x_1)\cdot\sin\theta\\ x_1+\alpha_y(y_2-y_1)\cdot\cos(90^{\circ}+\omega+\theta)& y_1+\alpha_y(y_2-y_1)\cdot\sin(90^{\circ}+\omega+\theta)\end{bmatrix}$$

To get the parameters from the target:

  1. First identify the lower-left corner of the target box $(X_1, Y_1)$ (which one would that be? One shared with the embedded triangle and with a lower x-coordinate. The other shared corner is lower-right $(X_2, Y_2)$, the one opposite to this one is $(X_3, Y_3)$ etc).
  2. Calculate $\alpha_x$ and $\alpha_y$ from the ratio of corresponding edge ratios.
  3. Calculate $\theta$ from the angle between the lower edges (i.e. the triangle bases)
  4. Calculate $\omega+\theta$ (and subsequently $\omega$) from the angle between the left edges (i.e. one of the other pair of edges)

Thus if we wish to get from target (capital letters, ignoring the upper-right corner again) to source (lower letters): $$\begin{bmatrix}X_1& Y_1\\ X_2& Y_2\\ X_3& Y_3\end{bmatrix}\longrightarrow \begin{bmatrix}x_1& y_1\\ x_2& y_1\\ x_1& y_2\end{bmatrix}$$

Then: $$\alpha_x = \frac{\sqrt{(X_2-X_1)^2+(Y_2-Y_1)^2}}{x_2-x_1}$$ $$\alpha_y = \frac{\sqrt{(X_3-X_1)^2+(Y_3-Y_1)^2}}{y_2-y_1}$$ $$\tan\theta=\frac{Y_2-Y_1}{X_2-X1}\quad \text{ (uniquely determines $\theta$ in its range)}$$ $$\sin(90^{\circ}+\omega+\theta)=\frac{Y_3-Y_1}{\sqrt{(X_3-X_1)^2+(Y_3-Y_1)^2}}$$ $$\cos(90^{\circ}+\omega+\theta)=\frac{X_3-X_1}{\sqrt{(X_3-X_1)^2+(Y_3-Y_1)^2}}\quad \text{ (together uniquely determine $\omega$ in the range of length $180^\circ$)}$$

  • $\begingroup$ Okay, I see you wish the reverse transformation: parameters from the target. I'll add more to this answer shortly $\endgroup$ Sep 29, 2020 at 6:41

You must log in to answer this question.

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