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

    Centers in Python (Object / Polygon etc)

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 537 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 04/06/2014 at 07:06, xxxxxxxx wrote:

      Hello,

      Can anybody point me in the right direction regarding getting the centre points of objects and polygons in python.

      Cinema4d has this built in (i.e. axis center, /points center) but i can't find it in the sdk or online.
      I'm sure this must be fairly standard when manipulating geometry in Python and was wondering if anyone can provide any help on this topic

      I just wrote a little script (for the polygon one) that selects a polygon index, and returns the four vector points in the list, and now I'm stuck, (mentally I could draw lines between the opposite vectors and where they intersect would( should) be the centre point of this polygon...

      I've also been looking into centroid maths....

      Any help would be much appreciated!

      Thank you,

      Simon

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

        On 04/06/2014 at 08:08, xxxxxxxx wrote:

        Update: Again if anyone has more information i'd appreciate it!

        ....but so far adding the vectors together then averaging them appears to be working, (I'm separating the averages into X, Y, Z and dividing by the number of points (4) on the polygon.

        I'm going to try this approach for an object and try averaging all points (i.e. 8 on a cube) then will try irregular geometry...

        Thanks for any help/advice!

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

          On 05/06/2014 at 08:19, xxxxxxxx wrote:

          Yeah, averaging's how you do it, and you don't have to separate the xyz values, since dividing (or multiplying) a vector by a float/integer does that operation on all three.

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

            On 05/06/2014 at 08:56, xxxxxxxx wrote:

            The average point position is a different to the bounding-box center.

            >>> values = [1, 2, 3, 42, 89, 1045]  
            \>>> sum(values) / float(len(values))   # Average  
            197.0  
            \>>> (min(values) + max(values)) / 2.0  # Center  
            523.0
            

            Use BaseObject.GetMp() and BaseObject.GetRad().

            -Niklas

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

              On 05/06/2014 at 16:16, xxxxxxxx wrote:

              Oohh, right.  Thanks, Niklas.

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

                On 06/06/2014 at 05:09, xxxxxxxx wrote:

                Brilliant! Thank you very much, really appreciated!

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