Визуализации молекул в Blender
- from math import degrees, acos
- from mathutils import Vector
- spheres = (Vector((2,3,3)),Vector((1,1,2)),Vector((2,3,4)),Vector((4,5,3)))
- edges = ((0,1),(1,2),(2,3))
- for i in range(0, len(spheres)):
- r1 = spheres[i]
- bpy.ops.mesh.primitive_uv_sphere_add(location=(r1.x, r1.y, r1.z))
- for i in range(0,len(edges)):
- r1 = spheres[edges[i][0]]
- r2 = spheres[edges[i][1]]
- r3 = (r1+r2)/2
- z = Vector((0,0,1))
- z_desired = (r1-r2).normalized()
- rot_axis = z.cross(z_desired)
- angle = acos(z.dot(z_desired))
- bpy.ops.mesh.primitive_cylinder_add(radius=0.3, depth=(r2-r1).length,location=(r3.x,r3.y,r3.z))
- bpy.ops.transform.rotate(value=(angle,), axis=rot_axis)
Скрипт построения в блендере парочки молекул