Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular Velocity vs Quaternions #566

Open
RobertMtx opened this issue May 20, 2022 · 1 comment
Open

Angular Velocity vs Quaternions #566

RobertMtx opened this issue May 20, 2022 · 1 comment

Comments

@RobertMtx
Copy link

RobertMtx commented May 20, 2022

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.

@gyeomannvidia
Copy link

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants