# Rotation causes shift in position when object is assymetric around origin

**URL:** <https://discourse.threejs.org/t/rotation-causes-shift-in-position-when-object-is-assymetric-around-origin/63724>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [April 6, 2024, 10:30am UTC](https://discourse.threejs.org/t/rotation-causes-shift-in-position-when-object-is-assymetric-around-origin/63724 "2024-04-06T10:30:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhruvasagar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/dhruvasagar/32/46517_2.png) [@dhruvasagar](https://discourse.threejs.org/u/dhruvasagar)\
**Post date:** [April 6, 2024, 10:30am UTC](https://discourse.threejs.org/t/rotation-causes-shift-in-position-when-object-is-assymetric-around-origin/63724/1 "2024-04-06T10:30:41Z")

</div>

I am building a rubik cube simulation based the great work of others I found here [Animate rotateOnWorldAxis - #5 by PavelBoytchev](https://discourse.threejs.org/t/animate-rotateonworldaxis/56994/5).

However, I am trying to generalize the logic to an n-sized rubik cube and not just 3 sided.  
I have got almost everything except for even sided cubes the rotation seems to cause a weird shift in position of the layer. I suspect this is due to the assymetry around origin. I tried a few tricks to try to translate to get it to come back to the correct position but it does not seem to work.

Before rotation:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/4/e/4e2347947c3c5ee80f781f8e58c45bff3f40cf8a.jpeg)  
After rotation:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/0/2/02d5e308d5b3ae5c7a8598d0cc08b1182c3b057c.jpeg)

Note: When building the cube I am trying to center it to the scene so it starts with (- size / 2) and goes till ((size / 2) - 1), so for even 4 sided one this would be from -2 to 1.

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [April 6, 2024, 10:51am UTC](https://discourse.threejs.org/t/rotation-causes-shift-in-position-when-object-is-assymetric-around-origin/63724/2 "2024-04-06T10:51:40Z")

</div>

1. If there are some, doublecheck the parts of that use rounding - like Math.floor and Math.ceil. L
2. Use Box3 to debug origins of the parts you’re trying to rotate.

---

<div class="post-metadata">

**Author:** ![dhruvasagar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/dhruvasagar/32/46517_2.png) [@dhruvasagar](https://discourse.threejs.org/u/dhruvasagar)\
**Post date:** [April 6, 2024, 10:58am UTC](https://discourse.threejs.org/t/rotation-causes-shift-in-position-when-object-is-assymetric-around-origin/63724/3 "2024-04-06T10:58:41Z")

</div>

As I was writing this question, I had an eureka moment. The issue is because of the asymmetry of the coordinates for even sided rubik cubes. So what if I shifted the center by 0.5 such that the coordinates go from [-1.5, -0.5, 0.5, 1.5], instead of [-2, -1, 0, 1] ? As I switched to this logic, the rotation issue resolved itself. Since now the cube is symmetric around the origin, the rotation does not cause this shift in position anymore.
