# angle\_between +/- results

**URL:** <https://forums.sketchup.com/t/angle-between-results/8781>\
**Category:** Ruby API\
**Created:** [March 19, 2015, 1:05am UTC](https://forums.sketchup.com/t/angle-between-results/8781 "2015-03-19T01:05:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![braddenn](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@braddenn](https://forums.sketchup.com/u/braddenn)\
**Post date:** [March 19, 2015, 1:05am UTC](https://forums.sketchup.com/t/angle-between-results/8781/1 "2015-03-19T01:05:08Z")

</div>

Been a while since I’ve been in a math course but this struck me an not quite correct - and my program does not work correctly. So:  
Consider 3 vectors  
1, 0, 0 is the reference - the x axis, X  
0,0,1 is vector A, the z axis (up)  
0,0,-1 is vector B, the -z axis (down)

Now, the angle from A to X is 1.57 radians. So, also, says angle\_between.  
But, angle\_between says B to X is ALSO 1.57 radians.

This cannot be right. B is opposite A. B to X must be 6.123 radians.

OK, some code:  
vRef = Geom::Vector3d 1,0,0  
vA = Geom::Vector3d 0,0,1  
vB = Geom::Vector3d 0,0,-1  
puts "vRef to vA is #{vRef.angle\_between vA} "  
puts “vRef to vB is #{vRef.angle\_between vB}”

Results:  
vRef to vA is 1.5707963267948966  
vRef to vB is 1.5707963267948966  
NOT!  
You might ask - what is the reference? The right-hand rule via the cross product of the two vectors. Note also the normal of a face - it must be + or - depending on the order of the points that define the face - again by the right-hand rule.

---

<div class="post-metadata">

**Author:** ![jim\_foltz](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/jim_foltz/32/74787_2.png) [@jim\_foltz](https://forums.sketchup.com/u/jim_foltz)\
**Post date:** [March 19, 2015, 1:17pm UTC](https://forums.sketchup.com/t/angle-between-results/8781/2 "2015-03-19T13:17:29Z")

</div>

`angle_between` always returns a positive. It may not be what you expect, but it is not technically incorrect. If you need angles greater than 180 or direction in the form of +/- then you need to do the math yourself. The Ruby API does not have those methods.

---

<div class="post-metadata">

**Author:** ![braddenn](https://avatars.discourse-cdn.com/v4/letter/b/f05b48/32.png) [@braddenn](https://forums.sketchup.com/u/braddenn)\
**Post date:** [March 20, 2015, 3:21am UTC](https://forums.sketchup.com/t/angle-between-results/8781/3 "2015-03-20T03:21:04Z")

</div>

Ah ha - then the answer is simple. Use the angle provided by angle\_between, Then use the sum of the product of the coefficients to determine the sign: i.e.  
a1_b1 + a2_b2 + a3\*b3  
The sign of this is the sign of the angle. Simple and cheap to calculate. Right?
