xdesign.geometry

Define geometric objects for compuational geometry operations.

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.

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]

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

x

Dimension 0 of the point.

y

Dimension 1 of the point.

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 coeffients 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.rotated(self, theta, center=None, axis=None)[source]

Rotates theta radians around an axis.

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.

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.

standard

Returns coeffients for the first N-1 standard equation coefficients. The Nth is returned separately.

xintercept

Return the x-intercept.

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.

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

Return the area.

bounding_box

Return the axis-aligned bounding box as two numpy vectors.

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.

diameter

Returns the diameter.

list

Return list representation for saving to files.

patch

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

vertices
Type:List of Points
sign

The sign of the area

Type:int (-1 or 1)
area = <MagicMock name='mock()' id='140706171286752'>
bounding_box

Return the axis-aligned bounding box as two numpy vectors.

bounds

Returns a 4-tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the Polygon.

center = <MagicMock name='mock()' id='140706171286752'>
contains(other)[source]

Return whether this Polygon contains the other.

edges

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

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

Return list representation.

numpy

Return Numpy representation.

numverts
patch

Returns a matplotlib patch.

perimeter = <MagicMock name='mock()' id='140706171286752'>
radius = <MagicMock name='mock()' id='140706171286752'>
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.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='140706171286752'>
center = <MagicMock name='mock()' id='140706171286752'>
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.

side_lengths

The lengths of the sides

Type:array
area = <MagicMock name='mock()' id='140706171286752'>
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.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.

bounding_box

Return the axis-aligned bounding box as two numpy vectors.

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.

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.

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
  • Reference
  • ———
  • Glassner, A. S. (Ed.). (2013). Graphics gems. Elsevier.