Basic geometrical operations.
This module defines some basic operations on simple geometrical entities such as lines, triangles, circles, planes.
Functions defined in the module geomtools
- geomtools.triangleInCircle(x)¶
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.
- geomtools.triangleCircumCircle(x, bounding=False)¶
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)¶
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)¶
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(P1, D1, P2, D2)¶
Finds the intersection of 2 coplanar lines.
The lines (P1,D1) and (P2,D2) are defined by a point and a direction vector. Let a and b be unit vectors along the lines, and c = P2-P1, let ld and d be the length and the unit vector of the cross product a*b, the intersection point X is then given by X = 0.5(P1+P2+sa*a+sb*b) where sa = det([c,b,d])/ld and sb = det([c,a,d])/ld
- geomtools.displaceLines(A, N, C, d)¶
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)¶
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, angle_spec=Deg)¶
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. 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. Specify angle_spec=Rad to get the angles in radians.
- geomtools.anyPerpendicularVector(A)¶
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.
- geomtools.projectionVOV(A, B)¶
- Return the projection of vector of A on vector of B.
- geomtools.projectionVOP(A, n)¶
- Return the projection of vector of A on plane of B.
- geomtools.intersectionPointsLWL(q1, m1, q2, m2)¶
Return the intersection points of lines (q1,m1) and lines (q2,m2)
with the perpendiculars between them.
This is equivalent to intersectionTimesLWL(q1,m1,q2,m2) but returns a tuple of (nq1,nq2,3) shaped arrays of intersection points instead of the parameter values.
- geomtools.intersectionTimesLWL(q1, m1, q2, m2)¶
Return the intersection of lines (q1,m1) and lines (q2,m2)
with the perpendiculars between them.
q1/m1 is a (nq1,3) shaped array of points/vectors. q2/m2 is a (nq2,3) shaped array of points/vectors.
The return value is a tuple of (nq1,nq2) shaped arrays of parameter values t1 and t2, such that the intersection points are given by q1+t1*m1 and q2+t2*m2.
- geomtools.intersectionPointsLWP(q, m, p, n)¶
Return the intersection points of lines (q,m) with planes (p,n).
This is equivalent to intersectionTimesLWP(q,m,p,n) but returns a (nq,np,3) shaped array of intersection points instead of the parameter values.
- geomtools.intersectionTimesLWP(q, m, p, n)¶
Return the intersection of lines (q,m) with planes (p,n).
q/m is a (nq,3) shaped array of points/vectors. p/n is a (np,3) shaped array of points/normals.
The return value is a (nq,np) shaped array of parameter values t, such that the intersection points are given by q+t*m.
- geomtools.intersectionPointsPWP(p1, n1, p2, n2, p3, n3)¶
Return the intersection points of planes (p1,n1), (p2,n2) and (p3,n3).
p1/n1 is a (np1,3) shaped array of points/normals. p2/n2 is a (np2,3) shaped array of points/normals. p3/n3 is a (np3,3) shaped array of points/normals.
The return value is a (np1,np2,np3,3) shaped array of intersection points.
- geomtools.intersectionLinesPWP(p1, n1, p2, n2)¶
Return the intersection lines of planes (p1,n1) and (p2,n2).
p1/n1 is a (np1,3) shaped array of points/normals. p2/n2 is a (np2,3) shaped array of points/normals.
The return value is a tuple of (np1,np2,3) shaped arrays of intersection points q and vectors m, such that the intersection lines are given by q+t*m.
- geomtools.intersectionPointsPOP(q, p, n)¶
Return the intersection points of perpendiculars from points q on planes (p,n).
This is equivalent to intersectionTimesPWP(q,p,n) but returns a (nq,np,3) shaped array of intersection points instead of the parameter values.
- geomtools.intersectionTimesPOP(q, p, n)¶
Return the intersection of perpendiculars from points q on planes (p,n).
q is (nq,3) shaped array of points. p/n is a (np,3) shaped array of points/normals.
The return value is a (nq,np) shaped array of parameter values t, such that the intersection points are given by q+t*n.
- geomtools.intersectionPointsPOL(p, q, m)¶
Return the intersection points of perpendiculars from points p on lines (q,m).
This is equivalent to intersectionTimesPWL(p,q,m) but returns a (np,nq,3) shaped array of intersection points instead of the parameter values.
- geomtools.intersectionTimesPOL(p, q, m)¶
Return the intersection of perpendiculars from points p on lines (q,m).
p is (np,3) shaped array of points. q/m is a (nq,3) shaped array of points/vectors.
The return value is a (np,nq) shaped array of parameter values t, such that the intersection points are given by q+t*m.
- geomtools.facetDistance(X, Fp, return_points=False)¶
Compute the closest perpendicular distance of points X to a set of facets.
X is a (nX,3) shaped array of points. Fp is a (nF,nplex,3) shaped array of facet vertices.
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)¶
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)¶
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.baryCoords(S, P)¶
Return the barycentric coordinates of points P wrt. simplexes S.
- S is a (nel,nplex,3) shaped array of n-simplexes (n=nplex-1) e.g.:
- 1-simplex: line segment
- 2-simplex: triangle
- 3-simplex: tetrahedron
P is a (npts,nel,3) shaped array of points.
The return value is a (npts,nel,nplex) shaped array of barycentric coordinates BC, such that the points P are given by (BC[:,:,:,newaxis]*S).sum(-2).
- geomtools.insideSimplex(BC, bound=True)¶
Check if points are in simplexes.
BC is an array of barycentric coordinates, which sum up to one. If bound = True, a point lying on the boundary is considered to be inside the simplex.