20. geomtools
— Basic geometrical operations.¶
This module defines some basic operations on simple geometrical entities such as points, lines, planes, vectors, segments, triangles, circles.
The operations include intersection, projection, distance computing.
Many of the functions in this module are exported as methods on the Coords and Geometry classes and subclasses.
Renamed functions:
intersectionPointsLWL > intersectLineWithLine
intersectionTimesLWL > intersectLineWithLine
intersectionPointsLWP > intersectLineWithPlane
intersectionTimesLWP > intersectLineWithPlane
Planned renaming of functions:
areaNormals
degenerate
levelVolumes
smallestDirection
distance > distance
closest
closestPair
projectedArea
polygonNormals
averageNormals
triangleInCircle
triangleCircumCircle
triangleBoundingCircle
triangleObtuse
lineIntersection > to be removed (or intersect2DLineWithLine)
displaceLines
segmentOrientation
rotationAngle
anyPerpendicularVector
perpendicularVector
projectionVOV > projectVectorOnVector
projectionVOP > projectVectorOnPlane
pointsAtLines > pointOnLine
pointsAtSegments > pointOnSegment
intersectionTimesSWP > remove or intersectLineWithLineTimes2
intersectionSWP > intersectSegmentWithPlaneTimes
intersectionPointsSWP > intersectSegmentWithPlane
intersectionTimesLWT > intersectLineWithTriangleTimes
intersectionPointsLWT > intersectLineWithTriangle
intersectionTimesSWT > intersectSegmentWithTriangleTimes
intersectionPointsSWT > intersectSegmentWithTriangle
intersectionPointsPWP > intersectThreePlanes
intersectionLinesPWP > intersectTwoPlanes (or intersectPlaneWithPlane)
intersectionSphereSphere > intersectTwoSpheres (or intersectSphereWithSphere)
faceDistance >
edgeDistance >
vertexDistance >
baryCoords
insideSimplex
insideTriangle
20.1. Functions defined in module geomtools¶

geomtools.
pointsAtLines
(q, m, t)[source]¶ Return the points of lines (q,m) at parameter values t.
Parameters:
 q,`m`: (…,3) shaped arrays of points and vectors, defining a single line or a set of lines. The vectors do not need to have unit length.
 t: array of parameter values, broadcast compatible with q and m. Parametric value 0 is at point q, parametric value 1 ia at q+m.
Returns a Coords array with the points at parameter values t.

geomtools.
pointsAtSegments
(S, t)[source]¶ Return the points of line segments S at parameter values t.
Parameters:
 S: (…,2,3) shaped array, defining a single line segment or a set of line segments.
 t: array of parameter values, broadcast compatible with S.
Returns an array with the points at parameter values t.

geomtools.
intersectLineWithLine
(q1, m1, q2, m2, mode='all', times=False)[source]¶ Find the common perpendicular of lines (q1,m1) and lines (q2,m2)
Return the intersection points of lines (q1,m1) and lines (q2,m2) with the perpendiculars between them. For intersecting lines, the corresponding points will coincide.
Parameters:
 qi,`mi` (i=1,2): (nqi,3) shaped arrays of points and vectors defining nqi lines.
 mode: ‘all’ or ‘pair:
 if ‘all’, the interesection of all lines q1,m1 with all lines q2,m2 is computed; nq1 and nq2 can be different.
 if ‘pair’: nq1 and nq2 should be equal (or 1) and the intersection of pairs of lines are computed (using broadcasting for length 1 data).
 times: bool: if True, returns the parameter values of the intersection points instead of the intersection points themselves.
