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:

Point(x)

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.

collision(other)[source]

Return True if this Point collides with another entity.

contains(other)[source]

Return wether the other is within the bounds of the Point.

Points can only contain other Points.

distance(other)[source]

Return the closest distance this and the other.

property norm

Euclidian (L2) norm of the vector to the point.

rotate(theta, point=None, axis=None)[source]

Rotates theta radians around an axis.

scale(vector)[source]

Scale the ambient space in each dimension according to vector.

Scaling is centered on the origin.

translate(vector)[source]

Translate the point along the given vector.

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

  • c1 (np.array (…, 1)) – The last coefficient for the hyper-plane

xdesign.geometry.point.dim(self)[source]

Return the dimensionality of the ambient space.

xdesign.geometry.point.distance(self, other)[source]

Return the closest distance this and the other.

xdesign.geometry.point.norm(self)[source]

Euclidian (L2) norm of the vector.

xdesign.geometry.point.rotated(self, theta, center=None, axis=None)[source]

Rotates theta radians around an axis.

One dimensional entities

Define one dimensional geometric entities.

Classes:

Line(p1, p2)

Line in 2D cartesian space.

Segment(p1, p2)

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.

p1
Type

Point

p2
Type

Point

distance(other)[source]

Returns the closest distance between entities.

intercept(n)[source]

Calculates the intercept for the nth dimension.

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.

class xdesign.geometry.line.Segment(p1, p2)[source]

Bases: xdesign.geometry.line.Line

Defines a finite line segment from two unique points.

distance(other)[source]

Return the distance to the other.

property midpoint

Return the midpoint of the line segment.

Two dimensional entities

Define two dimensional geometric entities.

Classes:

Curve(center)

The base class for closed manifolds defined by a single equation.

Circle(center, radius[, sign])

Circle in 2D cartesian space.

Polygon(vertices[, sign])

A convex polygon in 2D cartesian space.

RegularPolygon(center, radius, order[, ...])

A regular polygon in 2D cartesian space.

Triangle(p1, p2, p3)

Triangle in 2D cartesian space.

Rectangle(center, side_lengths)

Rectangle in 2D cartesian space.

Square(center[, side_length, radius])

Square in 2D cartesian space.

Mesh([obj, faces])

A collection of Entities

class xdesign.geometry.area.Circle(center, radius, sign=1)[source]

Bases: xdesign.geometry.area.Curve

Circle in 2D cartesian space.

center

The center point of the circle.

Type

Point

radius

The radius of the circle.

Type

scalar

sign

The sign of the area

Type

int (-1 or 1)

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, or Torus.

center
Type

Point

rotate(theta, point=None, axis=None)[source]

Rotates the Curve by theta radians around an axis which passes through a point radians.

translate(vector)[source]

Translates the Curve along a vector.

class xdesign.geometry.area.Mesh(obj=None, faces=[])[source]

Bases: xdesign.geometry.entity.Entity

A collection of Entities

faces

A list of the Entities

Type

list

area

The total area of the Entities

Type

float

population

The number entities in the Mesh

Type

int

radius

The radius of a bounding circle

Type

float

append(t)[source]

Add a triangle to the mesh.

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

import_triangle(obj)[source]

Loads mesh data from a Python Triangle dict.

property patch
pop(i=- 1)[source]

Pop i-th triangle from the mesh.

rotate(theta, point=None, axis=None)[source]

Rotate entity around an axis which passes through a point by theta radians.

scale(vector)[source]

Scale entity.

translate(vector)[source]

Translate entity.

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 include Square, Triangle, etc.

vertices
Type

List of Points

sign

The sign of the area

Type

int (-1 or 1)

:raises ValueError : If the number of vertices is less than three.:

area = <MagicMock name='mock()' id='140346947267856'>
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='140346947267856'>
contains(other)[source]

Return whether this Polygon contains the other.

property edges

Return a list of lines connecting the points of the Polygon.

half_space = <MagicMock name='mock()' id='140346947267856'>
property list

Return list representation.

property numpy

Return Numpy representation.

property numverts
property patch

Returns a matplotlib patch.

perimeter = <MagicMock name='mock()' id='140346947267856'>
radius = <MagicMock name='mock()' id='140346947267856'>
rotate(theta, point=None, axis=None)[source]

Rotates the Polygon around an axis which passes through a point by theta radians.

translate(vector)[source]

Translates the polygon by a vector.

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='140346947267856'>
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 of center and \(r\) = radius. The angle 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 polygon

  • radius (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='140346947267856'>
center = <MagicMock name='mock()' id='140346947267856'>

Intersect

Define algorithms to support intersection calculation.

Functions:

clip_SH(clipEdges, polygon)

Clip a polygon using the Sutherland-Hodgeman algorithm.

halfspacecirc(d, r)

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.