Apply force to bottom of object given rotation

49 Views Asked by At

I have a box and I want to apply a force in the direction that the bottom of the box is facing, given any Pitch, Roll, or Yaw rotation. At a resting point where pitch, roll, and yaw are 0, I know the downward force would be: x = 0, y = 0, z = -n, as the box is laying flat.

I also have the box's quaternion (qx, qy, qz, qw) available if that is helpful.

Here is a visual example showing my question:

A box with a pitch of 0

enter image description here

A box with a pitch of 90

enter image description here

How can I get this force using the objects rotation?

1

There are 1 best solutions below

0
On

I expanded my search terms to finding a force direction from a quaternion and was able to find an excellent answer by a user named Dobbs:

forward vector:

x = 2 * (xz + wy)

y = 2 * (yz - wx)

z = 1 - 2 * (xx + yy)

up vector:

x = 2 * (xy - wz)

y = 1 - 2 * (xx + zz)

z = 2 * (yz + wx)

left vector:

x = 1 - 2 * (yy + zz)

y = 2 * (xy + wz)

z = 2 * (xz - wy)

Using the "forward vector" with a negative magnitude I was able to apply a constant force onto the top of my object, no matter the orientation.