Returns two Coords arrays with the intersection points on lines (q1,m1) and (q2,m2) respectively (or, if times is True, two float arrays with the parameter values of these points). The size of the Coords arrays is (nq1,nq2,3) for mode ‘all’ and (nq1,3) for mode ‘pair’. With times True, the size of the returned parameter arrays is (nq1,nq2,3) for mode ‘all’ and size (nq1,3) for mode ‘pair’.
Note: taking the intersection of two parallel lines will result in nan values. These are not removed from the result. The user can do it if he so wishes.
Example:
>>> q,m = [[0,0,0],[0,0,1],[0,0,3]], [[1,0,0],[1,1,0],[0,1,0]] >>> p,n = [[2.,0.,0.],[0.,0.,0.]], [[0.,1.,0.],[0.,0.,1.]]
>>> x1,x2 = intersectLineWithLine(q,m,p,n) >>> print(x1) [[[ 2. 0. 0.] [ 0. 0. 0.]] <BLANKLINE> [[ 2. 2. 1.] [ 0. 0. 1.]] <BLANKLINE> [[ nan nan nan] [ 0. 0. 3.]]] >>> print(x2) [[[ 2. 0. 0.] [ 0. 0. 0.]] <BLANKLINE> [[ 2. 2. 0.] [ 0. 0. 1.]] <BLANKLINE> [[ nan nan nan] [ 0. 0. 3.]]]
>>> x1,x2 = intersectLineWithLine(q[:2],m[:2],p,n,mode='pair') >>> print(x1) [[ 2. 0. 0.] [ 0. 0. 1.]] >>> print(x2) [[ 2. 0. 0.] [ 0. 0. 1.]]
>>> t1,t2 = intersectLineWithLine(q,m,p,n,times=True) >>> print(t1) [[ 2. 0.] [ 2. 0.] [ nan 0.]] >>> print(t2) [[ 0. 0.] [ 2. 1.] [ nan 3.]]
>>> t1,t2 = intersectLineWithLine(q[:2],m[:2],p,n,mode='pair',times=True) >>> print(t1) [ 2. 0.] >>> print(t2) [0. 1.]

geomtools.
intersectLineWithPlane
(q, m, p, n, mode='all', times=False)[source]¶ Find the intersection of lines (q,m) and planes (p,n)
Return the intersection points of lines (q,m) and planes (p,n).
Parameters:
 q,`m`: (nq,3) shaped arrays of points and vectors (mode=all) or broadcast compatible arrays (mode=pair), defining a single line or a set of lines.
 p,`n`: (np,3) shaped arrays of points and normals (mode=all) or broadcast compatible arrays (mode=pair), defining a single plane or a set of planes.
 mode: all to calculate the intersection of each line (q,m) with all planes (p,n) or pair for pairwise intersections.
Returns a (nq,np) shaped (mode=all) array of parameter values t, such that the intersection points are given by q+t*m.
Notice that the result will contain an INF value for lines that are parallel to the plane.
Example:
>>> q,m = [[0,0,0],[0,1,0],[0,0,3]], [[1,0,0],[0,1,0],[0,0,1]] >>> p,n = [[1.,1.,1.],[1.,1.,1.]], [[1.,1.,0.],[1.,1.,1.]]
>>> t = intersectLineWithPlane(q,m,p,n,times=True) >>> print(t) [[ 2. 3.] [ 1. 2.] [ inf 0.]] >>> x = intersectLineWithPlane(q,m,p,n) >>> print(x) [[[ 2. 0. 0.] [ 3. 0. 0.]] <BLANKLINE> [[ 0. 2. 0.] [ 0. 3. 0.]] <BLANKLINE> [[ nan nan inf] [ 0. 0. 3.]]] >>> x = intersectLineWithPlane(q[:2],m[:2],p,n,mode='pair') >>> print(x) [[ 2. 0. 0.] [ 0. 3. 0.]]

geomtools.
intersectionTimesSWP
(S, p, n, mode='all')[source]¶ Return the intersection of line segments S with planes (p,n).
This is like intersectionTimesLWP, but the lines are defined by two points instead of by a point and a vector. Parameters:
 S: (nS,2,3) shaped array (mode=all) or broadcast compatible array (mode=pair), defining one or more line segments.
 p,`n`: (np,3) shaped arrays of points and normals (mode=all) or broadcast compatible arrays (mode=pair), defining a single plane or a set of planes.
 mode: all to calculate the intersection of each line segment S with all planes (p,n) or pair for pairwise intersections.
Returns a (nS,np) shaped (mode=all) array of parameter values t, such that the intersection points are given by (1t)*S[…,0,:] + t*S[…,1,:].

