xdesign.geometry
¶
Define geometric objects for compuational geometry operations.
Module author: Doga Gursoy <dgursoy@aps.anl.gov>
Module author: Daniel J Ching <carterbox@users.noreply.github.com>
Zero dimensional entities¶
Define zero dimensional geometric entities.
Classes:
|
Define a point in ND cartesian space. |
- class xdesign.geometry.point.Point(x)[source]¶
Bases:
xdesign.geometry.entity.Entity
Define a point in ND cartesian space.
- Parameters
x (
ndarray
,list
) – ND coordinates of the point.- Raises
TypeError – If x is not a list or ndarray.
- contains(other)[source]¶
Return wether the other is within the bounds of the Point.
Points can only contain other Points.
- property norm¶
Euclidian (L2) norm of the vector to the point.
- scale(vector)[source]¶
Scale the ambient space in each dimension according to vector.
Scaling is centered on the origin.
- property x¶
Dimension 0 of the point.
- property y¶
Dimension 1 of the point.
- property z¶
Dimension 2 of the point.
- xdesign.geometry.point.calc_standard(A)[source]¶
Return the standard equation for the row-wise points in A.
The coefficents (c_{0}*x + … = c_{1}) describe the hyper-plane defined by the row-wise N-dimensional points A.
- Parameters
A (
np.array
(…, N, N)) – Each row is an N-dimensional point on the plane.- Returns
c0 (
np.array
(…, N)) – The first N coefficients for the hyper-planec1 (
np.array
(…, 1)) – The last coefficient for the hyper-plane
One dimensional entities¶
Define one dimensional geometric entities.
Classes:
|
Line in 2D cartesian space. |
|
Defines a finite line segment from two unique points. |
- class xdesign.geometry.line.Line(p1, p2)[source]¶
Bases:
xdesign.geometry.line.LinearEntity
Line in 2D cartesian space.
The constructor takes two unique
Point
.- property standard¶
Returns coeffients for the first N-1 standard equation coefficients. The Nth is returned separately.
- property xintercept¶
Return the x-intercept.
- property yintercept¶
Return the y-intercept.
Two dimensional entities¶
Define two dimensional geometric entities.
Classes:
|
The base class for closed manifolds defined by a single equation. |
|
Circle in 2D cartesian space. |
|
A convex polygon in 2D cartesian space. |
|
A regular polygon in 2D cartesian space. |
|
Triangle in 2D cartesian space. |
|
Rectangle in 2D cartesian space. |
|
Square in 2D cartesian space. |
|
A collection of Entities |
- class xdesign.geometry.area.Circle(center, radius, sign=1)[source]¶
Bases:
xdesign.geometry.area.Curve
Circle in 2D cartesian space.
- radius¶
The radius of the circle.
- Type
scalar
- property area¶
Return the area.
- property bounding_box¶
Return the axis-aligned bounding box as two numpy vectors.
- property circumference¶
Returns the circumference.
- contains(other)[source]¶
Return whether other is a proper subset.
Return one boolean for all geometric entities. Return an array of boolean for array input.
- property diameter¶
Returns the diameter.
- property list¶
Return list representation for saving to files.
- property patch¶
Returns a matplotlib patch.
- class xdesign.geometry.area.Curve(center)[source]¶
Bases:
xdesign.geometry.entity.Entity
The base class for closed manifolds defined by a single equation. e.g.
Circle
,Sphere
, orTorus
.
- class xdesign.geometry.area.Mesh(obj=None, faces=[])[source]¶
Bases:
xdesign.geometry.entity.Entity
A collection of Entities
- property bounding_box¶
Return the axis-aligned bounding box as two numpy vectors.
- property center¶
- contains(other)[source]¶
Return whether this Mesh contains other.
FOR ALL x, THERE EXISTS a face of the Mesh that contains x AND (ALL cut outs that contain x or THERE DOES NOT EXIST a cut out).
- property patch¶
- class xdesign.geometry.area.Polygon(vertices, sign=1)[source]¶
Bases:
xdesign.geometry.entity.Entity
A convex polygon in 2D cartesian space.
It is defined by a number of distinct vertices of class
Point
. Superclasses includeSquare
,Triangle
, etc.- vertices¶
- Type
List of Points
:raises ValueError : If the number of vertices is less than three.:
- area = <MagicMock name='mock()' id='139660964738896'>¶
- property bounding_box¶
Return the axis-aligned bounding box as two numpy vectors.
- property bounds¶
Returns a 4-tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the Polygon.
- center = <MagicMock name='mock()' id='139660964738896'>¶
- property edges¶
Return a list of lines connecting the points of the Polygon.
- half_space = <MagicMock name='mock()' id='139660964738896'>¶
- property list¶
Return list representation.
- property numpy¶
Return Numpy representation.
- property numverts¶
- property patch¶
Returns a matplotlib patch.
- perimeter = <MagicMock name='mock()' id='139660964738896'>¶
- radius = <MagicMock name='mock()' id='139660964738896'>¶
- class xdesign.geometry.area.Rectangle(center, side_lengths)[source]¶
Bases:
xdesign.geometry.area.Polygon
Rectangle in 2D cartesian space.
Defined by a point and a vector to enforce perpendicular sides.
- Parameters
side_lengths (array) – The lengths of the sides
- area = <MagicMock name='mock()' id='139660964738896'>¶
- class xdesign.geometry.area.RegularPolygon(center, radius, order, angle=0, sign=1)[source]¶
Bases:
xdesign.geometry.area.Polygon
A regular polygon in 2D cartesian space.
It is defined by the polynomial center, order, and radius.
By default (i.e. when the
angle
parameter is zero), the regular polygon is oriented so that one of the vertices is at coordinates \((x + r, x)\) where \(x\) is the x-coordinate ofcenter
and \(r\) =radius
. Theangle
parameter is only meaningful modulo \(2\pi /\)order
since rotation by \(2\pi /\)order
gives a result equivalent to no rotation.- Parameters
center (
Point
) – The center of the polygonradius (float) – Distance from polygon center to vertices
order (int) – Order of the polygon (e.g. order 6 is a hexagon).
angle (float) – Optional rotation angle in radians.
sign (int (-1 or 1)) – Optional sign of the area (see
Polygon
)
- class xdesign.geometry.area.Square(center, side_length=None, radius=None)[source]¶
Bases:
xdesign.geometry.area.Rectangle
Square in 2D cartesian space.
Defined by a point and a length to enforce perpendicular sides.
- class xdesign.geometry.area.Triangle(p1, p2, p3)[source]¶
Bases:
xdesign.geometry.area.Polygon
Triangle in 2D cartesian space.
It is defined by three distinct points.
- area = <MagicMock name='mock()' id='139660964738896'>¶
- center = <MagicMock name='mock()' id='139660964738896'>¶
Intersect¶
Define algorithms to support intersection calculation.
Functions:
|
Clip a polygon using the Sutherland-Hodgeman algorithm. |
|
Return the area of intersection between a circle and half-plane. |
- xdesign.geometry.intersect.clip_SH(clipEdges, polygon)[source]¶
Clip a polygon using the Sutherland-Hodgeman algorithm.
- Parameters
clipEdges [[A, b], …] – half-spaces defined by coefficients
polygon
- xdesign.geometry.intersect.halfspacecirc(d, r)[source]¶
Return the area of intersection between a circle and half-plane.
Returns the smaller fraction of a circle split by a line d units away from the center of the circle.
- Parameters
d (scalar) – The distance from the line to the center of the circle
r (scalar) – The radius of the circle
- Returns
f (scalar) – The proportion of the circle in the smaller half-space
References
Glassner, A. S. (Ed.). (2013). Graphics gems. Elsevier.