# Calculating angle for connecting two objects

**URL:** <https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830>\
**Category:** Questions\
**Tags:** math, geometry\
**Created:** [September 24, 2019, 12:33pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830 "2019-09-24T12:33:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jos\_Bammens](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jos_bammens/32/7378_2.png) [@Jos\_Bammens](https://discourse.threejs.org/u/Jos_Bammens)\
**Post date:** [September 24, 2019, 12:33pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/1 "2019-09-24T12:33:09Z")

</div>

Hello guys,

I’m trying to add two objects together when two corners of them both are cut off. The way I am trying to do this is creating two objects, cutting one corner of each of them with CSG and then rotating and repositioning one of them so they fit.  
When the two corners fit perfectly there is no problem, but when they don’t I would like to rotate the object so they do fit.

Like in these images:

Non connected objects:

 ![32](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/9/9be57b5fc925833a74ab59c83906054e4fea0b08.png)

Connected objects (the result I would like to see):

 ![23](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/3/39854702fb4a4048806e2de13fcfc21021528640.png)

I would use the angleTo method but after rotating the object the vectors are not correct anymore.

Does anyone know how I could get the “new” vectors, or another way I could go about achieving my goal?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [September 24, 2019, 1:12pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/2 "2019-09-24T13:12:18Z")

</div>

Hi!  
If you know the angle of cut, then the angle between meshes is double value of cut.  
Means, cut is 45 degrees, between meshes is 90 degrees. Cut is 30 degrees, between meshes is 60 degrees. And so on.

Quick example:  
[https://jsfiddle.net/prisoner849/ysqnLae1/](https://jsfiddle.net/prisoner849/ysqnLae1/)  
 ![Cut_Angle](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/8/83b632fafbe9ebb5a200fda7beb776238d9241e1.png)  
Cut angle is 35 degrees.

---

<div class="post-metadata">

**Author:** ![Jos\_Bammens](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jos_bammens/32/7378_2.png) [@Jos\_Bammens](https://discourse.threejs.org/u/Jos_Bammens)\
**Post date:** [September 24, 2019, 3:11pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/3 "2019-09-24T15:11:37Z")

</div>

Thank you very much! I’m going to try this and let you know!

---

<div class="post-metadata">

**Author:** ![Jos\_Bammens](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jos_bammens/32/7378_2.png) [@Jos\_Bammens](https://discourse.threejs.org/u/Jos_Bammens)\
**Post date:** [September 25, 2019, 9:06am UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/4 "2019-09-25T09:06:34Z")

</div>

Your answer helped me a lot. I looked at your Fiddle and tried using Math.degToRad with the same angle as you and my mesh only rotates very slightly…

The top one is the one that needs rotating:

 ![12](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/8/890af635548cc6cb5d474cb63204203a0ae65e98.png)

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [September 25, 2019, 9:10am UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/5 "2019-09-25T09:10:36Z")

</div>

I simply do it like that: `meshB.rotation.z = THREE.Math.degToRad(angle * 2);`, considering that `angle` is in degrees, not in radians.

Could you provide a live code example of what and how you do?

---

<div class="post-metadata">

**Author:** ![Jos\_Bammens](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jos_bammens/32/7378_2.png) [@Jos\_Bammens](https://discourse.threejs.org/u/Jos_Bammens)\
**Post date:** [September 25, 2019, 9:15am UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/6 "2019-09-25T09:15:11Z")

</div>

My angle is in degrees too though. I calculated the degrees of the angles, which were 33. I’ll try and post a live example

---

<div class="post-metadata">

**Author:** ![Jos\_Bammens](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jos_bammens/32/7378_2.png) [@Jos\_Bammens](https://discourse.threejs.org/u/Jos_Bammens)\
**Post date:** [September 25, 2019, 12:13pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/7 "2019-09-25T12:13:47Z")

</div>

While I was making the Fiddle I saw that I overlooked the code where I converted the angle into radians already, so your solution did work!

Bit of an oversight on my part. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![EliasHasle](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/eliashasle/32/3010_2.png) [@EliasHasle](https://discourse.threejs.org/u/EliasHasle)\
**Post date:** [September 25, 2019, 1:37pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/8 "2019-09-25T13:37:32Z")

</div>

> [@Jos\_Bammens](#):
>
> after rotating the object the vectors are not correct anymore.

I suppose this is because the vectors are in local coordinates. You can transform both to global coordinates before checking the angle between them again.

---

<div class="post-metadata">

**Author:** ![Jos\_Bammens](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jos_bammens/32/7378_2.png) [@Jos\_Bammens](https://discourse.threejs.org/u/Jos_Bammens)\
**Post date:** [September 25, 2019, 2:02pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/9 "2019-09-25T14:02:20Z")

</div>

The position of the object is in world coordinates. After rotation the object is somewhere else in the “world” but the coordinates are still the same as “pre-rotation”. Which makes it hard to put these two object together since the coordinates of the second object aren’t correct.

---

<div class="post-metadata">

**Author:** ![EliasHasle](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/eliashasle/32/3010_2.png) [@EliasHasle](https://discourse.threejs.org/u/EliasHasle)\
**Post date:** [September 25, 2019, 2:22pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/10 "2019-09-25T14:22:54Z")

</div>

The position of the object may be in world coordinates, but the positions in the geometry are in local coordinates.

---

<div class="post-metadata">

**Author:** ![Jos\_Bammens](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jos_bammens/32/7378_2.png) [@Jos\_Bammens](https://discourse.threejs.org/u/Jos_Bammens)\
**Post date:** [September 25, 2019, 2:36pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/11 "2019-09-25T14:36:19Z")

</div>

Yes that’s true. Isn’t transforming these local coordinates of the geometry going to result in the same (world)coordinates that my object has?

---

<div class="post-metadata">

**Author:** ![EliasHasle](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/eliashasle/32/3010_2.png) [@EliasHasle](https://discourse.threejs.org/u/EliasHasle)\
**Post date:** [September 25, 2019, 10:09pm UTC](https://discourse.threejs.org/t/calculating-angle-for-connecting-two-objects/9830/12 "2019-09-25T22:09:13Z")

</div>

If the objects are rotated using `object.rotation`, their local coordinate systems will be rotated, and then positions of geometry or children within the rotated coordinate systems can no longer be compared directly. But if you transform the positions to a common coordinate system, where global coordinates is the most obvious choice, you may again compare them, such as checking the angle between them.

I am happy you found another solution to your particular problem, though.
