Did I find the right examples for you? yes no      Crawl my project      Python Jobs

# external.quickhull.qhull3d

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)
```Return the triangles making up the convex hull of C{vertices}.
Considers distances less than C{precision} to be zero (useful to simplify
the hull of a complex mesh, at the expense of exactness of the hull).

:param vertices: The vertices to find the hull of.
:param precision: Distance used to decide whether points lie outside of
the hull or not. Larger numbers mean fewer triangles, but some vertices
may then end up outside the hull, at a distance of no more than
C{precision}.
:param verbose: Print information about what the algorithm is doing. Only(more...)
```

```        def qhull3d(vertices, precision = 0.0001, verbose = False):
"""Return the triangles making up the convex hull of C{vertices}.
Considers distances less than C{precision} to be zero (useful to simplify
the hull of a complex mesh, at the expense of exactness of the hull).

:param vertices: The vertices to find the hull of.
:param precision: Distance used to decide whether points lie outside of
the hull or not. Larger numbers mean fewer triangles, but some vertices
may then end up outside the hull, at a distance of no more than
C{precision}.
:param verbose: Print information about what the algorithm is doing. Only
useful for debugging.
:return: A list cointaining the extreme points of C{vertices}, and
a list of triangle indices containing the triangles that connect
all extreme points.
"""
# find a simplex to start from
hull_vertices = basesimplex3d(vertices, precision)

# handle degenerate cases
if len(hull_vertices) == 3:
# coplanar
hull_vertices = qhull2d(vertices, vecNormal(*hull_vertices))
return hull_vertices, [ (0, i+1, i+2)
for i in xrange(len(hull_vertices) - 2) ]
elif len(hull_vertices) <= 2:
# colinear or singular
# no triangles for these cases
return hull_vertices, []

# construct list of triangles of this simplex
hull_triangles = set([ operator.itemgetter(i,j,k)(hull_vertices)
for i, j, k in ((1,0,2), (0,1,3), (0,3,2), (3,1,2)) ])

if verbose:
print("starting set", hull_vertices)

# construct list of outer vertices for each triangle
outer_vertices = {}
for triangle in hull_triangles:
outer = \
[ (dist, vert)
for dist, vert
in izip( ( vecDistanceTriangle(triangle, vert)
for vert in vertices ),
vertices )
if dist > precision ]
if outer:
outer_vertices[triangle] = outer

# as long as there are triangles with outer vertices
while outer_vertices:
# grab a triangle and its outer vertices
tmp_iter = outer_vertices.iteritems()
triangle, outer = tmp_iter.next() # tmp_iter trick to make 2to3 work
# calculate pivot point
pivot = max(outer)
if verbose:
print("pivot", pivot)
# add it to the list of extreme vertices
hull_vertices.append(pivot)
# and update the list of triangles:
# 1. calculate visibility of triangles to pivot point
visibility = [ vecDistanceTriangle(othertriangle, pivot) > precision
for othertriangle in outer_vertices.iterkeys() ]
# 2. get list of visible triangles
visible_triangles = [ othertriangle
for othertriangle, visible
in izip(outer_vertices.iterkeys(), visibility)
if visible ]
# 3. find all edges of visible triangles
visible_edges = []
for visible_triangle in visible_triangles:
visible_edges += [operator.itemgetter(i,j)(visible_triangle)
for i, j in ((0,1),(1,2),(2,0))]
if verbose:
print("visible edges", visible_edges)
# 4. construct horizon: edges that are not shared with another triangle
horizon_edges = [ edge for edge in visible_edges
if not tuple(reversed(edge)) in visible_edges ]
# 5. remove visible triangles from list
# this puts a hole inside the triangle list
visible_outer = set()
for outer_verts in outer_vertices.itervalues():
visible_outer |= set(map(operator.itemgetter(1), outer_verts))
for triangle in visible_triangles:
if verbose:
print("removing", triangle)
hull_triangles.remove(triangle)
del outer_vertices[triangle]
# 6. close triangle list by adding cone from horizon to pivot
# also update the outer triangle list as we go
for edge in horizon_edges:
newtriangle = edge + ( pivot, )
newouter = \
[ (dist, vert)
for dist, vert in izip( ( vecDistanceTriangle(newtriangle,
vert)
for vert in visible_outer ),
visible_outer )
if dist > precision ]
if newouter:
outer_vertices[newtriangle] = newouter
if verbose:

# no triangle has outer vertices anymore
# so the convex hull is complete!
# remap the triangles to indices that point into hull_vertices
return hull_vertices, [ tuple(hull_vertices.index(vert)
for vert in triangle)
for triangle in hull_triangles ]
```

```from external.transformations import translation_matrix, rotation_matrix
import external.transformations as tf
from external.quickhull import qhull3d
import logging
import pdb
```
```    def __init__(self, points):
super(Convex, self).__init__()
self.points = points
verts, triangles = qhull3d(points)
self.faces = range(len(triangles))
```