On 24/11/2014 at 17:09, xxxxxxxx wrote:
I am confused as to how some of this works. I've read the documentation, tried to implement it, and I just can't seem to get it to work. I read up on how to do the math on matrices, however, I am a bit lost.
I've looked into numPy but I currently don't have it.. and I would rather not use something that would have to be installed on every machine just to use this particular code.
Here's the rundown.
In the documentation it says:
What if you have a position in global coordinates and want to move an object to that position? Then you need a transformation back from global coordinates to the object's local position coordinates. Mathematically this is done by multiplication by the global matrix' inverse. If Mg is a matrix in global space and Mag is object a's global matrix, then Mag-1*Mg equals the first matrix' in a's local coordinates.
It also says that you don't need to do the math because there are the functions:
SetMl (ml) and SetMg (mg)
Those only work for the baseObject.. and not a point.
I've tried to plug in the Mag-1*Mg into some test code, just so I can see if the numbers come out correctly. However, I don't understand how to use that correctly. From my understanding of the documentation and the provided code, Mag is globalPoint and Mg would be worldSpaceCoords.
doc = c4d.documents.GetActiveDocument () op = doc.GetActiveObject () worldSpaceCoords = op.GetMg() allPoints = op.GetAllPoints() for i,a in enumerate (allPoints) : localPoint = op.GetPoint (i) print 'local', localPoint globalPoint = localPoint * worldSpaceCoords print 'global', globalPoint backLocalPoint = globalPoint-1*worldSpaceCoords print 'back to local', backLocalPoint print '--'
Currently I'm running into the following error:
TypeError: unsupported operand type(s) for -: 'c4d.Vector' and 'c4d.Matrix'
I'm lost in the math as to how to get back to the local coordinates.