geomtools.
intersectionSWP
(S, p, n, mode='all', return_all=False, atol=0.0)[source]¶ Return the intersection points of line segments S with planes (p,n).
Parameters:
 S: (nS,2,3) shaped array, defining a single line segment or a set of line segments.
 p,`n`: (np,3) shaped arrays of points and normals, defining a single plane or a set of planes.
 mode: all to calculate the intersection of each line segment S with all planes (p,n) or pair for pairwise intersections.
 return_all: if True, all intersection points of the lines along the segments are returned. Default is to return only the points that lie on the segments.
 atol: float tolerance of the points inside the line segments.
Return values if return_all==True:
 t: (nS,NP) parametric values of the intersection points along the line segments.
 x: the intersection points themselves (nS,nP,3).
Return values if return_all==False:
 t: (n,) parametric values of the intersection points along the line segments (n <= nS*nP)
 x: the intersection points themselves (n,3).
 wl: (n,) line indices corresponding with the returned intersections.
 wp: (n,) plane indices corresponding with the returned intersections

geomtools.
intersectionPointsSWP
(S, p, n, mode='all', return_all=False, atol=0.0)[source]¶ Return the intersection points of line segments S with planes (p,n) within tolerance atol.
This is like
intersectionSWP()
but does not return the parameter values. It is equivalent to:intersectionSWP(S,p,n,mode,return_all)[1:]

geomtools.
intersectionTimesLWT
(q, m, F, mode='all')[source]¶ Return the intersection of lines (q,m) with triangles F.
Parameters:
 q,`m`: (nq,3) shaped arrays of points and vectors (mode=all) or broadcast compatible arrays (mode=pair), defining a single line or a set of lines.
 F: (nF,3,3) shaped array (mode=all) or broadcast compatible array (mode=pair), defining a single triangle or a set of triangles.
 mode: all to calculate the intersection of each line (q,m) with all triangles F or pair for pairwise intersections.
 Returns a (nq,nF) shaped (mode=all) array of parameter values t,
 such that the intersection points are given q+tm.

geomtools.
intersectionPointsLWT
(q, m, F, mode='all', return_all=False)[source]¶ Return the intersection points of lines (q,m) with triangles F.
Parameters:
 q,`m`: (nq,3) shaped arrays of points and vectors, defining a single line or a set of lines.
 F: (nF,3,3) shaped array, defining a single triangle or a set of triangles.
 mode: all to calculate the intersection points of each line (q,m) with all triangles F or pair for pairwise intersections.
 return_all: if True, all intersection points are returned. Default is to return only the points that lie inside the triangles.
Returns: If return_all==True, a (nq,nF,3) shaped (mode=all) array of intersection points, else, a tuple of intersection points with shape (n,3) and line and plane indices with shape (n), where n <= nq*nF.

geomtools.
intersectionTimesSWT
(S, F, mode='all')[source]¶ Return the intersection of lines segments S with triangles F.
Parameters:
 S: (nS,2,3) shaped array (mode=all) or broadcast compatible array (mode=pair), defining a single line segment or a set of line segments.
 F: (nF,3,3) shaped array (mode=all) or broadcast compatible array (mode=pair), defining a single triangle or a set of triangles.
 mode: all to calculate the intersection of each line segment S with all triangles F or pair for pairwise intersections.
Returns a (nS,nF) shaped (mode=all) array of parameter values t, such that the intersection points are given by (1t)*S[…,0,:] + t*S[…,1,:].

geomtools.
intersectionPointsSWT
(S, F, mode='all', return_all=False)[source]¶ Return the intersection points of lines segments S with triangles F.
Parameters:
 S: (nS,2,3) shaped array, defining a single line segment or a set of line segments.
 F: (nF,3,3) shaped array, defining a single triangle or a set of triangles.
 mode: all to calculate the intersection points of each line segment S with all triangles F or pair for pairwise intersections.
 return_all: if True, all intersection points are returned. Default is to return only the points that lie on the segments and inside the triangles.
