# geometry

The functions of this package take various geometric primitives as input parameters. These primitives may be passed into those functions as instances of the corresponding classes or as an equivalent representation using (combinations of) built-in Python objects. The following table defines those equivalent representations.

parameter

representation

vector

list of XYZ coordinates.

point

list of XYZ coordinates.

segment

2-tuple of points.

line

2-tuple of points.

ray

2-tuple of points.

polyline

list of points.

polygon

list of points.

plane

2-tuple of origin (point) and normal (vector).

frame

3-tuple of origin (point), U axis (vector) and V axis (vector).

circle

3-tuple of center (point), normal (vector) and radius (float).

>>> cross_vectors([1.0, 0.0, 0.0], [0.0, 1.0, 0.0])
[0.0, 0.0, 1.0]
>>> cross_vectors(Vector(1, 0, 0), [0, 1, 0])
[0.0, 0.0, 1.0]
>>> cross_vectors(Vector(1, 0, 0), Vector(0, 1, 0))
[0.0, 0.0, 1.0]
>>> points = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0]]
>>> area_polygon(points) == area_polygon(Polygon(points))
True


Many functions also have an _xy variant. These variants ignore the Z-component of the input parameters. Therefore, they also accept 2D representations of geometric objects. However, they always return a 3D result in the XY plane (with z = 0). For example, scale_vector_xy accepts both 2D and 3D vectors, but always returns a 3D vector with the Z-component set to zero.

>>> points = [[0.0, 0.0, 1.0], [1.0, 0.0, 0.0], [1.0, 1.0, 1.0], [0.0, 1.0, 0.0]]
>>> area_polygon_xy(points) == area_polygon(points)
False


## Primitives

 Box A box is defined by a frame and its dimensions along the frame’s x-, y- and z-axes. Circle A circle is defined by a plane and a radius. Cone A cone is defined by a circle and a height. Cylinder A cylinder is defined by a circle and a height. Frame A frame is defined by a base point and two orthonormal base vectors. Line A line is defined by two points. Plane A plane is defined by a base point and a normal vector. Point A point is defined by XYZ coordinates. Polygon An object representing an ordered collection of points in space connected by straight line segments forming a closed boundary around the interior space. Polyhedron Compute the vertices and faces of one of the Platonic solids. Polyline A polyline is a sequence of points connected by line segments. Quaternion Creates a Quaternion object. Sphere A sphere is defined by a point and a radius. Torus A torus is defined by a plane and two radii. Vector A vector is defined by XYZ components and a homogenisation factor.

## Transformations

XForms

 Projection Reflection Creates a Reflection that mirrors points at a plane, defined by point and normal vector. Rotation Rotation extends Transformation to represent a 4x4 rotation matrix. Scale Creates a scaling transformation. Shear Constructs a Shear transformation by an angle along the direction vector on the shear plane (defined by point and normal). Transformation The Transformation represents a 4x4 transformation matrix. Translation Creates a translation transformation.

Functions

 mirror_points_line Mirror a point about a line. mirror_points_line_xy Mirror a point about a line. mirror_points_plane Mirror a point about a plane. mirror_points_point Mirror multiple points about a point. mirror_points_point_xy Mirror multiple points about a point. project_points_line Project points onto a line. project_points_line_xy Project points onto a line in the XY plane. project_points_plane Project multiple points onto a plane. reflect_line_plane Bounce a line of a reflection plane. reflect_line_triangle Bounce a line of a reflection triangle. rotate_points Rotates points around an arbitrary axis in 3D. rotate_points_xy Rotates points in the XY plane around the Z axis at a specific origin. scale_points Scale points. translate_points Translate points. translate_points_xy Translate points and in the XY plane.

