Hi everyone!
I have recently been learning some basics of linear algebra.
In order to verify my learning results, I created a Bezier spline Generator with Python Generator.
But when I set the tangents of the spline, something confused me.
When I moved the point of the spline, the left and right handles of the tangent would switch positions, or would they flip 180 degrees? I don't quite understand what's going on here.
And there is my test code and Scene file:
import c4d
import math
def main() -> c4d.BaseObject:
null = c4d.BaseObject(c4d.Onull)
a = op.GetDown()
b = a.GetNext()
c = b.GetNext()
obj = b.GetClone(0)
obj[c4d.NULLOBJECT_RADIUS] = 5
obj[c4d.ID_BASEOBJECT_USECOLOR] = 2
obj[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(1,0,0)
obj2 = obj.GetClone(0)
obj2[c4d.ID_BASEOBJECT_COLOR] = c4d.Vector(0,1,0)
a_pos_local = ~b.GetMg() * a.GetMg().off
a_polar_angle = math.atan2(a_pos_local.y, a_pos_local.x)
a_length = a_pos_local.GetLength()
b_pos_local = ~b.GetMg() * c.GetMg().off
b_polar_angle = math.atan2(b_pos_local.y, b_pos_local.x)
b_length = b_pos_local.GetLength()
polar = (a_polar_angle + b_polar_angle)/2 + (math.pi / 2)
leng = (a_length + b_length)/2
x = leng * math.cos(polar)
y = leng * math.sin(polar)
vec = c4d.Vector(x,y)
move_vec1 = vec.GetNormalized() * op[c4d.ID_USERDATA,1]
m1 = ~op.GetMg() * b.GetMg() * c4d.utils.MatrixMove(move_vec1)
m2 = ~op.GetMg() * b.GetMg() * c4d.utils.MatrixMove(-move_vec1)
obj.SetMg(m1)
obj2.SetMg(m2)
obj.InsertUnder(null)
obj2.InsertUnder(null)
spline = c4d.SplineObject(3, c4d.SPLINETYPE_BEZIER)
spline.SetPoint(0, a.GetMg().off)
spline.SetPoint(1, b.GetMg().off)
spline.SetPoint(2, c.GetMg().off)
vl = ~b.GetMg() * obj.GetMg().off
vr = ~b.GetMg() * obj2.GetMg().off
spline.SetTangent(1, vl, vr)
spline.InsertUnder(null)
return null
tangent.c4d