# Geom2d

From MatGeom

The **geom2d** module contains several functions for the manipulations of planar shapes
such as points, lines, circles and ellipses, polygons...
The goal is to provide a low-level library for manipulating geometrical
primitives, making easier the development of more complex geometric
algorithms.

Most functions works for planar shapes, but some ones have been extended to 3D or to any dimension.

## Contents

- 1 Function list
- 1.1 Points
- 1.2 Point Sets
- 1.3 Vectors
- 1.4 Straight lines
- 1.5 Edges (line segments between 2 points)
- 1.6 Rays
- 1.7 Relations between points and lines
- 1.8 Circles
- 1.9 Ellipses and Parabola
- 1.10 Geometric transforms
- 1.11 Angles
- 1.12 Boxes
- 1.13 Triangles
- 1.14 Rectangles
- 1.15 Splines
- 1.16 Various drawing functions
- 1.17 Other shapes

## Function list

### Points

- points2d - Description of functions operating on points
- midPoint - Middle point of two points or of an edge
- circumCenter - Circumcenter of three points
- isCounterClockwise - Compute relative orientation of 3 points
- polarPoint - Create a point from polar coordinates (rho + theta)
- angle2Points - Compute horizontal angle between 2 points
- angle3Points - Compute oriented angle made by 3 points
- distancePoints - Compute distance between two points
- transformPoint - Transform a point with an affine transform
- drawPoint - Draw the point on the axis.

### Point Sets

- clipPoints - Clip a set of points by a box
- centroid - Compute centroid (center of mass) of a set of points
- boundingBox - Bounding box of a set of points
- angleSort - Sort points in the plane according to their angle to origin
- minDistancePoints - Minimal distance between several points
- mergeClosePoints - Merge points that are closer than a given distance
- hausdorffDistance - Hausdorff distance between two point sets
- nndist - Nearest-neighbor distances of each point in a set

### Vectors

- vectors2d - Description of functions operating on plane vectors
- createVector - Create a vector from two points
- vectorNorm - Compute norm of a vector, or of a set of vectors
- vectorAngle - Angle of a vector, or between 2 vectors
- normalizeVector - Normalize a vector to have norm equal to 1
- isPerpendicular - Check orthogonality of two vectors
- isParallel - Check parallelism of two vectors
- transformVector - Transform a vector with an affine transform
- rotateVector - Rotate a vector by a given angle

### Straight lines

- lines2d - Description of functions operating on planar lines
- createLine - Create a straight line from 2 points, or from other inputs
- medianLine - Create a median line between two points
- cartesianLine - Create a straight line from cartesian equation coefficients
- orthogonalLine - Create a line orthogonal to another one.
- parallelLine - Create a line parallel to another one.
- intersectLines - Return all intersection points of N lines in 2D
- lineAngle - Computes angle between two straight lines
- linePosition - Position of a point on a line
- lineFit - Fit a straight line to a set of points
- clipLine - Clip a line with a box
- reverseLine - Return same line but with opposite orientation
- transformLine - Transform a line with an affine transform
- drawLine - Draw a straight line clipped by the current axis

### Edges (line segments between 2 points)

- edges2d - Description of functions operating on planar edges
- createEdge - Create an edge between two points, or from a line
- edgeToLine - Convert an edge to a straight line
- edgeAngle - Return angle of edge
- edgeLength - Return length of an edge
- parallelEdge - Edge parallel to another edge
- centeredEdgeToEdge - Convert a centered edge to a two-points edge
- midPoint - Middle point of two points or of an edge
- edgePosition - Return position of a point on an edge
- clipEdge - Clip an edge with a rectangular box
- reverseEdge - Intervert the source and target vertices of edge
- intersectEdges - Return all intersections between two set of edges
- intersectLineEdge - Return intersection between a line and an edge
- transformEdge - Transform an edge with an affine transform
- edgeToPolyline - Convert an edge to a polyline with a given number of segments
- drawEdge - Draw an edge given by 2 points
- drawCenteredEdge - Draw an edge centered on a point

### Rays

- rays2d - Description of functions operating on planar rays
- createRay - Create a ray (half-line), from various inputs
- bisector - Return the bisector of two lines, or 3 points
- clipRay - Clip a ray with a box
- drawRay - Draw a ray on the current axis

### Relations between points and lines

