Ask Your Question

# Quaternion to Rotate Rigid Frame

I have arbitrary planes defined by coefficients A,B,C,D such that Ax + By + Cz + D = 0.

I want to fit a solid box over each plane such that one short edge of the box is perpendicular to the normal of the plane, with the other two edge lengths being longer, and with one of the other two edges parallel to the horizontal XY plane. I've been able to construct the position of the box but making the orientation has been tricky.

The coefficients given above for the plane make it really easy to get the normal vector to the plane N = (A,B,C). The way I've been trying to compose the orientation of the box is:

1. Create a vector V normal to the global X axis and to the plane's normal vector by taking their cross product
2. Using a dot product determine the angle theta between the global X axis and the plane normal N
3. Create a quaternion using theta and V as the angle and rotation axis.

Using that quaternion for the object orientation gets me a box with its X-axis normal to the plane, but doesn't account for rotation of the box about its own X-axis. To get one of the edges (here its Y-axis) of the box parallel to the ground XY plane, I've been trying:

1. Rotate the global Y-axis by the previously made quaternion using tf::quatRotate to produce the intermediate local Y-axis Y'
2. Take the cross product of N and the global Z-axis to get a vector E parallel to the target plane and to the XY plane (E is the desired local box Y-axis)
3. Determine the angle between the E and Y' vectors
4. Use that angle and N to make a second quaternion, multiple this with the first quaternion to get the final box orientation

I haven't actually been able to get the second part to completely work yet, although I think the logic makes sense? But I was wondering if there were any utilities in TF that I've overlooked which might make this whole process easier / anywhere this is already implemented.

Fundamentally I just want to find the quaternion necessary to rotate a pair of perpendicular axes to a desired orientation, from a given start orientation, where the start and end axes are all defined as vectors.

edit retag close merge delete

## 1 Answer

Sort by » oldest newest most voted It sounds like the look_at_pose package does the same thing, but it uses dyads (similar to matrices). See https://math.stackexchange.com/questi...

I don't know the answer for quaternions.

more

## Comments

Hmm, ok, thanks! I'll definitely look into this at some point because I haven't used dyads before.

My implementation above is actually working now, though - I was just incorrectly initializing my tf::quaternions w,x,y,z instead of x,y,z,w !

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2017-07-14 10:39:40 -0500

Seen: 396 times

Last updated: Jul 14 '17