<p>I suggest computing the normal vector for each polygon and compute the angle between the normal vector of one triangle and the normal vector of a plane perpendicular to the other surface that passes through the common edge.</p>

<p>See the following illustration, where the red arrows are the normal vectors of the red polygons. The blue vector is the plane perpendicular to the left polygon that passes through the edge common to both polygons.</p>

<p><img src="https://i.sstatic.net/NNxNR.png" alt="this image"></p>

<p>If your polygons are planar, then you can compute the normal for any polygon ABC by computing the cross product <code>AB x AC</code>.</p>

<p>To obtain the blue vector, take the cross product of the normal of the left polygon and the vector that is the common edge.</p>

<p>The angle you're looking for is formed between this blue vector and the normal to the other polygon (the red vector on the right in the diagram).</p>

<p>You then compute the cosine of the angle between two vectors <code>u</code> and <code>v</code> by taking their dot product, then dividing by their magnitudes.</p>

<p><img src="https://www.analyzemath.com/stepbystep_mathworksheets/3D_vectors/angle_vectors.png" alt="Angle between vectors"></p>

<p><em>Image taken from <a href="https://www.analyzemath.com/stepbystep_mathworksheets/vectors/vector3D_angle.html" rel="nofollow noreferrer">here</a>.</em></p>

CC BY-SA 4.0
2019-09-16T18:06:36.103Z
I don’t think this approach will quite work here. Since the dot product is symmetrical around 0°, it’ll have the same value whether the normals are pointing “slightly towards” or “slightly away” from each other. The blue stuff in your diagram is relevant, but it’d be worth explaining how to get that vector.
Noah Witherspoon
CC BY-SA 4.0
2019-09-16T18:11:30.630Z
You're right.  Sorry.  To get the blue vector you take the cross product of the normal vector and the common edge.  Then you compare the blue vector and the *other* red vector.  I'll update the answer.
Wyck
CC BY-SA 4.0
2019-09-16T18:19:11.707Z
@NoahWitherspoon I've fixed it.  Thanks very much for pointing out that rather glaring omission.
Wyck
CC BY-SA 4.0
2019-09-16T22:16:20.063Z
While likely clear to the inclined geometry enthusiast, it's probably worth noting that direction very much matters here (as it usually does in a cross product), otherwise nothing stops me from using the common edge vector the "wrong" way around (or knowing which way is the "right" one to begin with) and basically again sitting there without knowing if the angle is the right way around. I mean, the approach is good and works, but it can't hurt to explain what's *actually* going on here.
Christian Rau
CC BY-SA 4.0
2019-09-17T07:04:27.353Z
@ChristianRau The expected behaviour is most likely consistent with the normals used for back/front face culling, so the direction is already defined by the order in which the vertices are given.
lightxbulb
CC BY-SA 4.0
2019-09-16T15:08:25.950Z
2019-09-16T18:18:11.340Z
2019-09-16T18:18:11.340Z
Wyck
<p>For my application, I want to render models as polygonal surfaces in 3D space and have edges that are bent "outwards" to have a solid line and those who are bent "inwards" to have a dotted line. So if I look from the top of the edge if they "bend towards me" they are bending inwards, if they bend away from me, they bend outwards.</p>

