Notifications
Clear all

[Closed] Getting a quaternion from cross product of 2 vectors?

I thought I understood quaternions as being a vector and a rotation value about that vector, but it seems like this is not the case at all.

Ive been struggling to figure how quats work at all, and any values I input seem to have completely arbitrary results.

Anyway, what im trying to do is create a coordinate system on an open edge so that X is parallel to the edge and Z is parallel to the normal of the edge’s face (or as close as possible, if the edge and normal are not perpendicular) It would also be nice if Y would point away from the face.

What I have so far is i convert the edge to a vector, get the normal of the face via polyop.getFaceNormal, then I just get stumped by the enigma that is quaternions.

Any math wizards have any ideas about how to go about this?

3 Replies

Why deal with quaternions at all? Just convert to a transform (matrix3). From there you can convert to a quat if you really need it.

Create a cross product between your 2 vectors and use those 3 vectors to construct the matrix. If the vectors aren’t all orthogonal you can easily make them so by setting your 2nd vector to the cross product of the first and third. Make sure you normalize all the vectors as well

something like (no scale):

(
	v1 = normalize v1
	v2 = normalize v2
	axis = normalize (cross v1 v2)
	angle = acos (dot v1 v2)
	(angleaxis angle axis) as quat
)

Thanks for the help guys! I ended up going with a matrix3 solution as suggested by inanisavich. Reason I was messing with quats at all was because I didnt really understand how transform matrices work either, but now that I looked in to them it seems like a considerably simpler solution to my problem, and also a flexible tool to use in other places too!

	tm = matrix3 axis (cross axis normal) normal tmCenter