• Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login
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
  • Register
  • Login

Creating a Circle (spline) with varying number of points.

Cinema 4D SDK
python r20
4
5
2.7k
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.
  • P
    pim
    last edited by Nov 1, 2018, 10:45 AM

    If I create a circle, it has always just 4 points.
    How can I create a circle (spline) with for example, 5 or 28 points?

    1 Reply Last reply Reply Quote 0
    • E
      eZioPan
      last edited by eZioPan Nov 2, 2018, 5:21 AM Nov 2, 2018, 5:20 AM

      Hi @pim,
      As far as I know, there is no way to make a "perfect circle" with any type of spline in Cinema 4D.
      I search on the Internet, based on this answer: How to create circle with Bézier curves?.
      I write the following code to create a circular-like spline shape:

      import c4d, math
      #Welcome to the world of Python
      
      deg = math.pi/180.0
      
      def main():
          pCnt = 4             # Here is the point count
          radius = 200         # Here is the radius of circle
          subdAngle = 5*deg    # Here is the subdivision angle
      
          #Prepare the data
          tangentLength = (4/3)*math.tan(math.pi/(2*pCnt))*radius # single side tangent handle length
          pointPosLs = []
          tangentLs = []
          for i in range(0,pCnt):
      
              angle = i*(2*math.pi)/pCnt    # caculate the angle
      
              # caculate point position
              y = math.sin(angle)*radius
              x = math.cos(angle)*radius
              pointPosLs.append(c4d.Vector(x, y, 0))
      
              # tangent position
              lx = math.sin(angle)*tangentLength
              ly = -math.cos(angle)*tangentLength
              rx = -lx
              ry = -ly
              vl = c4d.Vector(lx, ly, 0)
              vr = c4d.Vector(rx, ry, 0)
              tangentLs.append([vl, vr])
      
          # init a bezier circle
          circle = c4d.SplineObject(pcnt=pCnt, type=c4d.SPLINETYPE_BEZIER)
          circle.ResizeObject(pcnt=pCnt, scnt=1)
          circle.SetSegment(id=0, cnt=pCnt, closed=True)
          circle[c4d.SPLINEOBJECT_CLOSED] = True
          circle[c4d.SPLINEOBJECT_ANGLE] = subdAngle
          
          circle.SetAllPoints(pointPosLs) # set point position
      
          # set tangent position
          for i in range(0, pCnt):
              circle.SetTangent(i, tangentLs[i][0], tangentLs[i][1])
      
          circle.Message(c4d.MSG_UPDATE)
      
          return circle
      

      You can try put this code in a Python Generator object to get the result.

      I'm not very sure about my answer, waiting for more convincing answers.

      1 Reply Last reply Reply Quote 2
      • M
        mp5gosu
        last edited by Nov 2, 2018, 9:36 AM

        You may also want to take a look at the official Cinema 4D SDK for an example of a circle object: https://github.com/PluginCafe/cinema4d_cpp_sdk_extended/blob/master/plugins/cinema4dsdk/source/object/circle.cpp

        Though it's C++, the algorithm should be easily adaptable.

        1 Reply Last reply Reply Quote 3
        • S
          s_bach
          last edited by Nov 2, 2018, 9:52 AM

          Hello @pim ,

          I guess you are talking about the "Circle" spline primitive? The generated spline has always 4 control points; there is no way to change that.

          But you could try to get the generated spline and apply the "Subdivide" tool. Whit that tool you can add additional points.

          Or you could, as @eZioPan and @mp5gosu and have shown, create the spline completely by yourself.

          best wishes,
          Sebastian

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 2
          • P
            pim
            last edited by Nov 2, 2018, 1:03 PM

            Thank you all, great answers!
            I will take a different approach.
            I convert the circle to a spline and then divide that spline into the wanted number of points.

            -Pim

            1 Reply Last reply Reply Quote 0
            2 out of 5
            • First post
              Last post