xdesign.geometry

Functions:

Point(x) A point in ND cartesian space.
Superellipse(center, a, b, n) Superellipse in 2-D cartesian space.
Ellipse(center, a, b) Ellipse in 2-D cartesian space.
Circle(center, radius) Circle in 2-D cartesian space.
Line(p1, p2) Line in 2-D cartesian space.
Triangle(p1, p2, p3) Triangle in 2-D cartesian space.
Rectangle(p1, p2, p3, p4) Rectangle in 2-D cartesian space.
Square(center, side_length) Square in 2-D cartesian space.
class xdesign.geometry.Entity[source]

Bases: object

Base class for all geometric entities. All geometric entities should have these methods.

collision(other)[source]

Returns True if this entity collides with another entity.

contains(point)[source]

Returns True if the point(s) is within the bounds of the entity. point is either a Point or an N points listed as an NxD array.

dim

The dimensionality of the entity

distance(other)[source]

Return the closest distance between entities.

midpoint(other)[source]

Return the midpoint between entities.

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 in each dimension according to vector. Scaling is centered on the origin.

translate(vector)[source]

Translate entity along vector.

class xdesign.geometry.Point(x)[source]

Bases: xdesign.geometry.Entity

A point in ND cartesian space.

_x

1darray

ND coordinates of the point.

x

scalar

dimension 0 of the point.

y

scalar

dimension 1 of the point.

z

scalar

dimension 2 of the point.

norm

scalar

The L2/euclidian norm of the point.

collision(other)[source]

Returns True if this entity collides with another entity.

contains(other)[source]

Returns True if the other is within the bounds of the entity.

dim
distance(other)[source]

Return the closest distance between entities.

norm

Reference: http://stackoverflow.com/a/23576322

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

Rotate entity around an axis by theta radians.

scale(vector)[source]

Scale entity in each dimension according to vector. Scaling is centered on the origin.

translate(vector)[source]

Translate point along vector.

x
y
z
class xdesign.geometry.Circle(center, radius)[source]

Bases: xdesign.geometry.Curve

Circle in 2-D cartesian space.

center

Point

Defines the center point of the circle.

radius

scalar

Radius of the circle.

area

Return area.

circumference

Return circumference.

contains(points)[source]
diameter

Return diameter.

list

Return list representation for saving to files.

patch
scale(val)[source]

Scale.

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

Bases: xdesign.geometry.LinearEntity

Line in 2-D cartesian space.

It is defined by two distinct points.

p1

Point

p2

Point

distance(other)[source]

Return the closest distance between entities. REF: http://geomalgorithms.com/a02-_lines.html

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.Polygon(vertices)[source]

Bases: xdesign.geometry.Entity

A convex polygon in 2-D cartesian space.

It is defined by a number of distinct points.

vertices

sequence of Points

area

Return the area of the entity.

bounds

Return a tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the geometric figure.

contains(points)[source]
half_space
list

Return list representation.

numpy

Return Numpy representation.

numverts
patch
perimeter

Return the perimeter of the entity.

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

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

translate(vector)[source]

Translate polygon.

class xdesign.geometry.Triangle(p1, p2, p3)[source]

Bases: xdesign.geometry.Polygon

Triangle in 2-D cartesian space.

It is defined by three distinct points.

area
center
class xdesign.geometry.Rectangle(p1, p2, p3, p4)[source]

Bases: xdesign.geometry.Polygon

Rectangle in 2-D cartesian space.

It is defined by four distinct points.

area
center
class xdesign.geometry.Square(center, side_length)[source]

Bases: xdesign.geometry.Rectangle

Square in 2-D cartesian space.

It is defined by a center and a side length.

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

Bases: xdesign.geometry.Entity

A mesh object. It is a collection of polygons

append(t)[source]

Add a triangle to the mesh.

center
contains(points)[source]
half_space
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.