/
geometry.py
34 lines (26 loc) · 931 Bytes
/
geometry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## \example algebra/geometry.py
# IMP.algebra provides a set of geometric primitives and basic operations
# on them.
from __future__ import print_function
import IMP.algebra
import sys
IMP.setup_from_argv(sys.argv, "geometry")
# we can create some spheres
s = []
for i in range(0, 10):
s.append(IMP.algebra.Sphere3D(IMP.algebra.get_random_vector_in(
IMP.algebra.get_unit_bounding_box_3d()), .1))
# we can compute a sphere which contains them all
enclosing = IMP.algebra.get_enclosing_sphere(s)
print(enclosing.get_contains(s[0]))
print(IMP.algebra.get_distance(s[0], s[1]))
# or between the centers
print(IMP.algebra.get_distance(s[0].get_center(), s[1].get_center()))
# create a cylinder
c = IMP.algebra.Cylinder3D(
IMP.algebra.Segment3D(s[0].get_center(), s[1].get_center()), 1)
print(c)
# manipulate bounding boxes
bb = IMP.algebra.BoundingBox3D()
for si in s:
bb += IMP.algebra.get_bounding_box(si)