Conversions

 axis_and_angle_from_matrix Returns the axis and the angle of the rotation matrix M. axis_angle_vector_from_matrix Returns the axis-angle vector of the rotation matrix M. axis_angle_from_quaternion Returns an axis and an angle of rotation from the given quaternion. basis_vectors_from_matrix Returns the basis vectors from the rotation matrix R. euler_angles_from_matrix Returns Euler angles from the rotation matrix M according to specified axis sequence and type of rotation. euler_angles_from_quaternion Returns Euler angles from a quaternion. matrix_from_frame Computes a change of basis transformation from world XY to the frame. matrix_from_euler_angles Calculates a rotation matrix from Euler angles. matrix_from_axis_and_angle Calculates a rotation matrix from an rotation axis, an angle and an optional point of rotation. matrix_from_axis_angle_vector Calculates a rotation matrix from an axis-angle vector. matrix_from_basis_vectors Creates a rotation matrix from basis vectors (= orthonormal vectors). matrix_from_translation Returns a 4x4 translation matrix in row-major order. matrix_from_orthogonal_projection Returns an orthogonal projection matrix to project onto a plane defined by point and normal. matrix_from_parallel_projection Returns an parallel projection matrix to project onto a plane defined by point, normal and direction. matrix_from_perspective_projection Returns a perspective projection matrix to project onto a plane defined by point, normal and perspective. matrix_from_perspective_entries Returns a matrix from perspective entries. matrix_from_shear_entries Returns a shear matrix from the 3 factors for x-y, x-z, and y-z axes. matrix_from_shear Constructs a shear matrix by an angle along the direction vector on the shear plane (defined by point and normal). matrix_from_scale_factors Returns a 4x4 scaling transformation. matrix_from_quaternion Calculates a rotation matrix from quaternion coefficients. quaternion_from_matrix Returns the 4 quaternion coefficients from a rotation matrix. quaternion_from_euler_angles Returns a quaternion from Euler angles. quaternion_from_axis_angle Returns a quaternion describing a rotation around the given axis by the given angle.

Quaternion math

 quaternion_norm Calculates the length (euclidean norm) of a quaternion. quaternion_unitize Makes a quaternion unit-length. quaternion_is_unit Checks if a quaternion is unit-length. quaternion_multiply Multiplies two quaternions. quaternion_canonize Converts a quaternion into a canonic form if needed. quaternion_conjugate Conjugate of a quaternion.

## Linear algebra

 add_vectors Add two vectors. add_vectors_xy Add two vectors, assuming they lie in the XY-plane. cross_vectors Compute the cross product of two vectors. cross_vectors_xy Compute the cross product of two vectors, assuming they lie in the XY-plane. divide_vectors Element-wise division of two vectors. divide_vectors_xy Element-wise division of two vectors assumed to lie in the XY plane. dot_vectors Compute the dot product of two vectors. dot_vectors_xy Compute the dot product of two vectors, assuming they lie in the XY-plane. length_vector Calculate the length of the vector. length_vector_xy Compute the length of a vector, assuming it lies in the XY plane. length_vector_sqrd Compute the squared length of a vector. length_vector_sqrd_xy Compute the squared length of a vector, assuming it lies in the XY plane. multiply_matrices Mutliply a matrix with a matrix. multiply_matrix_vector Multiply a matrix with a vector. multiply_vectors Element-wise multiplication of two vectors. multiply_vectors_xy Element-wise multiplication of two vectors assumed to lie in the XY plane. norm_vector Calculate the length of a vector. norm_vectors Calculate the norm of each vector in a list of vectors. normalize_vector Normalise a given vector. normalize_vector_xy Normalize a vector, assuming it lies in the XY-plane. normalize_vectors Normalise multiple vectors. normalize_vectors_xy Normalise multiple vectors, assuming they lie in the XY plane. orthonormalize_vectors Orthonormalize a set of vectors. power_vector Raise a vector to the given power. power_vectors Raise a list of vectors to the given power. scale_vector Scale a vector by a given factor. scale_vector_xy Scale a vector by a given factor, assuming it lies in the XY plane. scale_vectors Scale multiple vectors by a given factor. scale_vectors_xy Scale multiple vectors by a given factor, assuming they lie in the XY plane. square_vector Raise a vector to the power 2. square_vectors Raise a multiple vectors to the power 2. subtract_vectors Subtract one vector from another. subtract_vectors_xy Subtract one vector from another, assuming they lie in the XY plane. sum_vectors Calculate the sum of a series of vectors along the specified axis. transpose_matrix Transpose a matrix. vector_component Compute the component of u in the direction of v. vector_component_xy Compute the component of u in the direction of v, assuming they lie in the XY-plane.

## Points, Vectors, Lines, Planes

