Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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
    • Recent
    • Tags
    • Users
    • Login

    Mean Rotation, object filps 180

    Scheduled Pinned Locked Moved PYTHON Development
    1 Posts 0 Posters 118 Views
    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 Offline
      Helper
      last edited by

      On 16/07/2014 at 23:48, xxxxxxxx wrote:

      Could some one please help me with why the object keeps flipping around to -180 when finding the mean rotation between two objects and how I could prevent it?

      import c4d
      from c4d import utils
        
      def SetGlobalRotation(obj, rot) :
          m = obj.GetMg()
          pos = m.off
          scale = c4d.Vector( m.v1.GetLength(),
                              m.v2.GetLength(),
                              m.v3.GetLength())
        
          m = utils.HPBToMatrix(rot)
        
          m.off = pos
          m.v1 = m.v1.GetNormalized() * scale.x
          m.v2 = m.v2.GetNormalized() * scale.y
          m.v3 = m.v3.GetNormalized() * scale.z
        
          obj.SetMg(m)
        
      def main() :
          a = op[c4d.ID_USERDATA,1]
          b = op[c4d.ID_USERDATA,2]
          c = op[c4d.ID_USERDATA,3]
          
          aRot = utils.MatrixToHPB(a.GetMg())
          bRot = utils.MatrixToHPB(b.GetMg())
          cRot = utils.MatrixToHPB(c.GetMg())
          
          x = [aRot,bRot]
          mean_rot = sum(x)/2
          SetGlobalRotation(c, mean_rot)
      

      https://dl.dropboxusercontent.com/u/2802779/mean_rotation.c4d

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