cape.geom: Generic geometry utilities

This module provides several methods for modifying points or performing other geometric manipulations in a way accessible to each of the subclasses.

The main categories are:

  • performing manipulations on sets of points, such as rotations

  • checking for intersections, polygon membership, etc.

cape.geom.DistancePointToCurve(x, X)

Get distance from point to segments of a piecewise linear curve

Call:
>>> D = DistancePointToCurve(x, X)
Inputs:
x: np.ndarray[float]

Test point, shape: (3,)

X: np.ndarray[float]

Array of curve break points, shape: (n,3)

Outputs:
D: np.ndarray[float]

Distance from x to each segment, shape: (n-1,)

Versions:
  • 2016-09-29 @ddalle: Version 1.0

cape.geom.DistancePointToLine(x, x1, x2)

Get distance from a point to a line segment

Call:
>>> d = DistancePointToLine(x, x1, x2)
Inputs:
x: np.ndarray[float]

Test point, shape: (3,)

x1: np.ndarray[float]

Segment start point, shape: (3,)

x2: np.ndarray[float]

Segment end point, shape: (3,)

Outputs:
d: float

Distance from segment to point

Versions:
  • 2016-09-29 @ddalle: Version 1.0

cape.geom.RotatePoints(X, v1, v2, theta)

Rotate a list of points

Call:
>>> Y = RotatePoints(X, v1, v2, theta)
Inputs:
X: numpy.ndarray[float]

Array of node coordinates, shape: (N, 3)

v1: numpy.ndarray[float]

Start point of rotation vector, shape: (3,)

v2: numpy.ndarray[float]

End point of rotation vector, shape: (3,)

theta: float

Rotation angle in degrees

Outputs:
Y: numpy.ndarray`(:class:`float), shape = (N,3)

List of rotated node coordinates

Versions:
  • 2014-10-07 @ddalle: Version 1.0, from TriBase

cape.geom.TranslatePoints(X, dR)

Translate the nodes of a triangulation object.

The offset coordinates may be specified as individual inputs or a single vector of three coordinates.

Call:
>>> TranslatePoints(X, dR)
Inputs:
X: numpy.ndarray[float]

List of node coordinates, shape: (N,3)

dR: numpy.ndarray | list

List of three coordinates to use for translation

Outputs:
Y: numpy.ndarray[float]

List of translated node coordinates, shape: (N,3)

Versions:
  • 2014-10-08 @ddalle: Version 1.0

cape.geom.dist2_lines_to_pt(X1, Y1, X2, Y2, x, y, **kw)

Get square of distance from point(s) to line segment(s)

The test point can either be a single point or a collection of points with dimensions equal to the collection of lines.

Call:
>>> d2 = dist2_lines_to_pt(X1, Y1, X2, Y2, x, y, **kw)
Inputs:
X1: np.ndarray[float]

x-coords of start points of several line segments

Y1: np.ndarray[float]

y-coords of start points of several line segments

X2: np.ndarray[float]

x-coords of end points of several line segments

Y2: np.ndarray[float]

y-coords of end points of several line segments

x: float | np.ndarray

x-coord of test point(s)

y: float | np.ndarray

y-coord of test point(s)

Outputs:
d2: np.ndarray[float]

Minimum distance from each segment to point

Versions:
  • 2022-11-01 @ddalle: Version 1.0

cape.geom.dist2_tris_to_pt(X, Y, x, y, **kw)

Get square of distance from a point to a collection of triangles

Points that are inside the triangle return a distance of 0

Call:
>>> D = dist_tris_to_pt(X, Y, x, y)
Inputs:
X: np.ndarray[float]

x-coords of vertices of n tris, shape: (n,3)

Y: np.ndarray[float], shape=(n,3))

y-coords of vertices of n tris, shape: (n,3)

x: float

x-coordinate of test point

y: float

y-coordinate of test point

Outputs:
D: np.ndarray[float]

Matrix of minimum distance squared from each tri to point

Versions:
  • 2017-02-06 @ddalle: Version 1.0

  • 2022-11-01 @ddalle: Version 2.0; faster

cape.geom.dist_lines_to_pt(X1, Y1, X2, Y2, x, y, **kw)

Get distance from a point to a collection of line segments

The test point can either be a single point or a collection of points with dimensions equal to the collection of lines.

