--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ee8a3775-1b14-4485-8657-262963977112%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If cubeA’s rotation is (0,0,0) and cubeC’s rotation is (100,200,300), cubeB’s rotation would be (50,100,150)
If this is what you’re looking to achieve, then you can achieve it by averaging each rotational channel individually.
cubeA = [0, 0, 0]
cubeC = [100, 200, 300]
cubeB = [
(cubeA[axis] + cubeC[axis]) * 0.5
for axis in range(3)
]
Which with nodes can be achieved with addDoubleLinear
for the addition and multDoubleLinear
for the multiplication.
This would support an infinite range of rotational values (and likely be faster than matrix multiplication). However, the result is likely not what you’d expect.. Simply averaging those values (known as “Euler Angles“) likely won’t look the way you’d expect. You can confirm this for yourself by taking an object, rotating it 90 degrees along e.g. Y such that two axes align, and then consider how you’d get the object to rotate along the axis you now longer have access to. The answer is simply, by adjusting multiple axes at once.
To get cube B visually oriented in between A and C, you’ll need to do what Angelo mentioned which is where things get complicated; Quaternions.
You can use Matrices, but you’ll run into oddities. I mocked up an example to illustrate.
from maya import cmds
cmds.file(new=True, force=True)
cmds.loadPlugin("matrixNodes", quiet=True)
cubeA, _ = cmds.polyCube(name="cubeA")
cubeB, _ = cmds.polyCube(name="cubeB")
cubeC, _ = cmds.polyCube(name="cubeC")
cmds.setAttr(cubeA + ".translate", *(0, 0, 0), type="double3")
cmds.setAttr(cubeB + ".translate", *(2, 0, 0), type="double3")
cmds.setAttr(cubeC + ".translate", *(4, 0, 0), type="double3")
cmds.setAttr(cubeC + ".rotate", *[0, 20, 0], type="double3")
average = cmds.createNode("wtAddMatrix")
decompose = cmds.createNode("decomposeMatrix")
cmds.connectAttr(cubeA + ".matrix", average + ".wtMatrix[0].matrixIn")
cmds.connectAttr(cubeC + ".matrix", average + ".wtMatrix[1].matrixIn")
cmds.connectAttr(average + ".matrixSum", decompose + ".inputMatrix")
cmds.connectAttr(decompose + ".outputRotate", cubeB + ".rotate")
cmds.setAttr(average + ".wtMatrix[0].weightIn", 0.5)
cmds.setAttr(average + ".wtMatrix[1].weightIn", 0.5)
Try your hand at rotating this around, and notice how at some point it’ll start to flip and behave oddly. Especially at the values you provided, (100, 200, 300)
.
Finally, to answer the question in your title, matrices can’t give you Euler angles past 180 degrees. I’ll have to let someone who knows more about why explain the why, but I suspect it has something to do with how the angles in a matrix relate to sine and cosine?
You need to use MQuaternion , go take a look at MFnTransform or MFnTransformation ( I don’t know which it is) and see the parts where it mentions MQuaternion , can’t remember it at the top of my head but you can have any angle with your quaternion in radians of course so past 180 deg like you want ( pi ) past 360 degrees ( 2 pi ) …
Sent from Mail for Windows 10
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c5861edd-f7b8-476f-838a-6bfd73251aa7%40googlegroups.com.
If getting it through nodes, there’s decomposeMatrix
which has a quaternion output, along with a eulerToQuat
node. Don’t know whether there’s any way to interpolate quaternions with any of the native nodes however?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5ab1bd25.0eaddf0a.850f5.e18f%40mx.google.com.
quatSlerp
Oooo that sounded too good to be true, so I had a look and found none (in Maya 2015). :O Could you be referring to this one? https://github.com/yantor3d/quatExtras
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c5861edd-f7b8-476f-838a-6bfd73251aa7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5ab1bd25.0eaddf0a.850f5.e18f%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da5dr8M%3DSkOXyER2HjQ99vYh1ed3NuiQTay27dP12y0YjQ%40mail.gmail.com.To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c5861edd-f7b8-476f-838a-6bfd73251aa7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5ab1bd25.0eaddf0a.850f5.e18f%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da5dr8M%3DSkOXyER2HjQ99vYh1ed3NuiQTay27dP12y0YjQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD4bjsQrWOYb8AT1u%3DATdGbniiuOVFYOJCbpPdZpLq9uw%40mail.gmail.com.