This algorithm takes a 3D triangle (
To preserve the true shape of the mesh, we extract the geometric relationships from the 3D coordinates.
-
Define 3D Vectors from vertex
$B$ :$\vec{V}_{BC} = C - B$ $\vec{V}_{BD} = D - B$
-
Calculate
$\cos(\beta)$ using the Dot Product: $$\cos(\beta) = \frac{\vec{V}{BC} \cdot \vec{V}{BD}}{|\vec{V}{BC}| \cdot |\vec{V}{BD}|}$$ -
Derive
$\sin(\beta)$ : Using the Pythagorean identity:$$\sin(\beta) = \sqrt{1 - \cos^2(\beta)}$$
In the UV plane (
-
Edge Length:
$L = |c - b|$ -
Local X-axis (
$\vec{u}$ ):$$\vec{u} = \frac{c - b}{L}$$ -
Local Z-axis (
$\vec{v}$ ): Rotate$\vec{u}$ by 90° in the 2D plane to create an orthogonal (perpendicular) axis:$$\vec{v} = (-u_z, u_x)$$
We determine the position of
$x_{local} = d_1 \cdot \cos(\beta)$ $z_{local} = d_1 \cdot \sin(\beta)$
To ensure the triangles "unfold" like a piece of paper rather than folding back
on top of the previous triangle, we use point
-
Reference Vector:
$\vec{w} = a - b$ -
Alignment Test: Calculate the dot product of
$\vec{w}$ and our perpendicular basis vector$\vec{v}$ :$Side_A = \vec{w} \cdot \vec{v}$
-
Final Placement:
- If
$Side_A$ is positive: Point$a$ lies in the direction of$+\vec{v}$ . Therefore, we must place$d$ in the opposite direction ($-\vec{v}$ ):$$d = b + (x_{local} \cdot \vec{u}) - (z_{local} \cdot \vec{v})$$ - If
$Side_A$ is negative: Point$a$ lies in the direction of$-\vec{v}$ . Therefore, we place$d$ in the positive direction ($+\vec{v}$ ):$$d = b + (x_{local} \cdot \vec{u}) + (z_{local} \cdot \vec{v})$$
- If