How to Rotate Mesh Along Certain Axis by Using rotationQuaternion?

Hi guys, thanks for reading this! Here is a very simple playground example!

I already have some basic idea about quaternion and rotation.

The problem is that a quaternion is defined by q = cos(theta/2) + i * sin(theta/2), which i represents the axis, but it only has a direction! Infinite numbers of axis can be defined by only a direction without a init point, so I can only assume that the axis always starts from the center of a mesh.

But what if I wish to rotate a mesh(like this ground) along any certain axis with both a direciton and a init point? Like a line starts from Vector3(0, 2, 0) and points at direction Vector3(1, 0, 0)?

In the example, I tried to move the ground mesh by a given displacement(y = +2), then I rotate it , then I do the opposite displacement, but the ground mesh have the same pose as I do not do any displacement but only rotation.

I wish there is a simple way to rotate a mesh along this line y=2 && direction = (1, 0, 0), by using rotationQuaterion property of a mesh!

Hope I made myself clear!

An axis is always an infinite line that pass thru (0,0,0)
You can’t move an axis but you can translate the mesh so the axis is moving relative to the mesh center.

I totally understand your theory and thats exactly what I’ve experienced in that PG.
Could you be more specific about “translate the mesh” ?
I did so by changing the position property of a mesh, as you could see in PG, I set the y position of that ground postion.y = 2, then I tried to do the rotation and then set position.y = 0. However it did not work.
Did you mean I have to change the position of all the vertices? Like if I have a triangle of 3 vertices, I then have to change the position of every vertex, then do the rotation along that axis?
Or Could you please do a demo on that PG?
Thanks again!

This can be achieved with a pivot:

the pivot point is relative to the mesh position, so it’s easy to compute its absolute value. Then, rotation applies around that pivot.

3 Likes

this is great ! thanks for the PG! Exactly what I need!

2 Likes