coords.Coords.project_on_surface#

Coords.project_on_surface(S, dir=0, missing='e', return_indices=False)#

Project a Coords on a triangulated surface.

The points of the Coords are projected in the specified direction dir onto the surface S. If a point has multiple projecions in the direction, the one nearest to the original is returned.

Parameters#

S: Mesh with eltype=’tri3’

A triangulated surface mesh

dir: int (0,1,2) or float array_like (3,)

The direction of the projection, either a global axis direction or specified as a vector with three components.

missing: ‘o’, ‘r’ or ‘e’

Specifies how to treat cases where the projective line does not intersect the surface:

  • ‘o’: return the original point,

  • ‘r’: remove the point from the result. Use return_indices = True to find out which original points correspond with the projections.

  • ‘e’: raise a ProjectionMissing exception (default).

return_indices: bool, optional

If True, also returns the indices of the points that have a projection on the surface.

Returns#

x: Coords

A Coords with the projections of the input points on the surface. With missing=’o’, this will have the same shape as the input, but some points might not actually lie on the surface. With missing=’r’, the shape will be (n_points,3) and the number of points may be less than the input.

ind: int array, optional

Only returned if return_indices is True: an index in the input Coords of the points that have a projection on the surface. With missing=’r’, this gives the indices of the orginal points corresponding with the projections. With missing=’o’, this can be used to check which points are located on the surface. The index is sequential, no matter what the shape of the input Coords is.

Examples#

>>> from hellotriangle import shapes
>>> S = shapes.sphere().scale(2).translate([0.0, 0.0, 0.2])
>>> x = Coords([[0.0, 0.0],[1.0, 0.0],[1.0, 1.0],[0.0, 1.0]])
>>> print(x)
[[0. 0. 0.]
 [1. 0. 0.]
 [1. 1. 0.]
 [0. 1. 0.]]
>>> xp = x.project_on_surface(S,dir=[0.0, 0.0, 1.0])
>>> print(xp)
[[ 0.      0.     -1.8   ]
 [ 1.      0.     -1.5321]
 [ 1.      1.     -1.198 ]
 [ 0.      1.     -1.5321]]
>>> y = x.scale(5.0)
>>> print(y)
[[0. 0. 0.]
 [5. 0. 0.]
 [5. 5. 0.]
 [0. 5. 0.]]
>>> yp = y.project_on_surface(S,dir=[0.0, 0.0, 1.0],missing='o')
>>> print(yp)
[[ 0.   0.  -1.8]
 [ 5.   0.   0. ]
 [ 5.   5.   0. ]
 [ 0.   5.   0. ]]