# Weird behaviour while rotating intersection (manually calculating Inverse Kinematics)

**URL:** <https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489>\
**Category:** Questions\
**Created:** [December 16, 2023, 5:52pm UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489 "2023-12-16T17:52:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumpjack2](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jumpjack2/32/36712_2.png) [@jumpjack2](https://forum.babylonjs.com/u/jumpjack2)\
**Post date:** [December 16, 2023, 5:52pm UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/1 "2023-12-16T17:52:40Z")

</div>

This is my playground: [https://playground.babylonjs.com/#D25VJD#14](https://playground.babylonjs.com/#D25VJD#14)

When I rotate the vertical wall around its vertical axis, intersection does not rotate:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/7/47521ed867f2990fa3c856e77fce5fc03e2755b2.png)

When I rotate around Z, thins get even weirder…

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/d/3d0cbeeeda043ada7461c515e9919257d0b52dd8.png)

What’s going on here?!?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 20, 2023, 10:57am UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/2 "2023-12-20T10:57:59Z")

</div>

Passing `true` for the `absolute` parameter of `CSG.FromMesh` works:

> **[Babylon.js Playground](https://playground.babylonjs.com/#D25VJD%2325)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![jumpjack2](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jumpjack2/32/36712_2.png) [@jumpjack2](https://forum.babylonjs.com/u/jumpjack2)\
**Post date:** [December 20, 2023, 4:27pm UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/3 "2023-12-20T16:27:15Z")

</div>

Cool thanks.  
Now more difficult 😉

> **[Babylon.js Playground](https://playground.babylonjs.com/#D25VJD%2330)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

If you drag the flat gizmo, script will calculate this intersection:

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/d/bd165aa863ea1a4bf4aaaf9b644fa8fe05821e2d.png)

The white line should go from gizmo to that intersection… but I always get 0,0,0 as its position, why?!? I tried with the “true” you suggestes, no luck.

Relevant lines are 384-411.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 20, 2023, 7:00pm UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/4 "2023-12-20T19:00:39Z")

</div>

Your PG is getting a little too complicated… Are you able to reduce it to the bare minimum to show the problem?

---

<div class="post-metadata">

**Author:** ![jumpjack2](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jumpjack2/32/36712_2.png) [@jumpjack2](https://forum.babylonjs.com/u/jumpjack2)\
**Post date:** [December 21, 2023, 8:27am UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/5 "2023-12-21T08:27:47Z")

</div>

As I said, the problem is in lines 384-411, where I try to figure out which are the coordinates of the final section.

I intersect a circle with a sphere, obtaining two objects, which actually are seen like one single mesh by Babylon;  
so I subtract the “upper part of the world” from this mesh, thus obtaining only the intersection under the horizontal plane;  
but this single small mesh keeps having (0,0,0) as coordinates, regardless of any matrix update I do.

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/9/e957a576dcea4694b0a900820e302558d237ef3c.png)

---

<div class="post-metadata">

**Author:** ![jumpjack2](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jumpjack2/32/36712_2.png) [@jumpjack2](https://forum.babylonjs.com/u/jumpjack2)\
**Post date:** [December 22, 2023, 8:57am UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/6 "2023-12-22T08:57:25Z")

</div>

Ok, simplified PG:

> **[Babylon.js Playground](https://playground.babylonjs.com/#RN1JE7)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

How do I get actual position of the intersection?!? I get always 0.

---

<div class="post-metadata">

**Author:** ![jumpjack2](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jumpjack2/32/36712_2.png) [@jumpjack2](https://forum.babylonjs.com/u/jumpjack2)\
**Post date:** [December 22, 2023, 10:59am UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/7 "2023-12-22T10:59:50Z")

</div>

I found the solution but… should this be considered a bug? The intersection position is always 0,0,0, but the center of its bounding box changes properly:

> **[Babylon.js Playground](https://playground.babylonjs.com/#RN1JE7%234)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [December 22, 2023, 12:20pm UTC](https://forum.babylonjs.com/t/weird-behaviour-while-rotating-intersection-manually-calculating-inverse-kinematics/46489/8 "2023-12-22T12:20:07Z")

</div>

It’s not a bug, it’s because the CSG mesh is not centered relative to its local coordinate system (local (0,0,0) is not the center of the bounding box) when it is created.
