# geometry

## Classes

### Primitives

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

### XForms

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

### Other

 KDTree A tree for nearest neighbor search in a k-dimensional space.

## Functions

The functions in this section 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).

Note

Many functions have an _xy variant. These variants ignore the Z-component of the input parameters. Therefore, they also accept 2D representations of geometric objects. However, 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.

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

### Average

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

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

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

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

### Distance

 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. 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 three points. 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.

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

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

### Isolines

 scalarfield_contours_numpy Compute the contour lines of a scalarfield.

### Linalg

 add_vectors Add two vectors. add_vectors_xy Add two vectors, assuming they lie in the XY-plane. sum_vectors Calculate the sum of a series of vectors along the specified axis. 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. 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.

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

### Offset

 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.

### Planarisation

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

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

### Size

 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.

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

### Transformations

 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.

### 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. delaunay_triangle Construct a Delaunay triangulation of set of vertices. constrained_delaunay_triangle Construct a Delaunay triangulation of set of vertices, constrained to the specified segments. conforming_delaunay_triangle Construct a Delaunay triangulation of set of vertices, constrained to the specified segments, and with as many Steiner points inserted as necessary to make sure all faces of the triangulation are Delaunay. voronoi_from_points_numpy Generate a voronoi diagram from a set of points.