Points in local and global coordinates [SOLVED]
-
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.
-
On 25/11/2014 at 01:29, xxxxxxxx wrote:
Hello,
as the documentation says "Mag" should be a matrix. In your code you try to handle a vector:
backLocalPoint = globalPoint-1*worldSpaceCoords
Also, "Mag-1" does not mean "minus one". It stands for the inverse matrix. You can create the inverse matrix using Python's "invert" operator:
inverseMatrix = ~worldSpaceCoords backLocalPoint = globalPoint * inverseMatrix
You find some examples of complex matrix use in the
SpherifyModifier example
[URL-REMOVED].best wishes,
Sebastian
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 25/11/2014 at 16:23, xxxxxxxx wrote:
I thought the documentation sounded weird with the -1 in there.
I was looking for the syntax for the invert operator. Everything is working now, which is fantastic thanks to you!