This problem is absolutely driving me crazy for over a week now. All I need is a bezier curve that starts at point with coordinates (x1, y1, z1,) and ends at a point with coordinates (x2, y2, z2).
I attempted to write a function using basic coordinate geometry, and it works pretty well 90% of the times, but fails depending on domain/range of numpy.atan. (It creates a bezier curve between the two points, then scales and rotates it appropriately)
def connect_points(v1, v2):
midpoint = [(1 / 2) * (v1[0] + v2[0]), (1 / 2) * (v1[1] + v2[1]), (1 / 2) *(v1[2] + v2[2])]
distance = math.sqrt((v2[0] - v1[0]) ** 2 + (v2[1] - v1[1]) ** 2 + (v2[2] - v1[2]) ** 2)
z_rotation = math.atan((v2[1] - v1[1]) / ((v2[0] - v1[0]) + 0.00001))
y_rotation = -math.atan((v2[2] - v1[2]) / math.sqrt((v2[1] - v1[1]) ** 2 + (v2[0] - v1[0]) ** 2))
bpy.ops.curve.primitive_bezier_curve_add(location=midpoint, radius=distance / 2, rotation=[0, y_rotation, z_rotation])
bpy.context.object.data.bevel_depth = 0.010
I am not willing to spend another week trying to write different cases for arctan. Is there a simpler way?
v0, v1 = Vector(v0), Vector(v1)as you're changing the type ofv0andv1. Also if you don't want to calculate handle points, you can set the handle types to AUTO. – dr. Sybren Jun 06 '18 at 21:22foreach_seton two points was a little overkill.. Changing the type ofv0, v1to Vector is exactly the intended result... could check to see if they are not vector types then convert them to vectors as they are only going to be used as vectors ... confusing. Importantly wanted to point out to OP to use vectors and not reinvent the wheel with Euclidean distance formulae et al. – batFINGER Jun 07 '18 at 07:52