Returns: If return_all==True, a (nS,nF,3) shaped (mode=all) array of intersection points, else, a tuple of intersection points with shape (n,3) and line and plane indices with shape (n), where n <= nS*nF.

geomtools.
intersectionPointsPWP
(p1, n1, p2, n2, p3, n3, mode='all')[source]¶ Return the intersection points of planes (p1,n1), (p2,n2) and (p3,n3).
Parameters:
 pi,`ni` (i=1…3): (npi,3) shaped arrays of points and normals (mode=all) or broadcast compatible arrays (mode=pair), defining a single plane or a set of planes.
 mode: all to calculate the intersection of each plane (p1,n1) with all planes (p2,n2) and (p3,n3) or pair for pairwise intersections.
Returns a (np1,np2,np3,3) shaped (mode=all) array of intersection points.

geomtools.
intersectionLinesPWP
(p1, n1, p2, n2, mode='all')[source]¶ Return the intersection lines of planes (p1,n1) and (p2,n2).
Parameters:
 pi,`ni` (i=1…2): (npi,3) shaped arrays of points and normals (mode=all) or broadcast compatible arrays (mode=pair), defining a single plane or a set of planes.
 mode: all to calculate the intersection of each plane (p1,n1) with all planes (p2,n2) or pair for pairwise intersections.
Returns a tuple of (np1,np2,3) shaped (mode=all) arrays of intersection points q and vectors m, such that the intersection lines are given by
q+t*m
.

geomtools.
intersectionSphereSphere
(R, r, d)[source]¶ Intersection of two spheres (or two circles in the x,y plane).
Computes the intersection of two spheres with radii R, resp. r, having their centres at distance d <= R+r. The intersection is a circle with its center on the segment connecting the two sphere centers at a distance x from the first sphere, and having a radius y. The return value is a tuple x,y.

geomtools.
projectPointOnPlane
(X, p, n, mode='all')[source]¶ Return the projection of points X on planes (p,n).
Parameters:
 X: a (nx,3) shaped array of points.
 p, n: (np,3) shaped arrays of points and normals defining np planes.
 mode: ‘all’ or ‘pair:
 if ‘all’, the projection of all points on all planes is computed; nx and np can be different.
 if ‘pair’: nx and np should be equal (or 1) and the projection of pairs of point and plane are computed (using broadcasting for length 1 data).
Returns a float array of size (nx,np,3) for mode ‘all’, or size (nx,3) for mode ‘pair’.
Example:
>>> X = Coords([[0.,1.,0.],[3.,0.,0.],[4.,3.,0.]]) >>> p,n = [[2.,0.,0.],[0.,1.,0.]], [[1.,0.,0.],[0.,1.,0.]] >>> print(projectPointOnPlane(X,p,n)) [[[ 2. 1. 0.] [ 0. 1. 0.]] <BLANKLINE> [[ 2. 0. 0.] [ 3. 1. 0.]] <BLANKLINE> [[ 2. 3. 0.] [ 4. 1. 0.]]] >>> print(projectPointOnPlane(X[:2],p,n,mode='pair')) [[ 2. 1. 0.] [ 3. 1. 0.]]

geomtools.
projectPointOnPlaneTimes
(X, p, n, mode='all')[source]¶ Return the projection of points X on planes (p,n).
This is like
projectPointOnPlane()
but instead of returning the projected points, returns the parametric values t along the lines (X,n), such that the projection points can be computed from X+t*n.Parameters: see
projectPointOnPlane()
.Returns a float array of size (nx,np) for mode ‘all’, or size (nx,) for mode ‘pair’.
Example:
>>> X = Coords([[0.,1.,0.],[3.,0.,0.],[4.,3.,0.]]) >>> p,n = [[2.,0.,0.],[0.,1.,0.]], [[1.,0.,0.],[0.,1.,0.]] >>> print(projectPointOnPlaneTimes(X,p,n)) [[ 2. 0.] [1. 1.] [2. 2.]] >>> print(projectPointOnPlaneTimes(X[:2],p,n,mode='pair')) [ 2. 1.]