- distancePointEdge - Minimum distance between a point and an edge
- distancePointLine - Minimum distance between a point and a line
- projPointOnLine - Project of a point orthogonally onto a line
- pointOnLine - Create a point on a line at a given position on the line
- isPointOnLine - Test if a point belongs to a line
- isPointOnEdge - Test if a point belongs to an edge
- isPointOnRay - Test if a point belongs to a ray
- isLeftOriented - Test if a point is on the left side of a line

### Circles

- circles2d - Description of functions operating on circles
- createCircle - Create a circle from 2 or 3 points
- createDirectedCircle - Create a directed circle
- intersectCircles - Intersection points of two circles
- intersectLineCircle - Intersection point(s) of a line and a circle
- circleToPolygon - Convert a circle into a series of points
- circleArcToPolyline - Convert a circle arc into a series of points
- isPointInCircle - Test if a point is located inside a given circle
- isPointOnCircle - Test if a point is located on a given circle.
- enclosingCircle - Find the minimum circle enclosing a set of points.
- circumCircle - Circumscribed circle of three points
- radicalAxis - Compute the radical axis (or radical line) of 2 circles
- drawCircle - Draw a circle on the current axis
- drawCircleArc - Draw a circle arc on the current axis

### Ellipses and Parabola

- ellipses2d - Description of functions operating on ellipses
- inertiaEllipse - Inertia ellipse of a set of points
- isPointInEllipse - Check if a point is located inside a given ellipse
- ellipsePerimeter - Perimeter of an ellipse
- ellipseToPolygon - Convert an ellipse into a series of points
- drawEllipse - Draw an ellipse on the current axis
- drawEllipseArc - Draw an ellipse arc on the current axis
- drawParabola - Draw a parabola on the current axis

### Geometric transforms

- transforms2d - Description of functions operating on transforms
- createTranslation - Create the 3*3 matrix of a translation
- createRotation - Create the 3*3 matrix of a rotation
- createRotation90 - Matrix of a rotation for 90 degrees multiples
- createScaling - Create the 3*3 matrix of a scaling in 2 dimensions
- createHomothecy - Create the the 3x3 matrix of an homothetic transform
- createBasisTransform - Compute matrix for transforming a basis into another basis
- createLineReflection - Create the the 3x3 matrix of a line reflection
- fitAffineTransform2d - Fit an affine transform using two point sets
- polynomialTransform2d - Apply a polynomial transform to a set of points
- fitPolynomialTransform2d - Coefficients of polynomial transform between two point sets

### Angles

- angles2d - Description of functions for manipulating angles
- normalizeAngle - Normalize an angle value within a 2*PI interval
- angleAbsDiff - Absolute difference between two angles
- angleDiff - Difference between two angles
- deg2rad - Convert angle from degrees to radians
- rad2deg - Convert angle from radians to degrees

### Boxes

- boxes2d - Description of functions operating on bounding boxes
- intersectBoxes - Intersection of two bounding boxes
- mergeBoxes - Merge two boxes, by computing their greatest extent
- randomPointInBox - Generate random point within a box
- boxToRect - Convert box data to rectangle data
- drawBox - Draw a box defined by coordinate extents

### Triangles

- isPointInTriangle - Test if a point is located inside a triangle
- triangleArea - Signed area of a triangle

### Rectangles

- rectToPolygon - Convert a rectangle into a polygon (set of vertices)
- rectToBox - Convert rectangle data to box data
- drawRect - Draw rectangle on the current axis
- orientedBox - Minimum-width oriented bounding box of a set of points
- orientedBoxToPolygon - Convert an oriented box to a polygon (set of vertices)
- drawOrientedBox - Draw centered oriented rectangle

### Splines

- cubicBezierToPolyline - Compute equivalent polyline from bezier curve control
- drawBezierCurve - Draw a cubic bezier curve defined by 4 control points

### Various drawing functions

- drawVector - Draw vector at a given position
- drawArrow - Draw an arrow on the current axis
- drawLabels - Draw labels at specified positions
- drawShape - Draw various types of shapes (circles, polygons...)
- isAxisHandle - Check if the input corresponds to a valid axis hanfle

### Other shapes

- squareGrid - Generate equally spaces points in plane.
- hexagonalGrid - Generate hexagonal grid of points in the plane.
- triangleGrid - Generate triangular grid of points in the plane.
- crackPattern - Create a (bounded) crack pattern tessellation
- crackPattern2 - Create a (bounded) crack pattern tessellation