## Rotating an object relatively

Started by habi, Apr 06, 2020, 02:00 AM

#### habi

Today, i will show you a special type of rotation.

objects current 'position' ---> after rotation

this is the code
a.RotateTo( Multiply( a.Rotation, t( PI ) ), 2000 )

where t( PI ) = (0, 0, 1, 7.54979e-08) = ( 0, 0, 1, 0 )
and from my scripts...
[spoiler]`function Multiply(a,b)//Quaternions{ local v1=Vector(a.x,a.y,a.z); local v2=Vector(b.x,b.y,b.z); local r1=a.w; local r2=b.w; local r=r1*r2-Dot(v1,v2); local v=MultiplyWithScalar( v2, r1 ) + MultiplyWithScalar( v1, r2 ) + Cross(v1,v2); return Quaternion(v.x,v.y,v.z,r);}function Dot(v1,v2){ return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z;}function Cross(a,b){ local i=a.y*b.z-a.z*b.y local j=a.z*b.x-a.x*b.z local k=a.x*b.y-a.y*b.x return Vector(i,j,k);//you know these are not i j k, but components of it.}function MultiplyWithScalar( v, s ){ return Vector( v.x * s, v.y * s, v.z * s );}function r(a){return Quaternion(sin(a/2),0,0,cos(a/2))};function s(a){return Quaternion(0,sin(a/2),0,cos(a/2))};function t(a){return Quaternion(0,0,sin(a/2),cos(a/2))};`[/spoiler]

Hope it helps. If you like, i will show more this kind of things.
( btw, is this rotation possible by 'Euler' , i do not know. i have made use of Quaternion multiplication to achieve this. )

#### Sebastian

Imagine a garage door - you can "open" it no matter how it is rotated.
Good job!

#### PSL

Your code is very useful.  I can control buildings more easily and directly.All in all, well done

you are welcome