Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
v_norm = v / l
cyl_height = l - head_length
z_rot = np.arccos(v_norm.dot(np.array([0.0, 1.0, 0.0])))
y_rot = np.arctan2(v[2], v[0])
cyl_center = start_vec + cyl_height/2 * v_norm
head_center = start_vec + (cyl_height + head_length/2) * v_norm
cyl_geom = pjs.CylinderGeometry(radiusTop=width, radiusBottom=width, height=cyl_height)
cyl_mesh.geometry = cyl_geom
cyl_mesh.material = pjs.MeshLambertMaterial(color=color)
cyl_mesh.position = cyl_center.tolist()
cyl_mesh.setRotationFromMatrix([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
cyl_mesh.rotateY(-y_rot)
cyl_mesh.rotateZ(-z_rot)
head_geom = pjs.CylinderGeometry(radiusTop=0.0, radiusBottom=head_width, height=head_length)
head_mesh.geometry = head_geom
head_mesh.material = pjs.MeshLambertMaterial(color=color)
head_mesh.position = head_center.tolist()
head_mesh.setRotationFromMatrix([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
head_mesh.rotateY(-y_rot)
head_mesh.rotateZ(-z_rot)
def make_arrow(cyl_mesh, head_mesh, start_vec, end_vec, width, head_width, head_length, color):
start_vec = np.array(start_vec)
end_vec = np.array(end_vec)
v = end_vec - start_vec
l = np.sqrt(v.dot(v))
v_norm = v / l
cyl_height = l - head_length
z_rot = np.arccos(v_norm.dot(np.array([0.0, 1.0, 0.0])))
y_rot = np.arctan2(v[2], v[0])
cyl_center = start_vec + cyl_height/2 * v_norm
head_center = start_vec + (cyl_height + head_length/2) * v_norm
cyl_geom = pjs.CylinderGeometry(radiusTop=width, radiusBottom=width, height=cyl_height)
cyl_mesh.geometry = cyl_geom
cyl_mesh.material = pjs.MeshLambertMaterial(color=color)
cyl_mesh.position = cyl_center.tolist()
cyl_mesh.setRotationFromMatrix([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
cyl_mesh.rotateY(-y_rot)
cyl_mesh.rotateZ(-z_rot)
head_geom = pjs.CylinderGeometry(radiusTop=0.0, radiusBottom=head_width, height=head_length)
head_mesh.geometry = head_geom
head_mesh.material = pjs.MeshLambertMaterial(color=color)
head_mesh.position = head_center.tolist()
head_mesh.setRotationFromMatrix([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
head_mesh.rotateY(-y_rot)
head_mesh.rotateZ(-z_rot)