<p>When performing the unfolding the way you want, after you have unfolded one triangle in the plane, the next one should be one of the three triangles, adjacent to the unfolded one, i.e. the next triangle to be unfolded shares a common edge with the unfolded one.</p>
<p>Assume you have a triangle <span class="math-container">$ABC$</span> in three space with vertices  <span class="math-container">$$A = [A_1, A_2, A_3], \,\, B = [B_1, B_2, B_3],\,\, C = [C_1, C_2, C_3]$$</span> which is one of the triangles from the 3D mesh.</p>
<p><strong>If</strong> <span class="math-container">$ABC$</span> is the first triangle you are starting the unfolding with, then:</p>
<ol>
<li>calculate <span class="math-container">$l_{AB} = ||A - B|| = \sqrt{(A_1 - B_1)^2 + (A_2 - B_2)^2 + (A_3 - B_3)^2}$</span>;</li>
<li>set the 2D vertices <span class="math-container">$a = [0,0]$</span> and <span class="math-container">$b = [l_{AB}, 0]$</span> as well as $$l_{ab} = l_{AB};</li>
</ol>
<p><strong>Else if</strong> <span class="math-container">$ABC$</span> is a next triangle to be unfolded in the plane, i.e. you have already unfolded one of <span class="math-container">$ABC$</span>'s adjacent (neighboring) triangles, therefore one of <span class="math-container">$ABC$</span>'s edges is already unfolded in the plane. Say that this edge is <span class="math-container">$AB$</span> and it is unfolded in the plane as the edge with vertices <span class="math-container">$a = [a_1, a_2]$</span> and <span class="math-container">$b = [b_1, b_2]$</span>, where <span class="math-container">$l_{ab} = ||a-b|| = \sqrt{(a_1 - b_1)^2 + (a_2 - b_2)^2} = ||A-B|| = l_{AB}$</span>.</p>
<p>Either way, for the triangle <span class="math-container">$ABC$</span> you already have the edge <span class="math-container">$AB$</span> unfolded as <span class="math-container">$ab$</span> in the plane, so that <span class="math-container">$l_{ab} = l_{AB}$</span> (i.e. you already know <span class="math-container">$a, \, b$</span> and <span class="math-container">$l_{ab}$</span>). The question is, how do you find the coordinates of the third vertex <span class="math-container">$c = [c_1, c_2]$</span> so that <span class="math-container">$l_{bc} = l_{BC}$</span> and <span class="math-container">$l_{ca} = l_{CA}$</span>? We impose the latter two conditions because two triangles that have pairwise equal edge-lengths are congruent (isometric, i.e. identical copies of each other).</p>
<p>For your information, I will write vectors like <span class="math-container">$B - A = [B_1 - A_1, \, B_2 - A_2, \, B_3 - A_3]$</span> and <span class="math-container">$C - A = [C_1 - A_1, \, C_2 - A_2, \, C_3 - A_3]$</span> and <span class="math-container">$b-a = [b_1 - a_1, b_2-a_2]$</span> and will use dot product <span class="math-container">$\cdot$</span> and cross product <span class="math-container">$\times$</span> between vectors. You already know what <span class="math-container">$||B-A|| = l_{AB}$</span> and <span class="math-container">$||C-A|| = l_{CA}$</span> are and that <span class="math-container">$l_{AB} = l_{ab} = \|b-a\|$</span>.</p>
<ol>
<li><p>Calculate <span class="math-container">$$s = \frac{\|(B-A)\times(C-A)\|}{l_{ab}^2}$$</span></p>
</li>
<li><p>Calculate <span class="math-container">$$c = \frac{(B-A)\cdot(C-A)}{l_{ab}^2}$$</span></p>
</li>
<li><p>Calculate both pairs of coordinates
<span class="math-container">\begin{align}
&amp;c'_1 = a_1 + c(b_1-a_1) - s(b_2 - a_2)\\
&amp;c'_2 = a_2 + c(b_2-a_2) + s(b_1 - a_1)
\end{align}</span>
and
<span class="math-container">\begin{align}
&amp;c''_1 = a_1 + c(b_1-a_1) + s(b_2 - a_2)\\
&amp;c''_2 = a_2 + c(b_2-a_2) - s(b_1 - a_1)
\end{align}</span></p>
</li>
<li><p>You have two candidate points <span class="math-container">$c' = [c'_1, c'_2]$</span> and <span class="math-container">$c'' = [c''_1, c''_2]$</span></p>
</li>
<li><p>Perform a check whether <span class="math-container">$c'$</span> is on the same side of the edge <span class="math-container">$ab$</span> as the  triangle unfolded right before <span class="math-container">$ABC$</span>.</p>
</li>
</ol>
<p><strong>If</strong> it is not, then <span class="math-container">$c = c'$</span></p>
<p><strong>else if</strong> it is, then <span class="math-container">$c = c''$</span></p>
<p>As a result of this procedure, you have constructed the planar unfolding <span class="math-container">$abc$</span> of triangle <span class="math-container">$ABC$</span> and the next triangle from the 3D mesh to be unfolded (if any), should be the one that shares either edge <span class="math-container">$BC$</span> or <span class="math-container">$CA$</span> with <span class="math-container">$ABC$</span>. Either way, for that next triangle, you already know the unfolding <span class="math-container">$bc$</span> of the edge <span class="math-container">$BC$</span> and the unfolding <span class="math-container">$ca$</span> of <span class="math-container">$CA$</span> (whichever is relevant), so you can apply the same procedure for that next triangle. And so on and so forth, until you have unfolded all triangles from the mesh.</p>
<p>Have in mind that there are 3D meshes that do not posses unfolding that do not self overlap, no matter what you do. For such meshes there no greedy algorithms or any other algorithm that can do it.</p>

