def apply_tropism(turtle, tropism_vector):
"""Apply tropism_vector to turtle direction"""
h_cross_t = turtle.dir.cross(tropism_vector)
# calc angle to rotate by (from ABoP) multiply to achieve accurate results from WP attractionUp param
alpha = 10 * h_cross_t.magnitude
h_cross_t.normalize()
# rotate by angle about axis perpendicular to turtle direction and tropism vector
turtle.dir.rotate(Quaternion(h_cross_t, radians(alpha)))
turtle.dir.normalize()
turtle.right.rotate(Quaternion(h_cross_t, radians(alpha)))
turtle.right.normalize()
评论列表
文章目录