<p>For this, I need to calculate the angle between two connected triangles.
How can I calculate this angle? How can I define if it is bent outwards or inwards (looking from the top it would always bend downwards if the angle is >180 and inwards (so up) if the angle is &lt;180, but how can I calculate this?</p>

CC BY-SA 4.0
2019-09-15T16:06:28.633Z
You might have to give a little more context here. I *think* I know what you're talking about but it's a little fuzzy. For example, are we talking about polygons in 3D-space here? Are they planar (though, it seems they are when you're concentrating on triangles)? When you say "looking from the top", do you actually mean "looking from the side"? It *seems* you're talking about the angle between adjacent triangles of a triangular mesh in 3D space, but I'm not entirely sure and a little more clarity and accuracy in the question's wording might be useful.
Christian Rau
CC BY-SA 4.0
2019-09-15T16:09:28.507Z
I'm sorry for the unclear question.
It is in 3D space. The triangles are planar.
2 Triangles always share one common edge.
For this edge I want to know if it is bent outwards or inwards. So if i look from the top of the edge if they "bend towards me" they are bending inwards, if they bend away from me, they bend outwards.
Does this make sense?
edit: maybe instead looking from the top, it is better to say that I look from the outside of the two triangles (their front faces)
Anima
CC BY-SA 4.0
2019-09-15T16:11:50.217Z
Yes, that helps. I tried to extend the question a little.
Christian Rau
<3d><vectors>
Calculating the angle between two polygons
Anima
# Calculating the angle between two polygons

(Asked by: username_0 on 2019-09-15)

For my application, I want to render models as polygonal surfaces in 3D space and have edges that are bent "outwards" to have a solid line and those who are bent "inwards" to have a dotted line. So if I look from the top of the edge if they "bend towards me" they are bending inwards, if they bend away from me, they bend outwards.

For this, I need to calculate the angle between two connected triangles.
How can I calculate this angle? How can I define if it is bent outwards or inwards (looking from the top it would always bend downwards if the angle is >180 and inwards (so up) if the angle is <180, but how can I calculate this?

**Tags:** 3d, vectors

> **Comments:**
> **username_1**: You might have to give a little more context here. I *think* I know what you're talking about but it's a little fuzzy. For example, are we talking about polygons in 3D-space here? Are they planar (though, it seems they are when you're concentrating on triangles)? When you say "looking from the top", do you actually mean "looking from the side"? It *seems* you're talking about the angle between adjacent triangles of a triangular mesh in 3D space, but I'm not entirely sure and a little more clarity and accuracy in the question's wording might be useful.  
> **username_0**: I'm sorry for the unclear question. It is in 3D space. The triangles are planar. 2 Triangles always share one common edge. For this edge I want to know if it is bent outwards or inwards. So if i look from the top of the edge if they "bend towards me" they are bending inwards, if they bend away from me, they bend outwards. Does this make sense? edit: maybe instead looking from the top, it is better to say that I look from the outside of the two triangles (their front faces)  
> **username_1**: Yes, that helps. I tried to extend the question a little.  

---

## 1 answers

### Answer by username_2 on 2019-09-16. Score: 4 | Accepted answer

I suggest computing the normal vector for each polygon and compute the angle between the normal vector of one triangle and the normal vector of a plane perpendicular to the other surface that passes through the common edge.

See the following illustration, where the red arrows are the normal vectors of the red polygons. The blue vector is the plane perpendicular to the left polygon that passes through the edge common to both polygons.

![this image](https://i.sstatic.net/NNxNR.png)

If your polygons are planar, then you can compute the normal for any polygon ABC by computing the cross product `AB x AC`.

To obtain the blue vector, take the cross product of the normal of the left polygon and the vector that is the common edge.

The angle you're looking for is formed between this blue vector and the normal to the other polygon (the red vector on the right in the diagram).

You then compute the cosine of the angle between two vectors `u` and `v` by taking their dot product, then dividing by their magnitudes.

![Angle between vectors](https://www.analyzemath.com/stepbystep_mathworksheets/3D_vectors/angle_vectors.png)

*Image taken from [here](https://www.analyzemath.com/stepbystep_mathworksheets/vectors/vector3D_angle.html).*

> **Comments:**
> **username_3**: I don’t think this approach will quite work here. Since the dot product is symmetrical around 0°, it’ll have the same value whether the normals are pointing “slightly towards” or “slightly away” from each other. The blue stuff in your diagram is relevant, but it’d be worth explaining how to get that vector.  
> **username_2**: You're right.  Sorry.  To get the blue vector you take the cross product of the normal vector and the common edge.  Then you compare the blue vector and the *other* red vector.  I'll update the answer.  
> **username_2**: @username_3 I've fixed it.  Thanks very much for pointing out that rather glaring omission.  
> **username_1**: While likely clear to the inclined geometry enthusiast, it's probably worth noting that direction very much matters here (as it usually does in a cross product), otherwise nothing stops me from using the common edge vector the "wrong" way around (or knowing which way is the "right" one to begin with) and basically again sitting there without knowing if the angle is the right way around. I mean, the approach is good and works, but it can't hurt to explain what's *actually* going on here.  
> **username_4**: @username_1 The expected behaviour is most likely consistent with the normals used for back/front face culling, so the direction is already defined by the order in which the vertices are given.  

---

