| 1 | # Get a triangulation of the part of a plane inside a closed surface.
|
|---|
| 2 |
|
|---|
| 3 | plane_normal = (0,0,1)
|
|---|
| 4 | plane_offset = 3.0 # Angstroms
|
|---|
| 5 |
|
|---|
| 6 | # Vertices is N by 3 numpy array of floats giving triangle vertex positions.
|
|---|
| 7 | # Triagles is T by 3 numpy array of integers giving indices
|
|---|
| 8 | # into vertex array for 3 vertices of each triangle.
|
|---|
| 9 | import Icosahedron as icos
|
|---|
| 10 | vertices, triangles = icos.icosahedron_triangulation(radius = 10)
|
|---|
| 11 |
|
|---|
| 12 | # Get vertices and triangles for part of plane inside surface
|
|---|
| 13 | import _surfacecap
|
|---|
| 14 | cv, ct = _surfacecap.compute_cap(plane_normal, -plane_offset, vertices, triangles)
|
|---|
| 15 |
|
|---|
| 16 | # compute_cap() uses the sweep-line method that produces long skinny triangles.
|
|---|
| 17 | # To refine so triangles are not so skinny use refine_mesh()
|
|---|
| 18 | subdivision_factor = 1
|
|---|
| 19 | cv, ct = _surfacecap.refine_mesh(cv, ct, subdivision_factor)
|
|---|
| 20 |
|
|---|
| 21 | print 'Clipped icosahedron, clip plane has', len(ct), 'triangles'
|
|---|