1

How can you rotate an object (let's say, its positions are at (5, 5, 0)) with the pivot point at let's say (3, 4, 0), even if the original point of rotation is (0, 0, 0)?

Here is a graphical explanation:

explain

I want to rotate the object in relation to the custom pivot point. The object is made in blender in such a way, that the object is away from the origin (at the point (5, 5, 0)).

How can we use matrices to solve this?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Coder101
  • 11
  • 2
  • although it can be done, why not move it to origin at first place? – apple apple Feb 18 '19 at 13:47
  • possible cross-site duplicate: https://math.stackexchange.com/q/2093314 – perivesta Feb 18 '19 at 13:48
  • 1
    no matter how you do it, it will be equivalent to moving the object to the origin, rotate around origin, then move back. Rather unclear what specifically is your problem – 463035818_is_not_an_ai Feb 18 '19 at 13:52
  • Pretty simple concept, in an armature hierarchy, each bone has a child (s), or a parent (s). If you want to move the arm you would be moving the hand, fingers, and all the children of that arm, and you want to move them in relation to the arm (pivot point), rather than the whole mesh's pivot point. So how can you rotate all the children of the arm according to the arm pivot point, rather than the whole object's pivot. – Coder101 Feb 18 '19 at 13:56
  • the strategy is always the same, you move the object such that the objects will rotate around the origin, then you rotate around the origin, then you move the objects back – 463035818_is_not_an_ai Feb 18 '19 at 14:05
  • Possible duplicate of [Opengl rotation at a point](https://stackoverflow.com/questions/7631890/opengl-rotation-at-a-point) – BDL Feb 18 '19 at 14:05

1 Answers1

2

As it was already pointed out in the comments, the easiest approach would be to translate the object so the pivot point is at the origin, then rotate the object around the origin, and then translate it back. Each of the these steps can be done using a matrix; multiplying these matrices should result in a matrix that does all this at once.

In the given example, these matrices would be:

1.translation by (-3,-4,0):
    [ 1, 0, 0,-3,
      0, 1, 0,-4,
      0, 0, 1, 0,
      0, 0, 0, 1 ]

2. rotation (in this example by 90 degrees)
    [ 0, 1, 0, 0,
     -1, 0, 0, 0,
      0, 0, 1, 0,
      0, 0, 0, 1 ]

3. translation by (3,4,0)
    [ 1, 0, 0, 3,
      0, 1, 0, 4,
      0, 0, 1, 0,
      0, 0, 0, 1 ]

This would then result in the following matrix as the final transformation:

    [ 0, 1, 0,-1,
     -1, 0, 0, 7,
      0, 0, 1, 0,
      0, 0, 0, 1 ]

You may need to change the order of multiplication depending on your implementation details, but in general this should work.

peabrainiac
  • 998
  • 9
  • 16