geomtools.
projectPointOnLine
(X, p, n, mode='all')[source]¶ Return the projection of points X on lines (p,n).
Parameters:
 X: a (nx,3) shaped array of points.
 p, n: (np,3) shaped arrays of points and vectors defining np lines.
 mode: ‘all’ or ‘pair:
 if ‘all’, the projection of all points on all lines is computed; nx and np can be different.
 if ‘pair’: nx and np should be equal (or 1) and the projection of pairs of point and line are computed (using broadcasting for length 1 data).
Returns a float array of size (nx,np,3) for mode ‘all’, or size (nx,3) for mode ‘pair’.
Example:
>>> X = Coords([[0.,1.,0.],[3.,0.,0.],[4.,3.,0.]]) >>> p,n = [[2.,0.,0.],[0.,1.,0.]], [[0.,2.,0.],[1.,0.,0.]] >>> print(projectPointOnLine(X,p,n)) [[[ 2. 1. 0.] [ 0. 1. 0.]] <BLANKLINE> [[ 2. 0. 0.] [ 3. 1. 0.]] <BLANKLINE> [[ 2. 3. 0.] [ 4. 1. 0.]]] >>> print(projectPointOnLine(X[:2],p,n,mode='pair')) [[ 2. 1. 0.] [ 3. 1. 0.]]

geomtools.
projectPointOnLineTimes
(X, p, n, mode='all')[source]¶ Return the projection of points X on lines (p,n).
This is like
projectPointOnLine()
but instead of returning the projected points, returns the parametric values t along the lines (X,n), such that the projection points can be computed from p+t*n.Parameters: see
projectPointOnLine()
.Returns a float array of size (nx,np) for mode ‘all’, or size (nx,) for mode ‘pair’.
Example:
>>> X = Coords([[0.,1.,0.],[3.,0.,0.],[4.,3.,0.]]) >>> p,n = [[2.,0.,0.],[0.,1.,0.]], [[0.,1.,0.],[1.,0.,0.]] >>> print(projectPointOnLineTimes(X,p,n)) [[ 1. 0.] [ 0. 3.] [ 3. 4.]] >>> print(projectPointOnLineTimes(X[:2],p,n,mode='pair')) [ 1. 3.]

geomtools.
distanceFromLine
(X, lines, mode='all')[source]¶ Return the distance of points X from lines (p,n).
Parameters:
 X: a (nx,3) shaped array of points.
 lines: one of the following definitions of the line(s):
 a tuple (p,n), where both p and n are (np,3) shaped arrays of respectively points and vectors defining np lines;
 an (np,2,3) shaped array containing two points of each line.
 mode: ‘all’ or ‘pair:
 if ‘all’, the distance of all points to all lines is computed; nx and np can be different.
 if ‘pair’: nx and np should be equal (or 1) and the distance of pairs of point and line are computed (using broadcasting for length 1 data).
Returns a float array of size (nx,np) for mode ‘all’, or size (nx) for mode ‘pair’.
Example:
>>> X = Coords([[0.,1.,0.],[3.,0.,0.],[4.,3.,0.]]) >>> L = Line([[2.,0.,0.],[0.,1.,0.]], [[0.,3.,0.],[1.,0.,0.]]) >>> print(distanceFromLine(X,L)) [[ 2. 0.] [ 1. 1.] [ 2. 2.]] >>> print(distanceFromLine(X[:2],L,mode='pair')) [ 2. 1.] >>> L = Line([[[2.,0.,0.],[2.,2.,0.]], [[0.,1.,0.],[1.,1.,0.]]]) >>> print(distanceFromLine(X,L)) [[ 2. 0.] [ 1. 1.] [ 2. 2.]] >>> print(distanceFromLine(X[:2],L,mode='pair')) [ 2. 1.]

geomtools.
pointNearLine
(X, p, n, atol, nproc=1)[source]¶ Find the points from X that are near to lines (p,n).
Finds the points from X that are closer than atol to any of the lines (p,n).
Parameters:
 X: a (nx,3) shaped array of points.
 p, n: (np,3) shaped arrays of points and vectors defining np lines.
 atol: float or (nx,) shaped float array of pointwise tolerances
