scallop dome pyformex logo

Previous topic

32. trisurface — Operations on triangulated surfaces.

Next topic

34. nurbs — Using NURBS in pyFormex.

[FSF Associate Member]

Valid XHTML 1.0 Transitional

33. geomtools — Basic geometrical operations.

This module defines some basic operations on simple geometrical entities such as lines, triangles, circles, planes.

Classes defined in module geomtools

Functions defined in module geomtools

geomtools.areaNormals(x)

Compute the area and normal vectors of a collection of triangles.

x is an (ntri,3,3) array of coordinates.

Returns a tuple of areas,normals. The normal vectors are normalized. The area is always positive.

geomtools.polygonArea(x, project=None)

Compute area inside a polygon.

Parameters:

  • x: (nplex,3) Coords array representing the vertices of a (possibly nonplanar) polygon.
  • project: (3,) Coords array representing a unit direction vector.

Returns: a single float value with the area inside the polygon. If a direction vector is given, the area projected in that direction is returned.

Note that if the polygon is nonplanar and no direction is given, the area inside the polygon is not well defined.

geomtools.polygonNormals(x)

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.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, m=None, angle_spec=0.017453292519943295)

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. 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.

The returned vector is always a vector in the x,y plane. If the original is the z-axis, the result is the x-axis.

geomtools.perpendicularVector(A, B)

Return vectors perpendicular on both A and B.

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.pointsAtLines(q, m, t)

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.
  • t: array of parameter values, broadcast compatible with q and m.

Returns: An array with the points at parameter values t.

geomtools.pointsAtSegments(S, t)

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.intersectionTimesLWL(q1, m1, q2, m2, mode='all')

Return the intersection of lines (q1,m1) and lines (q2,m2)

with the perpendiculars between them.

Parameters:

  • qi,`mi` (i=1...2): (nqi,3) shaped arrays of points and vectors (mode=all) or broadcast compatible arrays (mode=pair), defining a single line or a set of lines.
  • mode: all to calculate the intersection of each line (q1,m1) with all lines (q2,m2) or pair for pairwise intersections.

Returns: A tuple of (nq1,nq2) shaped (mode=all) arrays of parameter values t1 and t2, such that the intersection points are given by q1+t1*m1 and q2+t2*m2.

geomtools.intersectionPointsLWL(q1, m1, q2, m2, mode='all')

Return the intersection points of lines (q1,m1) and lines (q2,m2)

with the perpendiculars between them.

This is like intersectionTimesLWL but returns a tuple of (nq1,nq2,3) shaped (mode=all) arrays of intersection points instead of the parameter values.

geomtools.intersectionTimesLWP(q, m, p, n, mode='all')

Return the intersection of lines (q,m) with 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.

geomtools.intersectionPointsLWP(q, m, p, n, mode='all')

Return the intersection points of lines (q,m) with planes (p,n).

This is like intersectionTimesLWP but returns a (nq,np,3) shaped (mode=all) array of intersection points instead of the parameter values.

geomtools.intersectionTimesSWP(S, p, n, mode='all')

Return the intersection of line segments S with planes (p,n).

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.
  • 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 (1-t)*S[...,0,:] + t*S[...,1,:].

This function is comparable to intersectionTimesLWP, but ensures that parameter values 0<=t<=1 are points inside the line segments.

geomtools.intersectionPointsSWP(S, p, n, mode='all', return_all=False)

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.

Returns: if return_all==True, a (nS,np,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*np.

geomtools.intersectionTimesLWT(q, m, F, mode='all')

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)

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')

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 (1-t)*S[...,0,:] + t*S[...,1,:].

geomtools.intersectionPointsSWT(S, F, mode='all', return_all=False)

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')

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')

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.intersectionTimesPOP(X, p, n, mode='all')

Return the intersection of perpendiculars from points X on planes (p,n).

Parameters:

  • X: a (nX,3) shaped array of points (mode=all) or broadcast compatible array (mode=pair).
  • 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 for each point X with all planes (p,n) or pair for pairwise intersections.

Returns: A (nX,np) shaped (mode=all) array of parameter values t, such that the intersection points are given by X+t*n.

geomtools.intersectionPointsPOP(X, p, n, mode='all')

Return the intersection points of perpendiculars from points X on planes (p,n).

This is like intersectionTimesPOP but returns a (nX,np,3) shaped (mode=all) array of intersection points instead of the parameter values.

geomtools.intersectionTimesPOL(X, q, m, mode='all')

Return the intersection of perpendiculars from points X on lines (q,m).

Parameters:

  • X: a (nX,3) shaped array of points (mode=all) or broadcast compatible array (mode=pair).
  • 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.
  • mode: all to calculate the intersection for each point X with all lines (q,m) or pair for pairwise intersections.

Returns: A (nX,nq) shaped (mode=all) array of parameter values t, such that the intersection points are given by q+t*m.

geomtools.intersectionPointsPOL(X, q, m, mode='all')

Return the intersection points of perpendiculars from points X on lines (q,m).

This is like intersectionTimesPOL but returns a (nX,nq,3) shaped (mode=all) array of intersection points instead of the parameter values.

geomtools.distancesPFL(X, q, m, mode='all')

Return the distances of points X from lines (q,m).

Parameters:

  • X: a (nX,3) shaped array of points (mode=all) or broadcast compatible array (mode=pair).
  • 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.
  • mode: all to calculate the distance of each point X from all lines (q,m) or pair for pairwise distances.

Returns: A (nX,nq) shaped (mode=all) array of distances.

geomtools.distancesPFS(X, S, mode='all')

Return the distances of points X from line segments S.

Parameters:

  • X: a (nX,3) shaped array of points (mode=all) or broadcast compatible array (mode=pair).
  • S: (nS,2,3) shaped array of line segments (mode=all) or broadcast compatible array (mode=pair), defining a single line segment or a set of line segments.
  • mode: all to calculate the distance of each point X from all line segments S or pair for pairwise distances.

Returns: A (nX,nS) shaped (mode=all) array of distances.

geomtools.insideTriangle(x, P, method='bary')

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.

geomtools.faceDistance(X, Fp, return_points=False)

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)

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)

Compute the barycentric coordinates of points P wrt. simplexes S.

S is a (nel,nplex,3) shaped array of n-simplexes (n=nplex-1): - 1-simplex: line segment - 2-simplex: triangle - 3-simplex: 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)

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.