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?
Solved Creating a Circle (spline) with varying number of points.
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.
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.
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