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?