Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Points in local and global coordinates [SOLVED]

    PYTHON Development
    0
    3
    622
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post