Angles

 angle_points Compute the smallest angle between the vectors defined by three points. angle_points_xy Compute the smallest angle between the vectors defined by the XY components of three points. angle_vectors Compute the smallest angle between two vectors. angle_vectors_xy Compute the smallest angle between the XY components of two vectors. angles_points Compute the two angles between two vectors defined by three points. angles_points_xy Compute the two angles between the two vectors defined by the XY components of three points. angles_vectors Compute the the 2 angles formed by a pair of vectors. angles_vectors_xy Compute the angles between the XY components of two vectors.

Distance

 distance_line_line Compute the shortest distance between two lines. distance_point_line Compute the distance between a point and a line. distance_point_line_xy Compute the distance between a point and a line, assuming they lie in the XY-plane. distance_point_line_sqrd Compute the squared distance between a point and a line. distance_point_line_sqrd_xy Compute the squared distance between a point and a line lying in the XY-plane. distance_point_plane Compute the distance from a point to a plane defined by origin point and normal. distance_point_point Compute the distance bewteen a and b. distance_point_point_xy Compute the distance between points a and b, assuming they lie in the XY plane. distance_point_point_sqrd Compute the squared distance bewteen points a and b. distance_point_point_sqrd_xy Compute the squared distance between points a and b lying in the XY plane.

Centroids

 centroid_points Compute the centroid of a set of points. centroid_points_xy Compute the centroid of a set of points lying in the XY-plane. midpoint_point_point Compute the midpoint of two points lying in the XY-plane. midpoint_point_point_xy Compute the midpoint of two points lying in the XY-plane. midpoint_line Compute the midpoint of a line defined by two points. midpoint_line_xy Compute the midpoint of a line defined by two points. weighted_centroid_points Compute the weighted centroid of a set of points.

## Polygons & Polyhedrons

Centroid

 centroid_polygon Compute the centroid of the surface of a polygon. centroid_polygon_xy Compute the centroid of the surface of a polygon projected to the XY plane. centroid_polygon_vertices Compute the centroid of the vertices of a polygon. centroid_polygon_vertices_xy centroid_polygon_edges Compute the centroid of the edges of a polygon. centroid_polygon_edges_xy centroid_polyhedron Compute the center of mass of a polyhedron.

Area and volume

 area_polygon Compute the area of a polygon. area_polygon_xy Compute the area of a polygon lying in the XY-plane. area_triangle Compute the area of a triangle defined by three points. area_triangle_xy Compute the area of a triangle defined by three points lying in the XY-plane. volume_polyhedron Compute the volume of a polyhedron represented by a closed mesh.

Normals

 normal_polygon Compute the normal of a polygon defined by a sequence of points. normal_triangle Compute the normal vector of a triangle. normal_triangle_xy Compute the normal vector of a triangle assumed to lie in the XY plane.

## Pointclouds

Bounding Box

 bounding_box Computes the axis-aligned minimum bounding box of a list of points. bounding_box_xy Compute the axis-aligned minimum bounding box of a list of points in the XY-plane. oriented_bounding_box_numpy Compute the oriented minimum bounding box of a set of points in 3D space. oriented_bounding_box_xy_numpy Compute the oriented minimum bounding box of set of points in the XY plane.

Convex Hull

 convex_hull Construct convex hull for a set of points. convex_hull_numpy Compute the convex hull of a set of points. convex_hull_xy Computes the convex hull of a set of 2D points. convex_hull_xy_numpy Compute the convex hull of a set of points in the XY plane.

Triangulation

 delaunay_from_points Computes the delaunay triangulation for a list of points. delaunay_from_points_numpy Computes the delaunay triangulation for a list of points using Numpy. voronoi_from_points_numpy Generate a voronoi diagram from a set of points.

