# Determine Angles

**URL:** <https://forums.sketchup.com/t/determine-angles/46861>\
**Category:** Developers\
**Created:** [June 19, 2017, 3:56pm UTC](https://forums.sketchup.com/t/determine-angles/46861 "2017-06-19T15:56:38Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [June 19, 2017, 3:56pm UTC](https://forums.sketchup.com/t/determine-angles/46861/1 "2017-06-19T15:56:38Z")

</div>

I have a bit of code that does calculate the angle between 2 faces. The 2 faces share a common edge and they are both oriented correctly.

```auto
          if (edge.faces.length == 2)
            angle = edge.faces[0].normal.angle_between(edge.faces[1].normal)
            angle = angle.radians
            angle = ((angle * 100).round).to_f / 100.0

```

If the angle === 0 then I ignore it - but if there is an angle I want to figure out the inside angle and the corresponding outside angle.

This example returns 20.3 degrees but I’m looking for inside 200.3 degrees and outside 159.7 degrees. The second example has the inside and outside switched.

 ![](https://global.discourse-cdn.com/sketchup/original/3X/4/f/4fb8e34c38a080c506cbd8f3d71b3cefd763c895.png)

---

<div class="post-metadata">

**Author:** ![john\_mcclenahan](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/john_mcclenahan/32/135377_2.png) [@john\_mcclenahan](https://forums.sketchup.com/u/john_mcclenahan)\
**Post date:** [June 19, 2017, 6:01pm UTC](https://forums.sketchup.com/t/determine-angles/46861/2 "2017-06-19T18:01:17Z")

</div>

You might find it helpful to look at the code for Angular Dimension 2 or even the the original Angular Dimension plugin by @slbaumgartner (Steve Baumgartner). He wrote the code to measure the angle between two edges given three picked vertices, the middle pick being the common vertex. I think you could supply the equivalent from two planes with a common edge.

They are free, from SketchUcation Plugin Store.

I think that SU `angle_between` always returns an angle less than 180 so you have to figure out when to add 180.

And I see that 200.3 = 180 + 20.3.

And also that if you draw the normals in your diagram with a common vertex on the edge, you would expect to get 20.3°, not 159.7°, wouldn’t you?

If you want to get the obtuse angle, try reversing the direction of one normal.

---

<div class="post-metadata">

**Author:** ![Aerilius](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@Aerilius](https://forums.sketchup.com/u/Aerilius)\
**Post date:** [June 19, 2017, 6:04pm UTC](https://forums.sketchup.com/t/determine-angles/46861/3 "2017-06-19T18:04:06Z")

</div>

We cannot reproduce the numbers (since we don’t have the model).

Have you tried calculating your math for edge cases? E.g.

- two coplanar faces: normals are parallel (angle 0°) and you probably want to get 180° outside (frontside) / inside (backside)
- right angle: normals are at 90° and you want 270° outside (frontside) or 90° inside (backside)
- coplanar opposed (in theory, SketchUp merges faces): normals at 180°, you want 360° outside (frontside) or 0° inside (backside)

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [June 19, 2017, 6:35pm UTC](https://forums.sketchup.com/t/determine-angles/46861/4 "2017-06-19T18:35:32Z")

</div>

> [@john\_mcclenahan](#):
>
> I think that SU angle\_between always returns an angle less than 180 so you have to figure out when to add 180.

I believe this is correct.

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [June 19, 2017, 6:45pm UTC](https://forums.sketchup.com/t/determine-angles/46861/5 "2017-06-19T18:45:52Z")

</div>

And to figure it out…

Get the ‘.cross’ between those two vectors.  
Get the cross’s Z and if it’s +/- determines the angle direction.  
I there’s no cross result they are probably co-linear ?

---

<div class="post-metadata">

**Author:** ![john\_mcclenahan](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/john_mcclenahan/32/135377_2.png) [@john\_mcclenahan](https://forums.sketchup.com/u/john_mcclenahan)\
**Post date:** [June 19, 2017, 6:59pm UTC](https://forums.sketchup.com/t/determine-angles/46861/6 "2017-06-19T18:59:06Z")

</div>

I think this represents graphically what i was trying to say earlier:

 ![](https://global.discourse-cdn.com/sketchup/original/3X/4/6/467407db24154455db358c39d868cada845b44c6.png)

Still looks to me that if you reverse one normal, you get 159.7° as the returned angle. Then you have to figure out whether you want that, or its complement (180 + 20.3 = 200.3° or 360 - 159.7 = 200.3°) as the result,

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [June 19, 2017, 8:22pm UTC](https://forums.sketchup.com/t/determine-angles/46861/7 "2017-06-19T20:22:38Z")

</div>

Thanks guys for your input.

Of course when you look at the model you can immediately determine if you need to add 180 to the angle or subtract the angle from 180.

What I’m trying to figure out is how to do that inside a script I will play around with the cross as Tig suggests and see if that gives me what I want.

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [June 19, 2017, 10:10pm UTC](https://forums.sketchup.com/t/determine-angles/46861/8 "2017-06-19T22:10:06Z")

</div>

I looked at the Angular Dimension code. That part will work but I need to determine the proper vectors.

If I start with the mid point of the common edge and then draw one line on the 2 faces where each line is perpendicular to the common edge then I can get Angular Dimension to produce the correct results.

[angles.skp](https://forums.sketchup.com/uploads/short-url/mB9Rgbg2br87hNqPTjpua1mrBtr.skp) (15.8 KB)

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [June 20, 2017, 2:59pm UTC](https://forums.sketchup.com/t/determine-angles/46861/9 "2017-06-20T14:59:29Z")

</div>

I’ve now got better results. The added lines (vectors) are perpendicular to the common edge and are only there temporarily during the test phase.

I did a cross between the 2 vectors but I really can’t determine from the results when to use the compliment.

 ![](https://global.discourse-cdn.com/sketchup/original/3X/1/f/1fea2abf04de150fef87b15c83b0027dd3a7b7bf.png)

---

<div class="post-metadata">

**Author:** ![john\_mcclenahan](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/john_mcclenahan/32/135377_2.png) [@john\_mcclenahan](https://forums.sketchup.com/u/john_mcclenahan)\
**Post date:** [June 20, 2017, 3:57pm UTC](https://forums.sketchup.com/t/determine-angles/46861/10 "2017-06-20T15:57:56Z")

</div>

Can you describe in words when to use one rather than the other?

For example, if either or both face normals face ‘up’, use (obtuse) angle

If both normals ‘face down’ (back faces are both ‘up’) use complement?

You can test the z value to find ‘which way is up’ (z `>0`).

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [June 20, 2017, 4:12pm UTC](https://forums.sketchup.com/t/determine-angles/46861/11 "2017-06-20T16:12:28Z")

</div>

John,

The 2 faces belonging to the common edge can be facing absolutely any direction.

Essentially I want the angle for the 2 faces but only from the front faces. The one on the left is 141.18 - the one on the right should be 218.82

---

<div class="post-metadata">

**Author:** ![john\_mcclenahan](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/john_mcclenahan/32/135377_2.png) [@john\_mcclenahan](https://forums.sketchup.com/u/john_mcclenahan)\
**Post date:** [June 20, 2017, 4:26pm UTC](https://forums.sketchup.com/t/determine-angles/46861/12 "2017-06-20T16:26:46Z")

</div>

Then maybe try ‘if the intersection of the normals from the ends of the short lines you have drawn out from the edge is on the face side (of either face), use less than 180°, otherwise use the complement’?

Can you have one face the reverse of the other at the common edge? If so, I think the answer is indeterminate.

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [June 20, 2017, 4:42pm UTC](https://forums.sketchup.com/t/determine-angles/46861/13 "2017-06-20T16:42:44Z")

</div>

All faces are oriented properly.

What I am trying to do right now is this:

1. Create a temporary group
2. inside the group create another group that I will later explode
3. Use the normal from 1 of the 2 faces to create a transformation that will flatten that face and place it at ground level
4. create both faces inside the group that will be exploded
5. Apply the transformation and explode
6. One of the faces will be on the ground plane and the other will have vertices either above or below the ground plane.

This seems like overkill - but I think it will work.

---

<div class="post-metadata">

**Author:** ![john\_mcclenahan](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/john_mcclenahan/32/135377_2.png) [@john\_mcclenahan](https://forums.sketchup.com/u/john_mcclenahan)\
**Post date:** [June 20, 2017, 4:47pm UTC](https://forums.sketchup.com/t/determine-angles/46861/14 "2017-06-20T16:47:01Z")

</div>

Sounds as though it should. I can’t remember the Ruby method(s) that enable you to tell whether a point is on the plane of a face, [Edit: on the face side, or the reverse side] but I’m sure there is one.

---

<div class="post-metadata">

**Author:** ![gkernan](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gkernan](https://forums.sketchup.com/u/gkernan)\
**Post date:** [June 20, 2017, 6:08pm UTC](https://forums.sketchup.com/t/determine-angles/46861/16 "2017-06-20T18:08:21Z")

</div>

I’ve got it working with the temporary groups

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [September 20, 2017, 10:08am UTC](https://forums.sketchup.com/t/determine-angles/46861/17 "2017-09-20T10:08:31Z")

</div>

Closed on September 20, 2017, 10:08am UTC

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.