Returns a list of arrays with sorted point indices for each of the lines.
Example:
>>> X = Coords([[0.,1.,0.],[3.,0.,0.],[4.,3.,0.]]) >>> p,n = [[2.,0.,0.],[0.,1.,0.]], [[0.,3.,0.],[1.,0.,0.]] >>> print(pointNearLine(X,p,n,1.5)) [array([1]), array([0, 1])] >>> print(pointNearLine(X,p,n,1.5,2)) [array([1]), array([0, 1])]

geomtools.
faceDistance
(X, Fp, return_points=False)[source]¶ Compute the closest perpendicular distance to a set of triangles.
X is a (nX,3) shaped array of points. Fp is a (nF,3,3) shaped array of triangles.
Note that some points may not have a normal with footpoint inside any of the facets.
The return value is a tuple OKpid,OKdist,OKpoints where:
 OKpid is an array with the point numbers having a normal distance;
 OKdist is an array with the shortest distances for these points;
 OKpoints is an array with the closest footpoints for these points and is only returned if return_points = True.

geomtools.
edgeDistance
(X, Ep, return_points=False)[source]¶ Compute the closest perpendicular distance of points X to a set of edges.
X is a (nX,3) shaped array of points. Ep is a (nE,2,3) shaped array of edge vertices.
Note that some points may not have a normal with footpoint inside any of the edges.
The return value is a tuple OKpid,OKdist,OKpoints where:
 OKpid is an array with the point numbers having a normal distance;
 OKdist is an array with the shortest distances for these points;
 OKpoints is an array with the closest footpoints for these points and is only returned if return_points = True.

geomtools.
vertexDistance
(X, Vp, return_points=False)[source]¶ Compute the closest distance of points X to a set of vertices.
X is a (nX,3) shaped array of points. Vp is a (nV,3) shaped array of vertices.
The return value is a tuple OKdist,OKpoints where:
 OKdist is an array with the shortest distances for the points;
 OKpoints is an array with the closest vertices for the points and is only returned if return_points = True.

geomtools.
areaNormals
(x)[source]¶ Compute the area and normal vectors of a collection of triangles.
x is an (ntri,3,3) array with the coordinates of the vertices of ntri triangles.
Returns a tuple (areas,normals) with the areas and the normals of the triangles. The area is always positive. The normal vectors are normalized.

geomtools.
degenerate
(area, normals)[source]¶ Return a list of the degenerate faces according to area and normals.
area,normals are equal sized arrays with the areas and normals of a list of faces, such as the output of the
areaNormals()
function.A face is degenerate if its area is less or equal to zero or the normal has a nan (notanumber) value.
Returns a list of the degenerate element numbers as a sorted array.

geomtools.
hexVolume
(x)[source]¶ Compute the volume of hexahedrons.
Parameters:
 x: float array (nelems,8,3)
Returns a float array (nelems) withe the approximate volume of the hexahedrons formed by each 8tuple of vertices. The volume is obained by dividing the hexahedron in 24 tetrahedrons and using the formulas from http://www.osti.gov/scitech/servlets/purl/632793
Example:
>>> from pyformex.elements import Hex8 >>> X = Coords(Hex8.vertices).reshape(1,8,3) >>> print(hexVolume(X)) [ 1.]

geomtools.
levelVolumes
(x)[source]¶ Compute the level volumes of a collection of elements.
x is an (nelems,nplex,3) array with the coordinates of the nplex vertices of nelems elements, with nplex equal to 2, 3 or 4.
If nplex == 2, returns the lengths of the straight line segments. If nplex == 3, returns the areas of the triangle elements. If nplex == 4, returns the signed volumes of the tetraeder elements. Positive values result if vertex 3 is at the positive side of the plane defined by the vertices (0,1,2). Negative volumes are reported for tetraeders having reversed vertex order.
For any other value of nplex, raises an error. If succesful, returns an (nelems,) shaped float array.

geomtools.
inertialDirections
(x)[source]¶ Return the directions and dimension of a Coords based of inertia.
 x: a Coordslike array
Returns a tuple of the principal direction vectors and the sizes along these directions, ordered from the smallest to the largest direction.

