I'm trying to calculate the vector difference between a face normal and an object. This is similar to some other questions, such as this one:
I can get the cone to align properly in the example, but a very similar action using a vector other than 'Up' doesn't rotate the way I would expect.
In this example the cube is facing the opposite direction of the wall. I simply want to calculate the angle difference and rotate the cube to match the wall.
To accomplish that I use the following code (skipping to the important bits):
>>> norm Vector((-1.0, 0.0, 0.0)) >>> cabvec Vector((1.0, 0.0, 0.0)) >>> norm.rotation_difference(cabvec) Quaternion((-4.371138828673793e-08, -0.0, -0.7071067690849304, -0.7071067690849304))
Which flips it around, and turns it on its side (which may be happening to the cone also, but the cone shape is forgiving in this aspect).
What I would want in this situation is a result that simply flips the object on the z-axis 180 degrees. Which in the quaternion nomenclature would look like this:
>>> mathutils.Quaternion((0.0, 0.0, 1.0), math.radians(180.0)) Quaternion((-0.0, -0.0, -0.0, -1.0))
So I'm missing something on how to properly set up and calculate these rotations.
So this only appears to not work when the vectors are in opposite directions. If I move the wall slightly then it works fine:
norm --> <Vector (-0.9970, -0.0776, 0.0000)> qrot --> <Quaternion (w=0.0388, x=-0.0000, y=0.0000, z=0.9992)
I'm just learning about these rotation systems, but I was under the impression that issues with things like gimble lock would occur with Euler type rotations. Quaternion didn't have these types of limitations.
Either way I'm pretty sure the process itself is good because it works in all the other scenarios. So I don't know if I'm dealing with a math issue (can't perform this type of operation) or Blender issue (maybe need to present the info in a different way).