[Closed] rotation
Hi,
I need a plane that is rotated perpendicular to the vector between two vertices.
So I calculate all 3 euler angles using this:
angle = acos (dot N1 N2)
as N1 I use [1,0,0], [0,1,0] and [0,0,1] as vectors that represent the world orientation. And N2 is my vector
So this way I get the quat angle:
rotVect = eulerToQuat (eulerAngles angleX angleY angleZ)
Now when I use this rotation on my object it rotates around the (0,0,0) even though its pivot is geometry centered.
What do I do wrong?
Edit: I can make the rotation first and then adjust the position. But still the angle is not right
I can do this other way, like in Houdini.
Calculate double cross product of the vector to get 2 vectors perpendicular to this vector, which will give me the perpendicular plane I’m looking for.
But still how do I get the angle of the plane?
wow, thanks. I wasn’t thinking of actually creating the plane. But I can get the rotation from the created plane!
One strange thing happens now:
midVect = normalize(myVector)
nXvect = [1,0,0]
cross1vect = cross midVect nXvect
cross2vect = cross cross1vect midVect
n = cross2vect - cross1vect
p = plane transform:(matrixFromNormal n)
the created plane is not perpendicular to the midVect but parallel
Hm… Did I do the double cross product properly? I think so…
I mean you need to calculate the cross product of the vector and any other vector, to just get the prerpendicular vector (cross1vect),
and than calculate the cross product of this vector and your original vector.
This way you get two vectors perpendicular to the original vector and defining the plane.
Right?
Right, and you also don’t need to create the plane object, that was just for demonstration.
Actually I dont how to get the rotation without the plane. When I use sth like that:
fn setRot A B = (
rot = (matrixFromNormal (A – B)) as quat
)
I get the wrong rotation, But when I do this:
fn setRot A B = (
p = plane transform:(matrixFromNormal (A – B))
rot = p.rotation
)
everything is fine. Is it because of some matrix? I’m not very good with matrices…
Try this code. It’s what @lo is saying.
fn setRot p A B = (
p.transform = matrixFromNormal (A - B)
)
p = $Plane01 -- p contains your plane
A = [0,0,0]
B = [1,1,0]
setRot p A B
In any case, 3DSMax and angles is something curious.
In the next example you can see that the rotation is not the same than the rotation part of the transform matrix.
fn setRot p A B = (
p.transform = matrixFromNormal (A - B)
rot1_Q = p.transform.rotation
rot1_E = QuatToeuler p.transform.rotation
rot2_Q = p.rotation
rot2_E = QuatToeuler p.rotation
format "rotation1 Quat = %
" rot1_Q
format "rotation1 Euler = %
" rot1_E
format "rotation2 Quat = %
" rot2_Q
format "rotation2 Euler = %
" rot2_E
)
p = $Plane01
A = [0,0,0]
B = [1,1,0]
setRot p A B
rotation angle in euler angles depends on order of rotation about axis. for example Euler himself did it in order ZXZ
$.transform.rotation can be different than $.rotation because these two rotations are in different coordinate systems. the first one is absolute(world), the second is relative(parent)