CC BY-SA 4.0
2019-04-20T05:43:44.613Z
Hi, thank you for your response. I'm not sure if I can follow your solution. For matrix m I don't know any of these points?
Anima
CC BY-SA 4.0
2019-04-20T13:34:32.037Z
@Anima I thought you had those. In your question you are asking about the transformation matrices. So do you need a method for calculating the coordinates of the vertices in the plane?
Futurologist
CC BY-SA 4.0
2019-04-20T14:19:43.090Z
The coordinates on the plane, do not matter for me (it can be transformed to any position on the plane), I'd only need to do this transformation to the plane of the first triangle and then accordingly transform all other triangles too. I'm sorry if i was unclear :(
Anima
CC BY-SA 4.0
2019-04-20T14:53:10.697Z
@Anima Do you want each triangle from the 3D mesh to be transformed isometrically, i.e. the original triangle and the triangle in the plane to be congruent (to be identical copies of each other)? In this case the unfolding may self-intersect. Or is there any other geometric requirement? And what matrices are you asking about, because an infolding does not necessarily require matrices (angles or edge-lengths are enough), unless you want to transform points inside the triangles.
Futurologist
CC BY-SA 4.0
2019-04-20T15:03:13.540Z
@Anima Are you trying to rotate the whole 3D mesh so that one triangle ends up on the plane, then rotate it again, for the next triangle to land on the plane and so on? Like rolling the 3D mesh on the plane?
Futurologist
CC BY-SA 4.0
2019-04-20T15:42:19.363Z
The overlaps/intersects I would handle separately. A greedy algorithm will try to figure out a unfolding, where there are no overlaps. 
The unfolded triangles should be identical copies (i.e. after unfolding I want to be able to recreate the original model)
I thought for unfolding I'd need matrices, how could I do it through the angles and length?
Anima
CC BY-SA 4.0
2019-04-20T21:09:48.600Z
@Anima I changed my post, so now you can see a sketch of an algorithm of unfolding using edge-lengths.
Futurologist
CC BY-SA 4.0
2019-04-19T23:44:39.760Z
2019-04-20T20:36:10.593Z
2020-06-18T08:32:12.800Z
Futurologist
<p>Unfolding the mesh the way you describe it, most likely you will end up with overlapping triangles in the 2D plane unless your 3D geometry is simple. If that's ok, one laborious way is to compute the distances of the triangle sides and the angles and construct the triangle again in the 2D plane.
For example, set:</p>

<p>a = (0,0)</p>

<p>b = (0,D1)</p>

<p>c = (D2*cos(phi), D2*sin(phi))</p>

<p>where </p>

<p>D1 is the distance between a and b in 3D, </p>

<p>D2 is the distance between a and c in 3D,</p>

<p>and phi is the angle at the a point.</p>

<p>Then using an affine transformation you can transform the triangle where you want.</p>

<p>UV unwrapping, which was mentioned, is the way to go only if its not important to keep the shapes of the 3D triangles intact.</p>

CC BY-SA 4.0
2019-04-20T05:41:28.513Z
Hi, thank you for your response! The overlaps will/should be removed by an greedy algorithm I plan to implement later, but for now I just want to unfold it to get a better feeling of what is happening (so no blind programming needs to be done).

I understand how I get to the 2D - triangle with your solution, but I'm not sure how I can "stick" the triangle together again with affine transformation, since here I lose all information of the real place of the triangle, do I?
Anima
CC BY-SA 4.0
2019-04-19T10:19:10.797Z
2019-04-19T10:19:10.797Z
giorgk
<p>I'm trying to unfold a 3D mesh onto a 2D plane. My general idea to do this, would be to cycle through all the faces of the meshes and perform a hierarchical transformation.</p>

<p>So I would start at the first face and transform it's vertices to the plane, then go to the next face and transform the vertices, that were not already transformed (since the mesh consists of triangles, each face shares 2 vertices with the next triangle) with the transformation of the last face and then add another transformation to get it to the plane. </p>

<p>The problem is I don't really have an idea how to calculate the transformation matrices.
Can someone help me?
Thanks.</p>

CC BY-SA 4.0
2019-04-18T11:33:05.873Z
What you're doing is quite similar to *UV unwrapping*, for which there are a few good algorithms. If you search for that, you'll probably find some existing code that could be adapted to your use case.
Dan Hulme
CC BY-SA 4.0
2019-04-19T13:52:22.233Z
Do you want the geometry of the unfolding to be arbitrary? In many problems, one seeks a geometrically very well structured unfolding. Often the choice is a type of discrete conformal mapping (also called conformal parametrization, or conformal uniformization), a discrete version of the continuous analytic conformal parametrization (uniformization). There are several different way of defining it in the case of meshes (see for example https://www.discretization.de/media/filer_public/2015/11/16/a01-10-bss.pdf)
Futurologist
<3d><2d>
Unfold a 3D mesh to a 2D plane
Anima
# Unfold a 3D mesh to a 2D plane

(Asked by: username_0 on 2019-04-18)

I'm trying to unfold a 3D mesh onto a 2D plane. My general idea to do this, would be to cycle through all the faces of the meshes and perform a hierarchical transformation.

So I would start at the first face and transform it's vertices to the plane, then go to the next face and transform the vertices, that were not already transformed (since the mesh consists of triangles, each face shares 2 vertices with the next triangle) with the transformation of the last face and then add another transformation to get it to the plane.

The problem is I don't really have an idea how to calculate the transformation matrices.
Can someone help me?
Thanks.

**Tags:** 3d, 2d

> **Comments:**
> **username_1**: What you're doing is quite similar to *UV unwrapping*, for which there are a few good algorithms. If you search for that, you'll probably find some existing code that could be adapted to your use case.  
> **username_2**: Do you want the geometry of the unfolding to be arbitrary? In many problems, one seeks a geometrically very well structured unfolding. Often the choice is a type of discrete conformal mapping (also called conformal parametrization, or conformal uniformization), a discrete version of the continuous analytic conformal parametrization (uniformization). There are several different way of defining it in the case of meshes (see for example https://www.discretization.de/media/filer_public/2015/11/16/a01-10-bss.pdf)  

---

## 2 answers

### Answer by username_2 on 2019-04-19. Score: 2 | Accepted answer

When performing the unfolding the way you want, after you have unfolded one triangle in the plane, the next one should be one of the three triangles, adjacent to the unfolded one, i.e. the next triangle to be unfolded shares a common edge with the unfolded one.

Assume you have a triangle $ABC$ in three space with vertices $$A = [A\_1, A\_2, A\_3], \,\, B = [B\_1, B\_2, B\_3],\,\, C = [C\_1, C\_2, C\_3]$$ which is one of the triangles from the 3D mesh.

**If** $ABC$ is the first triangle you are starting the unfolding with, then:

1. calculate $l\_{AB} = ||A - B|| = \sqrt{(A\_1 - B\_1)^2 + (A\_2 - B\_2)^2 + (A\_3 - B\_3)^2}$;
2. set the 2D vertices $a = [0,0]$ and $b = [l\_{AB}, 0]$ as well as $$l\_{ab} = l\_{AB};

**Else if** $ABC$ is a next triangle to be unfolded in the plane, i.e. you have already unfolded one of $ABC$'s adjacent (neighboring) triangles, therefore one of $ABC$'s edges is already unfolded in the plane. Say that this edge is $AB$ and it is unfolded in the plane as the edge with vertices $a = [a\_1, a\_2]$ and $b = [b\_1, b\_2]$, where $l\_{ab} = ||a-b|| = \sqrt{(a\_1 - b\_1)^2 + (a\_2 - b\_2)^2} = ||A-B|| = l\_{AB}$.

Either way, for the triangle $ABC$ you already have the edge $AB$ unfolded as $ab$ in the plane, so that $l\_{ab} = l\_{AB}$ (i.e. you already know $a, \, b$ and $l\_{ab}$). The question is, how do you find the coordinates of the third vertex $c = [c\_1, c\_2]$ so that $l\_{bc} = l\_{BC}$ and $l\_{ca} = l\_{CA}$? We impose the latter two conditions because two triangles that have pairwise equal edge-lengths are congruent (isometric, i.e. identical copies of each other).

For your information, I will write vectors like $B - A = [B\_1 - A\_1, \, B\_2 - A\_2, \, B\_3 - A\_3]$ and $C - A = [C\_1 - A\_1, \, C\_2 - A\_2, \, C\_3 - A\_3]$ and $b-a = [b\_1 - a\_1, b\_2-a\_2]$ and will use dot product $\cdot$ and cross product $\times$ between vectors. You already know what $||B-A|| = l\_{AB}$ and $||C-A|| = l\_{CA}$ are and that $l\_{AB} = l\_{ab} = \|b-a\|$.

1. Calculate $$s = \frac{\|(B-A)\times(C-A)\|}{l\_{ab}^2}$$
2. Calculate $$c = \frac{(B-A)\cdot(C-A)}{l\_{ab}^2}$$
3. Calculate both pairs of coordinates
   \begin{align}
   &c'\_1 = a\_1 + c(b\_1-a\_1) - s(b\_2 - a\_2)\\
   &c'\_2 = a\_2 + c(b\_2-a\_2) + s(b\_1 - a\_1)
   \end{align}
   and
   \begin{align}
   &c''\_1 = a\_1 + c(b\_1-a\_1) + s(b\_2 - a\_2)\\
   &c''\_2 = a\_2 + c(b\_2-a\_2) - s(b\_1 - a\_1)
   \end{align}
4. You have two candidate points $c' = [c'\_1, c'\_2]$ and $c'' = [c''\_1, c''\_2]$
5. Perform a check whether $c'$ is on the same side of the edge $ab$ as the triangle unfolded right before $ABC$.

**If** it is not, then $c = c'$

**else if** it is, then $c = c''$

As a result of this procedure, you have constructed the planar unfolding $abc$ of triangle $ABC$ and the next triangle from the 3D mesh to be unfolded (if any), should be the one that shares either edge $BC$ or $CA$ with $ABC$. Either way, for that next triangle, you already know the unfolding $bc$ of the edge $BC$ and the unfolding $ca$ of $CA$ (whichever is relevant), so you can apply the same procedure for that next triangle. And so on and so forth, until you have unfolded all triangles from the mesh.

Have in mind that there are 3D meshes that do not posses unfolding that do not self overlap, no matter what you do. For such meshes there no greedy algorithms or any other algorithm that can do it.

> **Comments:**
> **username_0**: Hi, thank you for your response. I'm not sure if I can follow your solution. For matrix m I don't know any of these points?  
> **username_2**: @username_0 I thought you had those. In your question you are asking about the transformation matrices. So do you need a method for calculating the coordinates of the vertices in the plane?  
> **username_0**: The coordinates on the plane, do not matter for me (it can be transformed to any position on the plane), I'd only need to do this transformation to the plane of the first triangle and then accordingly transform all other triangles too. I'm sorry if i was unclear :(  
> **username_2**: @username_0 Do you want each triangle from the 3D mesh to be transformed isometrically, i.e. the original triangle and the triangle in the plane to be congruent (to be identical copies of each other)? In this case the unfolding may self-intersect. Or is there any other geometric requirement? And what matrices are you asking about, because an infolding does not necessarily require matrices (angles or edge-lengths are enough), unless you want to transform points inside the triangles.  
> **username_2**: @username_0 Are you trying to rotate the whole 3D mesh so that one triangle ends up on the plane, then rotate it again, for the next triangle to land on the plane and so on? Like rolling the 3D mesh on the plane?  
> **username_0**: The overlaps/intersects I would handle separately. A greedy algorithm will try to figure out a unfolding, where there are no overlaps.  The unfolded triangles should be identical copies (i.e. after unfolding I want to be able to recreate the original model) I thought for unfolding I'd need matrices, how could I do it through the angles and length?  
> **username_2**: @username_0 I changed my post, so now you can see a sketch of an algorithm of unfolding using edge-lengths.  

---

### Answer by username_3 on 2019-04-19. Score: 0

Unfolding the mesh the way you describe it, most likely you will end up with overlapping triangles in the 2D plane unless your 3D geometry is simple. If that's ok, one laborious way is to compute the distances of the triangle sides and the angles and construct the triangle again in the 2D plane.
For example, set:

a = (0,0)

b = (0,D1)

c = (D2\*cos(phi), D2\*sin(phi))

where

D1 is the distance between a and b in 3D,

D2 is the distance between a and c in 3D,

and phi is the angle at the a point.

Then using an affine transformation you can transform the triangle where you want.

UV unwrapping, which was mentioned, is the way to go only if its not important to keep the shapes of the 3D triangles intact.

> **Comments:**
> **username_0**: Hi, thank you for your response! The overlaps will/should be removed by an greedy algorithm I plan to implement later, but for now I just want to unfold it to get a better feeling of what is happening (so no blind programming needs to be done).  I understand how I get to the 2D - triangle with your solution, but I'm not sure how I can "stick" the triangle together again with affine transformation, since here I lose all information of the real place of the triangle, do I?  

---

