 # Get difference between 2 normals and apply in another one?

Hi there!

Could someone help me in a doubt?

I have 2 normals, I want to get the difference between these 2 normals, so I have a new direction which would be the result of a (third direction + the difference of the initial 2).

Explanning a bit better:

1. I have NORMAL A and DIRECTION A

2. I have NORMAL B

3. I want to create DIRECTION B relative to NORMAL B, with the same angle DIRECTION A is based on NORMAL A.

Is it possible?

Thanks a lot!

The result you describe is ambiguous. You can create an extra vector from NORMAL B that has a similar angle to that normal B as the angle difference between NORMAL A + DIRECTION A. However, that vector can be rotated 360 around NORMAL B (around that vector) and keep the same angle between the two vectors. As such, many results are ‘valid’.

Thus I think the result you’d be getting isn’t exactly what you want.

But let’s give it a go using the Maya API.

``````import maya.api.OpenMaya as om

normal1 = om.MVector([0, 1, 0])
direction1 = om.MVector([0.5, 0.5, 0])

# Get the quaternion rotation between the two vectors
quat = normal1.rotateTo(direction1)

normal2 = om.MVector([1, 0, 0])
# Rotate the normal2 by a similar rotation
direction2 = normal2.rotateBy(quat)
print(direction2)
``````
1 Like

thanks a lot @BigRoyNL!
I understood what you meant, but I am planning to make an upvector to a similar direction, so they would match in the same orientation.
I will try your code and get back to you with the result.
thanks a lot!

Hi @BigRoyNL!
Your code worked great, thanks a lot!
I added this line so I can use quat in order to apply to the locator, the final direction:

`om.MQuaternion(YVector, direction2 , 1.0)`

I suppose I need to convert to quat if I want to apply the direction in a locator, correct?
thank u very much!