Calculating angle for connecting two objects

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:

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

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!

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/
Cut_Angle
Cut angle is 35 degrees.

3 Likes

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

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:

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?

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

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!

1 Like

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.

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.

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

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?

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.