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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Object position to spline offset with python

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 239 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 09/06/2012 at 03:27, xxxxxxxx wrote:

      Trying to understand vectors, matrix, etc. I am trying to (re)place  an object on a spline using the spline offset.

      So, on frame x, the Sphere is placed on the spline using spline offset.
      On frame x+1, I want to position the sphere a bit further (randomly) on the spline, thus increase the spline offset a bit and replace the sphere.
      Now the question is, how to get the spline offset using the sphere position?

      Below the code I use at this moment to calculate the spline offset given the sphere position and the 'origin' position of the spline (offset = 0).

      For a straight spline it is ok, but when I change (round) the spline a bit, something goes wrong.
      After the next point, the position goes 'wild'.
      It seems that  need to take the rotation into account, but how?

      Another strange thing is, that when I do not use random, but just a standard offset (frame / 100.0) everything is ok?

      ---- Piece of code, see link for the complete file ---
      scene file: www.nfvc.nl/test - place object on spline.zip

      #get offset on spline based on object position
      pos0 = sh.GetPosition(0)                 # get 'origin' position spline offset=0
      objmtx = current_object.GetMg()     # Get the object's global matrix
      diff = objmtx.off                                # get object position

      dist = (diff-pos0).GetLength()          # get difference between spline origin and object

      currentoffset = sh.GetOffsetFromUnit(dist) # get offset on spline

      Note: I can solve the issue by storing the spline offset at frame x and use it in frame x+1, but I really want to understand.

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 12/06/2012 at 05:12, xxxxxxxx wrote:

        Just do as you have already stated in your 'note'. That is the way to handle it. The way you want to achieve it is absolutely unnecessary and impractical. It's also not very trivial. I'm not sure if there actually is a way to precisely calculate it, rather than going the iterative way.

        -Nik

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