geomtools.
smallestDirection
(x, method='inertia', return_size=False)[source]¶ Return the direction of the smallest dimension of a Coords
 x: a Coordslike array
 method: one of ‘inertia’ or ‘random’
 return_size: if True and method is ‘inertia’, a tuple of a direction vector and the size along that direction and the cross directions; else, only return the direction vector.

geomtools.
largestDirection
(x, return_size=False)[source]¶ Return the direction of the largest dimension of a Coords.
 x: a Coordslike array
 return_size: if True and method is ‘inertia’, a tuple of a direction vector and the size along that direction and the cross directions; else, only return the direction vector.

geomtools.
distance
(X, Y)[source]¶ Returns the distance of all points of X to those of Y.
Parameters:
 X: (nX,3) shaped array of points.
 Y: (nY,3) shaped array of points.
Returns an (nX,nT) shaped array with the distances between all points of X and Y.

geomtools.
closest
(X, Y=None, return_dist=False)[source]¶ Find the point of Y closest to each of the points of X.
Parameters:
 X: (nX,3) shaped array of points
 Y: (nY,3) shaped array of points. If None, Y is taken equal to X, allowing to search for the closest point in a single set. In the latter case, the point itself is excluded from the search (as otherwise that would obviously be the closest one).
 return_dist: bool. If True, also returns the distances of the closest points.
Returns:
 ind: (nX,) int array with the index of the closest point in Y to the points of X
 dist: (nX,) float array with the distance of the closest point. This is equal to length(XY[ind]). It is only returned if return_dist is True.

geomtools.
closestPair
(X, Y)[source]¶ Find the closest pair of points from X and Y.
Parameters:
 X: (nX,3) shaped array of points
 Y: (nY,3) shaped array of points
Returns a tuple (i,j,d) where i,j are the indices in X,Y identifying the closest points, and d is the distance between them.

geomtools.
projectedArea
(x, dir)[source]¶ Compute projected area inside a polygon.
Parameters:
 x: (npoints,3) Coords with the ordered vertices of a (possibly nonplanar) polygonal contour.
 dir: either a global axis number (0, 1 or 2) or a direction vector consisting of 3 floats, specifying the projection direction.
Returns a single float value with the area inside the polygon projected in the specified direction.
Note that if the polygon is planar and the specified direction is that of the normal on its plane, the returned area is that of the planar figure inside the polygon. If the polygon is nonplanar however, the area inside the polygon is not defined. The projected area in a specified direction is, since the projected polygon is a planar one.

geomtools.
polygonNormals
(x)[source]¶ Compute normals in all points of polygons in x.
x is an (nel,nplex,3) coordinate array representing nel (possibly nonplanar) polygons.
The return value is an (nel,nplex,3) array with the unit normals on the two edges ending in each point.

geomtools.
averageNormals
(coords, elems, atNodes=False, treshold=None)[source]¶ Compute average normals at all points of elems.
coords is a (ncoords,3) array of nodal coordinates. elems is an (nel,nplex) array of element connectivity.
The default return value is an (nel,nplex,3) array with the averaged unit normals in all points of all elements. If atNodes == True, a more compact array with the unique averages at the nodes is returned.

geomtools.
triangleInCircle
(x)[source]¶ Compute the incircles of the triangles x
The incircle of a triangle is the largest circle that can be inscribed in the triangle.
x is a Coords array with shape (ntri,3,3) representing ntri triangles.
Returns a tuple r,C,n with the radii, Center and unit normals of the incircles.
Example:
>>> X = Formex(Coords([1.,0.,0.])).rosette(3,120.) >>> print(X) {[1.0,0.0,0.0], [0.5,0.866025,0.0], [0.5,0.866025,0.0]} >>> radius, center, normal = triangleInCircle(X.coords.reshape(1,3,3)) >>> print(radius) [ 0.5] >>> print(center) [[ 0. 0. 0.]]

