Scripts: capcalc.py

File capcalc.py, 867 bytes (added by goddard, 10 years ago)
Line 
1# Get a triangulation of the part of a plane inside a closed surface.
2
3plane_normal = (0,0,1)
4plane_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.
9import Icosahedron as icos
10vertices, triangles = icos.icosahedron_triangulation(radius = 10)
11
12# Get vertices and triangles for part of plane inside surface
13import _surfacecap
14cv, 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()
18subdivision_factor = 1
19cv, ct = _surfacecap.refine_mesh(cv, ct, subdivision_factor)
20
21print 'Clipped icosahedron, clip plane has', len(ct), 'triangles'