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

    calculating polygon from points

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 764 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 22/08/2017 at 12:14, xxxxxxxx wrote:

      Hello PluginCafe,

      I have written a small script, which creates supershapes (based on a sphere).
      So far so good, I can calculate all the points of my object but I don't know why,
      but when it comes to calculating the polygons I just don't get it right.
      I know this is not that sdk related or anything, but it's my first time building an object
      and it would help me for future reference aswell.

      import c4d
      import math
      from c4d import gui
      #Welcome to the world of Python
        
      #constants
      a = 1
      b = 1
      m = 0
      n1 = 1
      n2 = 1
      n3 = 1
        
      def supershapeRAD(theta, m, n1, n2, n3) :
          """Calculates the radius of the supershape from a given theta (lon/lat) and some defined constants"""
          t1 = math.fabs((1/a)*math.cos(m*theta/4))
          t1 = math.pow(t1, n2)
          t2 = math.fabs((1/b)*math.sin(m*theta/4))
          t2 = math.pow(t2, n3)
          t3 = t1+t2
          r = math.pow(t3, -1/n1)
          return r
        
      def main() :
             
          total = 20 # number of points
          rad = 200 #base radius of the sphere
        
          obj = c4d.PolygonObject(total*total, total*total) #create a new polygon object
          
          counter = 0 #counter for polygons
          for i in xrange(total-1) :
              lat = c4d.utils.RangeMap(i, 0, total, -math.pi/2, math.pi/2, False) #map latitude to -pi/2  pi/2
              r2 = supershapeRAD(lat, m, n1, n2, n3) #calculate first supershape radius
              for j in xrange(total) :
                  lon = c4d.utils.RangeMap(j, 0, total, -math.pi, math.pi, False)  #map londitude to -pi  pi
                  r1 = supershapeRAD(lon, m, n1, n2, n3) #calculate second supershape radius
                  
                  #calculate position (x,y,z) of the points
                  x = rad *r1* math.cos(lon) * r2*math.cos(lat)
                  y = rad *r1* math.sin(lon) * r2*math.cos(lat)
                  z = rad *r2* math.sin(lat)
                  
                  obj.SetPoint(j+i*total, c4d.Vector(x,y,z)) #set the point
                     
                  #This is the part that gives me trouble
                  #obj.SetPolygon(counter, c4d.CPolygon(a,b,c))
                  
                  counter += 1
                  
                  
          obj.Message(c4d.MSG_UPDATE)
          doc.InsertObject(obj)
          c4d.EventAdd()
         
      if __name__=='__main__':
          main()
      

      This is my current code, it is able to calculate the necessary points.
      I have already looked into the PyRoundedTube example, but that doesn't really help me.

      I hope somebody can help me, because I feel really stupid right now

      greetings,
      Florian

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

        On 23/08/2017 at 07:48, xxxxxxxx wrote:

        Hi Florian,

        I'm not sure about the actual question.
        Basically the CPolygon contains the indexes of points in a left handed order. So you wouldn't call SetPolygon() for every point, but only for a group of points belonging to the polygon (probably just an indentation issue in your code snippet).
        I leave the question which points belong to a polygon in your algorithm to the community.

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

          On 23/08/2017 at 08:53, xxxxxxxx wrote:

          Can sound stupid but does the R19 reconstruction feature will be able to input point cloud (list of vectors) and then output a mesh(list of CPolygon)? Since reconstruction feature, seem to take a video as input, I'm pretty sure c4d build a point cloud from this and then perform the reconstruction. It will be awesome and allow a bunch of new things for 3d scanning inside c4d !

          Btw I know you are not allowed to talk explicitly about new features and things like that, then take it as a suggestion 😉

          Anyway regarding op problem I guess this script for blender can help you !
          http://wiki.theprovingground.org/blender-py-supershape

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

            On 23/08/2017 at 09:05, xxxxxxxx wrote:

            Hey Adnreas,

            my problem wasn't the CPolygon object, but how to correctly calculate the points for the polygon.

            cheers,
            Florian

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

              On 23/08/2017 at 09:21, xxxxxxxx wrote:

              Hey gr4ph0s,

              thanks for the link, I managed to calculate the polygons correctly, thank you very much!

              greetings,
              Florian

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