geomtools.
triangleCircumCircle
(x, bounding=False)[source]¶ Compute the circumcircles of the triangles x
x is a Coords array with shape (ntri,3,3) representing ntri triangles.
Returns a tuple r,C,n with the radii, Center and unit normals of the circles going through the vertices of each triangle.
If bounding=True, this returns the triangle bounding circle.

geomtools.
triangleBoundingCircle
(x)[source]¶ Compute the bounding circles of the triangles x
The bounding circle is the smallest circle in the plane of the triangle such that all vertices of the triangle are on or inside the circle. If the triangle is acute, this is equivalent to the triangle’s circumcircle. It the triangle is obtuse, the longest edge is the diameter of the bounding circle.
x is a Coords array with shape (ntri,3,3) representing ntri triangles.
Returns a tuple r,C,n with the radii, Center and unit normals of the bounding circles.

geomtools.
triangleObtuse
(x)[source]¶ Checks for obtuse triangles
x is a Coords array with shape (ntri,3,3) representing ntri triangles.
Returns an (ntri) array of True/False values indicating whether the triangles are obtuse.

geomtools.
lineIntersection
(P0, N0, P1, N1)[source]¶ Finds the intersection of 2 (sets of) lines.
This relies on the lines being pairwise coplanar.

geomtools.
displaceLines
(A, N, C, d)[source]¶ Move all lines (A,N) over a distance a in the direction of point C.
A,N are arrays with points and directions defining the lines. C is a point. d is a scalar or a list of scalars. All line elements of F are translated in the plane (line,C) over a distance d in the direction of the point C. Returns a new set of lines (A,N).

geomtools.
segmentOrientation
(vertices, vertices2=None, point=None)[source]¶ Determine the orientation of a set of line segments.
vertices and vertices2 are matching sets of points. point is a single point. All arguments are Coords objects.
Line segments run between corresponding points of vertices and vertices2. If vertices2 is None, it is obtained by rolling the vertices one position foreward, thus corresponding to a closed polygon through the vertices). If point is None, it is taken as the center of vertices.
The orientation algorithm checks whether the line segments turn positively around the point.
Returns an array with +1/1 for positive/negative oriented segments.

geomtools.
rotationAngle
(A, B, m=None, angle_spec=0.017453292519943295)[source]¶ Return rotation angles and vectors for rotations of A to B.
A and B are (n,3) shaped arrays where each line represents a vector. This function computes the rotation from each vector of A to the corresponding vector of B. If m is None, the return value is a tuple of an (n,) shaped array with rotation angles (by default in degrees) and an (n,3) shaped array with unit vectors along the rotation axis. If m is a (n,3) shaped array with vectors along the rotation axis, the return value is a (n,) shaped array with rotation angles. The returned angle is then the angle between the planes formed by the axis and the vectors. Specify angle_spec=RAD to get the angles in radians.

geomtools.
anyPerpendicularVector
(A)[source]¶ Return arbitrary vectors perpendicular to vectors of A.
A is a (n,3) shaped array of vectors. The return value is a (n,3) shaped array of perpendicular vectors.
The returned vector is always a vector in the x,y plane. If the original is the zaxis, the result is the xaxis.

geomtools.
baryCoords
(S, P)[source]¶ Compute the barycentric coordinates of points P wrt. simplexes S.
S is a (nel,nplex,3) shaped array of nsimplexes (n=nplex1):  1simplex: line segment  2simplex: triangle  3simplex: tetrahedron P is a (npts,3), (npts,nel,3) or (npts,1,3) shaped array of points.
The return value is a (nplex,npts,nel) shaped array of barycentric coordinates.

geomtools.
insideSimplex
(BC, bound=True)[source]¶ Check if points are in simplexes.
BC is an array of barycentric coordinates (along the first axis), which sum up to one. If bound = True, a point lying on the boundary is considered to be inside the simplex.

geomtools.
insideTriangle
(x, P, method='bary')[source]¶ Checks whether the points P are inside triangles x.
x is a Coords array with shape (ntri,3,3) representing ntri triangles. P is a Coords array with shape (npts,ntri,3) representing npts points in each of the ntri planes of the triangles. This function checks whether the points of P fall inside the corresponding triangles.
Returns an array with (npts,ntri) bool values.