Call:
>>> D = dist_lines_to_pt(X1, Y1, X2, Y2, x, y, **kw)
Inputs:
X1: np.ndarray[float]

x-coords of start points of several line segments

Y1: np.ndarray[float]

y-coords of start points of several line segments

X2: np.ndarray[float]

x-coords of end points of several line segments

Y2: np.ndarray[float]

y-coords of end points of several line segments

x: float | np.ndarray

x-coord of test point(s)

y: float | np.ndarray

y-coord of test point(s)

Outputs:
D: np.ndarray[float]

Minimum distance from each segment to point

Versions:
  • 2017-02-06 @ddalle: Version 1.0

cape.geom.dist_tris_to_pt(X, Y, x, y, **kw)

Get distance from a point to a collection of triangles

Points that are inside the triangle return a distance of 0.

Call:
>>> D = dist_tris_to_pt(X, Y, x, y)
Inputs:
X: np.ndarray[float]

x-coords of vertices of n tris, shape: (n,3)

Y: np.ndarray[float], shape=(n,3))

y-coords of vertices of n tris, shape: (n,3)

x: float

x-coordinate of test point

y: float

y-coordinate of test point

Outputs:
D: np.ndarray[float]

Matrix of minimum distance from each tri to point

Versions:
  • 2017-02-06 @ddalle: Version 1.0

  • 2022-11-01 @ddalle: Version 2.0; faster

cape.geom.edges_int_line(X1, Y1, X2, Y2, x1, y1, x2, y2, **kw)

Check if a set of edges intersects another line segment

Intersections between the test segment and the start point of any edge are not counted as an intersection. The test point can either be a single point or a collection of points with dimensions equal to the collection of lines.

Call:
>>> Q = edges_int_line(X1, Y1, X2, Y2, x1, y1, x2, y2, **kw)
Inputs:
X1: np.ndarray[float]

x-coords of start points of several line segments

Y1: np.ndarray[float]

y-coords of start points of several line segments

X2: np.ndarray[float]

x-coords of end points of several line segments

Y2: np.ndarray[float]

y-coords of end points of several line segments

x1: float | np.ndarray

Start point x-coordinate of test segment

y1: float | np.ndarray

Start point y-coordinate of test segment

x2: float | np.ndarray

End point x-coordinate of test segment

y2: float | np.ndarray

End point y-coordinate of test segment

Outputs:
Q: np.ndarray (bool, shape=*X1.shape*)

Matrix of whether or not each segment intersects test segment

Versions:
  • 2017-02-06 @ddalle: Version 1.0

cape.geom.lines_int_line(X1, Y1, X2, Y2, x1, y1, x2, y2, **kw)

Check if a set of line segments intersects another line segment

Call:
>>> Q = lines_int_line(X1, Y1, X2, Y2, x1, y1, x2, y2, **kw)
Inputs:
X1: np.ndarray[float]

x-coords of start points of several line segments

Y1: np.ndarray[float]

y-coords of start points of several line segments

X2: np.ndarray[float]

x-coords of end points of several line segments

Y2: np.ndarray[float]

y-coords of end points of several line segments

x1: float | np.ndarray

Start point x-coordinate of test segment

y1: float | np.ndarray

Start point y-coordinate of test segment

x2: float | np.ndarray

End point x-coordinate of test segment

y2: float | np.ndarray

End point y-coordinate of test segment

Outputs:
Q: np.ndarray[bool]

Whether or not each segment intersects test segment

Versions:
  • 2017-02-06 @ddalle: Version 1.0

cape.geom.tris_have_pt(X, Y, x, y, **kw)

Check if each triangle in a list contains a specified point(s)

Call:
>>> Q = tris_have_pt(X, Y, x, y, **kw)
Inputs:
X: np.ndarray[float]

x-coords of vertices of n tris, shape: (n,3)

Y: np.ndarray[float]

y-coords of vertices of n tris, shape: (n,3)

x: float | np.ndarray

x-coord of test point(s), shape: (n,)

y: float | np.ndarray

y-coord of test point(s), shape: (n,)

Outputs:
Q: np.ndarray[bool]

Whether or not each tri contains the test point

Versions:
  • 2017-02-06 @ddalle: Version 1.0

  • 2022-11-02 @ddalle: Version 2.0; use tri areas