NVIDIAGameWorks/PhysX

Angular Velocity vs Quaternions

RobertMtx opened this issue · 1 comments

I may just be having a dumb moment, but I'm having some trouble wrapping my head around the angular velocity component in PhysX.

Angular velocity is expressed as a vector-3. Does this mean it is equivalent to Euler angles or yaw-pitch-roll?

I'm used to working with rotations as quaternions, matrices, or axis-angles, so I'm probably tripping over myself more than is necessary.

What I'm trying to accomplish is to compute a unit rotation (and translation) between two full/absolute transforms (quaternion + vector), then convert that into linear and angular velocity. IE, convert 2 keyframes into velocity. But I got hung up when I started to convert my rotation into an angular velocity vector.

I've converted Euler into quaternion, but not the other way around. After looking around online, I managed to scrape together this function out of bits and pieces:

vec3 qtn::Eulers() const
{
	return vec3(
		atan2(-2.0f * ( x * y - w * z ),w * w + x * x - y * y - z * z),
		asin(2.0f * ( x * z + w * y )),
		atan2(-2.0f * ( y * z - w * x ),w * w - x * x - y * y + z * z)
	);
}

My project is still not at a stage where I can test things. I don't expect anyone to confirm the math for me, but could anyone tell me if I'm heading in the right direction? Can I generate this vector, scale it (if necessary), then upload that to a body as angular velocity?

EDIT: After doing some more research, it seems there is yet another way to represent a rotation - especially when that rotation is representing an angular velocity. And that is to define a unit vector for the rotation axis, then scale that axis by the angle-velocity-length (per second). Now I'm not a math wiz, but that seems very similar to a Euler angle vector. Perhaps when it comes to velocity, there really isn't a difference between Euler angles and a scaled axis? If anyone can shed some light on this for me, I would really appreciate it.

I'm assuming there is code somewhere under the hood of PhysX that would help me understand angular velocity. Most likely the code that applies that velocity to the current body's rotation. But I haven't been able to locate that bit yet.

Sorry to drag this out. Really appreciate any guidance.

Something like this should work:

PxVec3 computeAngularVelocity(PxQuat q1, PxQuat q2, float dt)
{
PxQuat dq = q2 * q1.getConjugate();

float angle;
PxVec3 axis;
q.toRadiansAndUnitAxis(angle, axis);

PxVec3 omega = axis*(angle/dt);
return omega;

}

int main()
{
//q1 = q(t)
//q2 = q(t+dt)
PxQuat q1(0.1, PxVec3(0,1,0));
PxQuat q2(0.2, PxVec3(0,1,0));
PxVec3 omega = computeAngularVelocity(q1, q2, dt)
}