def calc_helix_points(turtle, rad, pitch):
""" calculates required points to produce helix bezier curve with given radius and pitch in direction of turtle"""
# alpha = radians(90)
# pit = pitch/(2*pi)
# a_x = rad*cos(alpha)
# a_y = rad*sin(alpha)
# a = pit*alpha*(rad - a_x)*(3*rad - a_x)/(a_y*(4*rad - a_x)*tan(alpha))
# b_0 = Vector([a_x, -a_y, -alpha*pit])
# b_1 = Vector([(4*rad - a_x)/3, -(rad - a_x)*(3*rad - a_x)/(3*a_y), -a])
# b_2 = Vector([(4*rad - a_x)/3, (rad - a_x)*(3*rad - a_x)/(3*a_y), a])
# b_3 = Vector([a_x, a_y, alpha*pit])
# axis = Vector([0, 0, 1])
# simplifies greatly for case inc_angle = 90
points = [Vector([0, -rad, -pitch / 4]),
Vector([(4 * rad) / 3, -rad, 0]),
Vector([(4 * rad) / 3, rad, 0]),
Vector([0, rad, pitch / 4])]
# align helix points to turtle direction and randomize rotation around axis
trf = turtle.dir.to_track_quat('Z', 'Y')
spin_ang = rand_in_range(0, 2 * pi)
for p in points:
p.rotate(Quaternion(Vector([0, 0, 1]), spin_ang))
p.rotate(trf)
return points[1] - points[0], points[2] - points[0], points[3] - points[0], turtle.dir.copy()
评论列表
文章目录