## Queries

 is_ccw_xy Determine if c is on the left of ab when looking from a to b, and assuming that all points lie in the XY plane. is_colinear Determine if three points are colinear. is_colinear_xy Determine if three points are colinear in the XY plane. is_coplanar Determine if the points are coplanar. is_intersection_line_line Verifies if two lines intersection in one point. is_intersection_line_line_xy Determine if two lines intersect in 2d lying in the XY plane. is_intersection_line_plane Determine if a line (continuous ray) intersects with a plane. is_intersection_line_triangle Verifies if a line (ray) intersects with a triangle. is_intersection_plane_plane Computes the intersection of two planes is_intersection_segment_plane Determine if a line segment intersects with a plane. is_intersection_segment_segment is_intersection_segment_segment_xy Determine if two the segments ab and cd intersect? is_polygon_convex Determine if a polygon is convex. is_polygon_convex_xy Determine if the polygon is convex in the XY-plane. is_point_in_circle Determine if a point lies in a circle. is_point_in_circle_xy Determine if a point lies in a circle lying in the XY plane. is_point_in_convex_polygon_xy Determine if a point is in the interior of a convex polygon lying in the XY-plane. is_point_on_line Determine if a point lies on a line. is_point_on_line_xy Determine if a point lies on a line in the XY-plane. is_point_on_plane Determine if a point lies in a plane. is_point_infront_plane Determine if a point lies in front of a plane. is_point_in_polygon_xy Determine if a point is in the interior of a polygon lying in the XY-plane. is_point_on_polyline Determine if a point is on a polyline. is_point_on_segment Determine if a point lies on a given line segment. is_point_on_segment_xy Determine if a point lies on a given line segment in the XY-plane. is_point_in_triangle Determine if a point is in the interior of a triangle. is_point_in_triangle_xy Determine if a point is in the interior of a triangle lying in the XY-plane.

## Proximity

 closest_point_in_cloud Calculates the closest point in a pointcloud. closest_point_in_cloud_xy Calculates the closest point in a list of points in the XY-plane. closest_point_on_line Computes closest point on line to a given point. closest_point_on_line_xy Compute closest point on line (continuous) to a given point lying in the XY-plane. closest_point_on_plane Compute closest point on a plane to a given point. closest_point_on_polyline Find the closest point on a polyline to a given point. closest_point_on_polyline_xy Compute closest point on a polyline to a given point, assuming they both lie in the XY-plane. closest_point_on_segment Computes closest point on line segment (p1, p2) to testpoint. closest_point_on_segment_xy Compute closest point on line segment to a given point lying in the XY-plane.

## Intersections

 intersection_circle_circle_xy Calculates the intersection points of two circles in 2d lying in the XY plane. intersection_line_line Computes the intersection of two lines. intersection_line_line_xy Compute the intersection of two lines, assuming they lie in the XY plane. intersection_line_plane Computes the intersection point of a line and a plane intersection_line_triangle Computes the intersection point of a line (ray) and a triangle based on the Moeller Trumbore intersection algorithm intersection_plane_plane Computes the intersection of two planes intersection_plane_plane_plane Computes the intersection of three planes intersection_segment_segment_xy Compute the intersection of two lines segments, assuming they lie in the XY plane. intersection_segment_plane Computes the intersection point of a line segment and a plane

## Offsets

 offset_line Offset a line by a distance. offset_polyline Offset a polyline by a distance. offset_polygon Offset a polygon (closed) by a distance.

## Optimisation

Smoothing

 smooth_centroid Smooth a connected set of vertices by moving each vertex to the centroid of its neighbors. smooth_centerofmass Smooth a connected set of vertices by moving each vertex to the center of mass of the polygon formed by the neighboring vertices. smooth_area Smooth a set of connected vertices by moving each vertex to the centroid of the surrounding faces, weighted by the area of the face.

Planarisation

 flatness Compute mesh flatness per face. planarize_faces Planarise a set of connected faces.

Interpolation

 discrete_coons_patch Creates a coons patch from a set of four or three boundary polylines (ab, bc, dc, ad). tween_points Compute the interpolated points between two sets of points. tween_points_distance Compute an interpolated set of points between two sets of points, at a given distance.

Bestfit

 bestfit_circle_numpy Fit a circle through a set of points. bestfit_plane Fit a plane to a list of (more than three) points. bestfit_plane_numpy Fit a plane through more than three (non-coplanar) points.

## Other functions

Parametric curves

 archimedean_spiral_evaluate Evalutes a spiral at a parameter. circle_evaluate Evalutes a circle at a parameter. ellipse_evaluate Evalutes an ellipse at a parameter. helix_evaluate Evalutes an helix at a parameter. logarithmic_spiral_evaluate Evalutes a logarithmic spiral at a parameter.

Isolines

 scalarfield_contours_numpy Compute the contour lines of a scalarfield.