How do I map a 3D triangle into 2D?

9.7k Views Asked by At

The problem I'm having is mapping a 3D triangle into 2 dimensions. I have three points in $(x,y,z)$ form, and want to map them onto the plane described by the normal of the triangle, such that I end up with three points in $(x,y)$ form.

My guess would be it'd assign an arbitrary up vector and then doing something? Finding the distance traveled along the plane from one vertex to another? What do I do, and how do I do it?

4

There are 4 best solutions below

3
On BEST ANSWER

You have not specified the problem well enough. Do you have three points $(x_1,y_1,z_1), (x_2,y_2,z_2), (x_3,y_3,z_3)$ to map to two dimensional points? The simplest is to ignore the third coordinate. This is not as stupid as it sounds-you are projecting the triangle on the $xy$ plane. If you want to project onto another plane, how is it defined?

1
On

My take on this is that you want to find a mapping of the form $(x, y, z) \mapsto (ax+by+cz, dx+ey+fz) $ so the resulting triangle in the plane is the same shape and size as the original triangle. Let $L_{ij}$ be the distance between points $i$ and $j$. Since we have 6 unknowns, we need 6 equations.

Let’s map $(x_1, y_1, z_1)$ into $(0, 0)$. We get $ax_1+by_1+cz_1 = 0$ and $dx_1+ey_1+fz_1 = 0$.
Let’s map $(x_2, y_2, z_2)$ into $(L_{12}, 0)$. We get $ax_2+by_2+cz_2 = L_{12}$ and $dx_2+ey_2+fz_2 = 0$.

Compute the point $(u, v)$ which is $L_{13}$ from $(0, 0)$ and $L_{23}$ from $(L_{12}, 0)$. The sine and cosine laws are your friends here. Map $(x_3, y_3, z_3)$ into $(u, v)$ via $ax_3+bx_3+cz_3 = u$ and $dx_3+ey_3+fz_3 = v$.

Solve these two sets of $3\times 3$ equations, and there’s your mapping.

0
On

If you only care about the shape of the triangle, not about its orientation, then it is reasonably simple -just calculate the distances between the points. I believe that is what Ralph Dratman is doing above.

Let us have the three 3D points

x1, y1, z1
x2, y2, z2
x3, y3, z3

Let us call the sides of the triangle a, b and c, and its vertices A, B, C.

a = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)
b = sqrt((x3-x2)^2 + (y3-y2)^2 + (z3-z2)^2)
c = sqrt((x1-x3)^2 + (y1-y3)^2 + (z1-z3)^2)

To draw this triangle, you can choose any orientation and position. One choice is

A: [0,0] 
B: [a,0]

The position of C would now need to be calculated using the above calculated sides a, b, c.

C: [xc, yc]

According to Wolfram Alpha (after label adjustment):

yc = sqrt((a + b - c) (a - b + c) (-a + b + c) (a + b + c))/(2 a)
xc = sqrt(c^2 - yc^2)
0
On

Suppose you have three points A(x_1, y_1, z_1) , B(x_2, y_2, z_2), C(x_3, y_3, z_3). You can have the axes of the coordinate system attached to the plane containing $A,B,C$ anywhere on this plane, and the orientation of the its $x', y'$ axes can be oriented freely as well. So to specify the problem further, let's assume that you want to place point $A$ at the origin of the $O'x'y'$ plane (which is coincident with the plane of the triangle). Further, assume that the $x'$ axis is chosen to be along the vector $\vec{AB}$. These two assumptions make the coordinate system $O'x'y'$ unique. It is specified in steps as follows:

Step 1: Find the normal vector to the plane of the triangle, this is given by

$ N = ( B - A) \times (C - A ) $

Step 2: Normalize vector $N$ by defining the unit vector along its direction by

$\hat{n} = \dfrac{N}{\| N \| } $

Step 3: Choose the $x'$ axis to point in the direction of $\vec{AB} = B - A $, therefore, the unit vector along the $x'$ axis will be

$ \hat{x'}= \dfrac{ B - A}{\| B - A \|} $

Step 4: Now for the right handed system, the $y'$ axis unit vector is given by

$ \hat{y'} = \hat{n} \times \hat{x'} $

Step 5: Place the three vectors $\hat{x'}, \hat{y'}, \hat{n} $ are the columns of a $3 \times 3 $ matrix R $ in this order.

Step 6: The coordinate system $O' x' y' n$ and the world coordinate system are related by

$ \large {P = A + R Q} $

where $P = [x, y, z]^T $ is the coordinate vector of a point expressed in the world coordinate frame, and $Q$ is the coordinate vector of the same point expressed in the frame what we just constructed.

From Step 6. we have

$Q = R^T (P - A) $

So for our triangle, we have

$A' = R^T (A - A) = 0 $

$B' = R^T (B - A) $

$C' = R^T (C - A) $

Points $A', B', C'$ are the coordinate vectors in the coordinate system $Ox'y'z'$ (the $z'$ axis is the axis along $\hat{n}$ ). Note that the $z'$ coordinate of $A', B', C'$ is zero, therefore, we effectively transformed the $3D$ world coordinates of $A,B,C$ to $2D$ coordinates in the reference frame $O'x'y'z'$ that we constructed in steps 1. through 6.