On 15/05/2015 at 04:12, xxxxxxxx wrote:
Hi Chris,
The documentation for GeUserArea.DrawBezier() isn't accurate but your notes are exact :slightly_smiling_face:.
There seem to have an issue passing an array for multiple splines. It only works as expected passing an array for one spline only.
So we can currently only draw one spline at a time (start/ending points + in/out control points/tangents).
To draw an approximation of a circle with bezier splines the best solution is to draw 4 bezier splines and use magic numbers 0.55228475 or 0.551784 to calculate the influence points.
Here's the code to use inside GeUserArea.DrawMsg():
width = x2
height = y2
diameter = height-1
# Create an array for 6 float values (3 points with x+y coordinates each)
points = array.array('f', xrange(6))
# Calculate 4 points for circle bezier spline approximation
p0 = c4d.Vector(diameter/2.0, diameter, 0.0)
p1 = c4d.Vector(diameter, diameter/2.0, 0.0)
p2 = c4d.Vector(diameter/2.0, 0.0, 0.0)
p3 = c4d.Vector(0.0, diameter/2.0, 0.0)
# Draw lower right bezier spline
points[c4d.DRAWBEZIER_BX] = p0.x + (p0.x * 0.551784)
points[c4d.DRAWBEZIER_BY] = p0.y
points[c4d.DRAWBEZIER_CX] = p1.x
points[c4d.DRAWBEZIER_CY] = p1.y + (p1.y * 0.551784)
points[c4d.DRAWBEZIER_DX] = p1.x
points[c4d.DRAWBEZIER_DY] = p1.y
self.DrawBezier(p0.x, p0.y, points, False, False)
# Draw upper right bezier spline
points[c4d.DRAWBEZIER_BX] = p1.x
points[c4d.DRAWBEZIER_BY] = p1.y - (p1.y * 0.551784)
points[c4d.DRAWBEZIER_CX] = p2.x + (p2.x * 0.551784)
points[c4d.DRAWBEZIER_CY] = p2.y
points[c4d.DRAWBEZIER_DX] = p2.x
points[c4d.DRAWBEZIER_DY] = p2.y
self.DrawBezier(p1.x, p1.y, points, False, False)
# Draw upper left bezier spline
points[c4d.DRAWBEZIER_BX] = p2.x - (p2.x * 0.551784)
points[c4d.DRAWBEZIER_BY] = p2.y
points[c4d.DRAWBEZIER_CX] = p3.x
points[c4d.DRAWBEZIER_CY] = p3.y - (p3.y * 0.551784)
points[c4d.DRAWBEZIER_DX] = p3.x
points[c4d.DRAWBEZIER_DY] = p3.y
self.DrawBezier(p2.x, p2.y, points, False, False)
# Draw lower left bezier spline
points[c4d.DRAWBEZIER_BX] = p3.x
points[c4d.DRAWBEZIER_BY] = p3.y + (p3.y * 0.551784)
points[c4d.DRAWBEZIER_CX] = p0.x - (p0.x * 0.551784)
points[c4d.DRAWBEZIER_CY] = p0.y
points[c4d.DRAWBEZIER_DX] = p0.x
points[c4d.DRAWBEZIER_DY] = p0.y
self.DrawBezier(p3.x, p3.y, points, False, False)
See this paper for the surprisingly simple maths behind this code and magic numbers 0.55228475 or 0.551784.