IMP logo

algebra examples

geometry

IMP.algebra provides a set of geometric primitives and basic operations on them.

from IMP.algebra import *

# we can create some spheres
s=[]
for i in range(0,10):
    s.append(Sphere3D(get_random_vector_in(IMP.algebra.get_unit_bounding_box_3d()), .1))

# we can compute a sphere which contains them all
enclosing= get_enclosing_sphere(s)

print enclosing.get_contains(s[0])

print IMP.algebra.get_distance(s[0], s[1])
# or between the centers
print get_distance(s[0].get_center(), s[1].get_center())

# create a cylinder
c= Cylinder3D(Segment3D(s[0].get_center(), s[1].get_center()), 1)
print c

# manipulate bounding boxes
bb= BoundingBox3D()
for si in s:
    bb+= get_bounding_box(si)

grid space

This example shows how to use the grid support in IMP.algebra to discretize a set of continuous points. In this case the points are simply randomly drawn from the surface of a sphere, but they could be taken from something more interesting.

import IMP.algebra

# create a unit grid with its origin at 0,0,0
g= IMP.algebra.SparseUnboundedIntGrid3D(1, IMP.algebra.Vector3D(0,0,0))

s= IMP.algebra.Sphere3D(IMP.algebra.Vector3D(1,1,1), 6)
count=0
for i in range(0,100):
    p= IMP.algebra.get_random_vector_on(s)
    ei= g.get_extended_index(p)
    if g.get_has_index(ei):
        print "hit"
    else:
        g.add_voxel(ei, count)
        count=count+1
print "There are", len(g.get_all_indexes()), "distinct values", count


Generated on Thu Mar 24 2011 02:01:40 for IMP by doxygen 1.7.3