Geometry
momapy.geometry
Geometric primitives and transformations for momapy.
This module provides geometric classes and functions for working with points, lines, segments, curves, and transformations. It includes support for Bezier curves, elliptical arcs, and various geometric operations.
Examples:
from momapy.geometry import Point, Line, Segment, Rotation, Translation
# Create points
p1 = Point(0, 0)
p2 = Point(10, 10)
# Create a line
line = Line(p1, p2)
line.slope()
# Create a segment
segment = Segment(p1, p2)
segment.length()
# Apply transformations
rotated = p1.transformed(Rotation(math.pi / 2, p2))
Classes:
| Name | Description |
|---|---|
Bbox |
Represents a bounding box. |
CubicBezierCurve |
Represents a cubic Bezier curve. |
EllipticalArc |
Represents an elliptical arc. |
GeometryObject |
Abstract base class for all geometry objects. |
Line |
Represents an infinite line defined by two points. |
MatrixTransformation |
Represents a transformation as a 3x3 matrix. |
Point |
Represents a 2D point with x and y coordinates. |
QuadraticBezierCurve |
Represents a quadratic Bezier curve. |
Rotation |
Represents a rotation transformation. |
Scaling |
Represents a scaling transformation. |
Segment |
Represents a line segment between two points. |
Transformation |
Abstract base class for geometric transformations. |
Translation |
Represents a translation transformation. |
Functions:
| Name | Description |
|---|---|
get_normalized_angle |
Normalize an angle to [0, 2*pi). |
get_primitives_anchor_point |
Get an anchor point of geometry primitives. |
get_primitives_angle |
Get the border point at a given angle. |
get_primitives_border |
Get the border point of geometry primitives in a given direction. |
get_transformation_for_frame |
Get transformation for a frame defined by origin and axes. |
Bbox
dataclass
Bbox(position: Point, width: float, height: float)
Bases: object
Represents a bounding box.
Attributes:
| Name | Type | Description |
|---|---|---|
position |
Point
|
Center point. |
width |
float
|
Width of the box. |
height |
float
|
Height of the box. |
Examples:
Methods:
| Name | Description |
|---|---|
anchor_point |
Get a named anchor point. |
around_points |
Create a minimal Bbox enclosing all given points. |
center |
Get the center point. |
east |
Get the east (right center) point. |
east_north_east |
Get the east-north-east point. |
east_south_east |
Get the east-south-east point. |
isnan |
Check if the position has NaN coordinates. |
north |
Get the north (top center) point. |
north_east |
Get the north-east corner. |
north_north_east |
Get the north-north-east point. |
north_north_west |
Get the north-north-west point. |
north_west |
Get the north-west corner. |
size |
Get the size as (width, height). |
south |
Get the south (bottom center) point. |
south_east |
Get the south-east corner. |
south_south_east |
Get the south-south-east point. |
south_south_west |
Get the south-south-west point. |
south_west |
Get the south-west corner. |
union |
Create a Bbox enclosing all given bounding boxes. |
west |
Get the west (left center) point. |
west_north_west |
Get the west-north-west point. |
west_south_west |
Get the west-south-west point. |
anchor_point
anchor_point(anchor_point: str) -> Point
Get a named anchor point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anchor_point
|
str
|
Name like 'north', 'south_east', 'center', etc. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The anchor point. |
Source code in src/momapy/geometry.py
around_points
classmethod
Create a minimal Bbox enclosing all given points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
Iterable[Point]
|
An iterable of Point objects. |
required |
Returns:
| Type | Description |
|---|---|
Bbox
|
A new Bbox that tightly encloses all input points. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the iterable is empty. |
Source code in src/momapy/geometry.py
center
center() -> Point
east
east() -> Point
east_north_east
east_north_east() -> Point
east_south_east
east_south_east() -> Point
isnan
Check if the position has NaN coordinates.
Returns:
| Type | Description |
|---|---|
bool
|
True if position has NaN. |
north
north() -> Point
north_east
north_east() -> Point
north_north_east
north_north_east() -> Point
north_north_west
north_north_west() -> Point
north_west
north_west() -> Point
size
Get the size as (width, height).
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (width, height). |
south
south() -> Point
south_east
south_east() -> Point
south_south_east
south_south_east() -> Point
south_south_west
south_south_west() -> Point
south_west
south_west() -> Point
union
classmethod
Create a Bbox enclosing all given bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bboxes
|
list[Bbox]
|
List of Bbox objects to merge. |
required |
Returns:
| Type | Description |
|---|---|
Bbox
|
A new Bbox enclosing all input bboxes. |
Source code in src/momapy/geometry.py
west
west() -> Point
west_north_west
west_north_west() -> Point
west_south_west
west_south_west() -> Point
CubicBezierCurve
dataclass
Bases: GeometryObject
Represents a cubic Bezier curve.
Attributes:
| Name | Type | Description |
|---|---|---|
p1 |
Point
|
Start point. |
p2 |
Point
|
End point. |
control_point1 |
Point
|
First control point. |
control_point2 |
Point
|
Second control point. |
Examples:
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box of the curve. |
derivative |
Compute the derivative at parameter t. |
evaluate |
Evaluate the curve at parameter t. |
evaluate_multi |
Evaluate the curve at multiple parameters. |
get_angle_at_fraction |
Get angle at a fraction of the arc length. |
get_intersection_with_line |
Get intersection with a line. |
get_position_and_angle_at_fraction |
Get both position and angle at a fraction of the arc length. |
get_position_at_fraction |
Get point at a fraction of the arc length. |
length |
Calculate the arc length of the curve. |
reversed |
Return a reversed copy of the curve. |
shortened |
Return a shortened copy of the curve. |
split |
Split the curve at parameter t using De Casteljau subdivision. |
transformed |
Apply a transformation to this curve. |
bbox
bbox() -> Bbox
Get the bounding box of the curve.
Returns:
| Type | Description |
|---|---|
Bbox
|
A Bbox enclosing the curve. |
Source code in src/momapy/geometry.py
derivative
Compute the derivative at parameter t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (dx/dt, dy/dt). |
Source code in src/momapy/geometry.py
evaluate
evaluate(t: float) -> Point
Evaluate the curve at parameter t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The point at parameter t. |
evaluate_multi
evaluate_multi(t_sequence: Sequence[float]) -> list[Point]
Evaluate the curve at multiple parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_sequence
|
Sequence[float]
|
Sequence of parameter values. |
required |
Returns:
| Type | Description |
|---|---|
list[Point]
|
List of points. |
Source code in src/momapy/geometry.py
get_angle_at_fraction
Get angle at a fraction of the arc length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle in radians. |
Source code in src/momapy/geometry.py
get_intersection_with_line
Get intersection with a line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The line to intersect with. |
required |
Returns:
| Type | Description |
|---|---|
list[Point] | list[Segment]
|
List of intersection points or segments. |
Source code in src/momapy/geometry.py
get_position_and_angle_at_fraction
get_position_and_angle_at_fraction(fraction: float) -> tuple[Point, float]
Get both position and angle at a fraction of the arc length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Point, float]
|
Tuple of (point, angle_in_radians). |
Source code in src/momapy/geometry.py
get_position_at_fraction
get_position_at_fraction(fraction: float) -> Point
Get point at a fraction of the arc length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The point at that fraction. |
Source code in src/momapy/geometry.py
length
Calculate the arc length of the curve.
Returns:
| Type | Description |
|---|---|
float
|
The arc length. |
reversed
reversed() -> CubicBezierCurve
Return a reversed copy of the curve.
Returns:
| Type | Description |
|---|---|
CubicBezierCurve
|
A new CubicBezierCurve going in reverse direction. |
Source code in src/momapy/geometry.py
shortened
shortened(length: float, start_or_end: Literal['start', 'end'] = 'end') -> CubicBezierCurve
Return a shortened copy of the curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
Amount to shorten by. |
required |
start_or_end
|
Literal['start', 'end']
|
Which end to shorten from. |
'end'
|
Returns:
| Type | Description |
|---|---|
CubicBezierCurve
|
A new shortened CubicBezierCurve. |
Source code in src/momapy/geometry.py
split
split(t: float) -> tuple[CubicBezierCurve, CubicBezierCurve]
Split the curve at parameter t using De Casteljau subdivision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[CubicBezierCurve, CubicBezierCurve]
|
Tuple of two CubicBezierCurves. |
Source code in src/momapy/geometry.py
transformed
transformed(transformation) -> CubicBezierCurve
Apply a transformation to this curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
The transformation to apply. |
required |
Returns:
| Type | Description |
|---|---|
CubicBezierCurve
|
A new transformed CubicBezierCurve. |
Source code in src/momapy/geometry.py
EllipticalArc
dataclass
EllipticalArc(p1: Point, p2: Point, rx: float, ry: float, x_axis_rotation: float, arc_flag: int, sweep_flag: int)
Bases: GeometryObject
Represents an elliptical arc.
Attributes:
| Name | Type | Description |
|---|---|---|
p1 |
Point
|
Start point. |
p2 |
Point
|
End point. |
rx |
float
|
X-radius of the ellipse. |
ry |
float
|
Y-radius of the ellipse. |
x_axis_rotation |
float
|
Rotation of the x-axis in radians. |
arc_flag |
int
|
Large arc flag (0 or 1). |
sweep_flag |
int
|
Sweep flag (0 or 1). |
Examples:
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box of the arc. |
derivative |
Compute the derivative of the arc at parameter t. |
evaluate |
Evaluate the arc at parameter t using center parameterization. |
get_angle_at_fraction |
Get angle at a fraction along the arc. |
get_center |
Get the center point of the ellipse. |
get_center_parameterization |
Get the center parameterization of the arc. |
get_intersection_with_line |
Get intersection with a line. |
get_position_and_angle_at_fraction |
Get both position and angle at a fraction. |
get_position_at_fraction |
Get point at a fraction along the arc. |
length |
Calculate the length of the arc. |
reversed |
Return a reversed copy of the arc. |
shortened |
Return a shortened copy of the arc. |
transformed |
Apply a transformation to this arc. |
bbox
bbox() -> Bbox
Get the bounding box of the arc.
Returns:
| Type | Description |
|---|---|
Bbox
|
A Bbox enclosing the arc. |
Source code in src/momapy/geometry.py
derivative
Compute the derivative of the arc at parameter t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (dx, dy) derivatives. |
Source code in src/momapy/geometry.py
evaluate
evaluate(t: float) -> Point
Evaluate the arc at parameter t using center parameterization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The point at parameter t. |
Source code in src/momapy/geometry.py
get_angle_at_fraction
Get angle at a fraction along the arc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle in radians. |
Source code in src/momapy/geometry.py
get_center
get_center() -> Point
get_center_parameterization
Get the center parameterization of the arc.
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, float, float, float, float, float]
|
Tuple of (cx, cy, rx, ry, sigma, theta1, theta2, delta_theta). |
Source code in src/momapy/geometry.py
get_intersection_with_line
Get intersection with a line.
Uses analytical ellipse-line intersection by solving Acos(theta) + Bsin(theta) + C = 0 via atan2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The line to intersect with. |
required |
Returns:
| Type | Description |
|---|---|
list[Point]
|
List of intersection points. |
Source code in src/momapy/geometry.py
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 | |
get_position_and_angle_at_fraction
get_position_and_angle_at_fraction(fraction: float) -> tuple[Point, float]
Get both position and angle at a fraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Point, float]
|
Tuple of (point, angle). |
Source code in src/momapy/geometry.py
get_position_at_fraction
get_position_at_fraction(fraction: float) -> Point
Get point at a fraction along the arc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The point at that fraction. |
Source code in src/momapy/geometry.py
length
reversed
reversed() -> EllipticalArc
Return a reversed copy of the arc.
Returns:
| Type | Description |
|---|---|
EllipticalArc
|
A new EllipticalArc going in reverse direction. |
Source code in src/momapy/geometry.py
shortened
shortened(length: float, start_or_end: Literal['start', 'end'] = 'end') -> EllipticalArc
Return a shortened copy of the arc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
Amount to shorten by. |
required |
start_or_end
|
Literal['start', 'end']
|
Which end to shorten from. |
'end'
|
Returns:
| Type | Description |
|---|---|
EllipticalArc
|
A new shortened EllipticalArc. |
Source code in src/momapy/geometry.py
transformed
transformed(transformation: Transformation) -> EllipticalArc
Apply a transformation to this arc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation to apply. |
required |
Returns:
| Type | Description |
|---|---|
EllipticalArc
|
A new transformed EllipticalArc. |
Source code in src/momapy/geometry.py
Line
dataclass
Bases: GeometryObject
Represents an infinite line defined by two points.
Attributes:
| Name | Type | Description |
|---|---|---|
p1 |
Point
|
First point on the line. |
p2 |
Point
|
Second point on the line. |
Examples:
Methods:
| Name | Description |
|---|---|
get_angle_to_horizontal |
Get the angle of the line relative to horizontal. |
get_distance_to_point |
Get perpendicular distance from a point to this line. |
get_intersection_with_line |
Get intersection with another line. |
has_point |
Check if a point lies on this line. |
intercept |
Calculate the y-intercept of the line. |
is_coincident_to_line |
Check if this line is coincident with another. |
is_parallel_to_line |
Check if this line is parallel to another. |
reversed |
Return a reversed copy of the line. |
slope |
Calculate the slope of the line. |
transformed |
Apply a transformation to this line. |
get_angle_to_horizontal
Get the angle of the line relative to horizontal.
Returns:
| Type | Description |
|---|---|
float
|
Angle in radians. |
get_distance_to_point
get_distance_to_point(point: Point) -> float
Get perpendicular distance from a point to this line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point to measure from. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The perpendicular distance. |
Source code in src/momapy/geometry.py
get_intersection_with_line
Get intersection with another line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The other line. |
required |
Returns:
| Type | Description |
|---|---|
list[Line] | list[Point]
|
List containing intersection point(s) or the coincident line. |
Source code in src/momapy/geometry.py
has_point
has_point(point: Point, max_distance: float = ROUNDING_TOLERANCE) -> bool
Check if a point lies on this line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point to check. |
required |
max_distance
|
float
|
Maximum allowed distance from line. |
ROUNDING_TOLERANCE
|
Returns:
| Type | Description |
|---|---|
bool
|
True if point is on the line within tolerance. |
Source code in src/momapy/geometry.py
intercept
Calculate the y-intercept of the line.
Returns:
| Type | Description |
|---|---|
float
|
The y-intercept, or NaN if vertical. |
Source code in src/momapy/geometry.py
is_coincident_to_line
is_coincident_to_line(line: Line) -> bool
Check if this line is coincident with another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The other line. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if coincident (same infinite line). |
Source code in src/momapy/geometry.py
is_parallel_to_line
is_parallel_to_line(line: Line) -> bool
Check if this line is parallel to another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The other line. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if parallel. |
Source code in src/momapy/geometry.py
reversed
reversed() -> Line
Return a reversed copy of the line.
Returns:
| Type | Description |
|---|---|
Line
|
A new Line with p1 and p2 swapped. |
slope
Calculate the slope of the line.
Returns:
| Type | Description |
|---|---|
float
|
The slope, or NaN if vertical. |
transformed
transformed(transformation: Transformation) -> Line
Apply a transformation to this line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation to apply. |
required |
Returns:
| Type | Description |
|---|---|
Line
|
A new transformed Line. |
Source code in src/momapy/geometry.py
MatrixTransformation
dataclass
Bases: Transformation
Represents a transformation as a 3x3 matrix.
Attributes:
| Name | Type | Description |
|---|---|---|
m |
NDArray
|
The 3x3 transformation matrix. |
Methods:
| Name | Description |
|---|---|
inverted |
Get the inverse transformation. |
to_matrix |
Get the matrix representation. |
inverted
inverted() -> Transformation
Get the inverse transformation.
Returns:
| Type | Description |
|---|---|
Transformation
|
The inverse matrix transformation. |
to_matrix
Point
dataclass
Bases: GeometryObject
Represents a 2D point with x and y coordinates.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
float
|
The x-coordinate. |
y |
float
|
The y-coordinate. |
Examples:
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box of this point. |
from_tuple |
Create a Point from a tuple. |
get_angle_to_horizontal |
Get the angle from origin to this point relative to horizontal. |
get_intersection_with_line |
Get intersection points with a line. |
isnan |
Check if either coordinate is NaN. |
reversed |
Return a reversed copy (identity for points). |
round |
Round coordinates to specified digits. |
to_matrix |
Convert to a 3x1 numpy matrix for transformation operations. |
to_tuple |
Convert to a tuple. |
transformed |
Apply a transformation to this point. |
bbox
bbox() -> Bbox
Get the bounding box of this point.
Returns:
| Type | Description |
|---|---|
Bbox
|
A Bbox with zero width and height. |
from_tuple
classmethod
Create a Point from a tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
tuple[float, float]
|
Tuple (x, y). |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new Point. |
get_angle_to_horizontal
Get the angle from origin to this point relative to horizontal.
Returns:
| Type | Description |
|---|---|
float
|
Angle in radians. |
get_intersection_with_line
isnan
Check if either coordinate is NaN.
Returns:
| Type | Description |
|---|---|
bool
|
True if x or y is NaN. |
reversed
reversed() -> Point
round
Round coordinates to specified digits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ndigits
|
Number of decimal places. |
None
|
Returns:
| Type | Description |
|---|---|
|
A new Point with rounded coordinates. |
Source code in src/momapy/geometry.py
to_matrix
Convert to a 3x1 numpy matrix for transformation operations.
Returns:
| Type | Description |
|---|---|
ndarray
|
A numpy array [[x], [y], [1]]. |
to_tuple
transformed
transformed(transformation: Transformation) -> Point
Apply a transformation to this point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation to apply. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A new transformed Point. |
Source code in src/momapy/geometry.py
QuadraticBezierCurve
dataclass
Bases: GeometryObject
Represents a quadratic Bezier curve.
Attributes:
| Name | Type | Description |
|---|---|---|
p1 |
Point
|
Start point. |
p2 |
Point
|
End point. |
control_point |
Point
|
The single control point. |
Examples:
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box of the curve. |
derivative |
Compute the derivative at parameter t. |
evaluate |
Evaluate the curve at parameter t. |
evaluate_multi |
Evaluate the curve at multiple parameters. |
get_angle_at_fraction |
Get angle at a fraction of the arc length. |
get_intersection_with_line |
Get intersection with a line. |
get_position_and_angle_at_fraction |
Get both position and angle at a fraction of the arc length. |
get_position_at_fraction |
Get point at a fraction of the arc length. |
length |
Calculate the arc length of the curve. |
reversed |
Return a reversed copy of the curve. |
shortened |
Return a shortened copy of the curve. |
split |
Split the curve at parameter t using De Casteljau subdivision. |
transformed |
Apply a transformation to this curve. |
bbox
bbox() -> Bbox
Get the bounding box of the curve.
Returns:
| Type | Description |
|---|---|
Bbox
|
A Bbox enclosing the curve. |
Source code in src/momapy/geometry.py
derivative
Compute the derivative at parameter t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (dx/dt, dy/dt). |
Source code in src/momapy/geometry.py
evaluate
evaluate(t: float) -> Point
Evaluate the curve at parameter t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The point at parameter t. |
evaluate_multi
evaluate_multi(t_sequence: Sequence[float]) -> list[Point]
Evaluate the curve at multiple parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_sequence
|
Sequence[float]
|
Sequence of parameter values. |
required |
Returns:
| Type | Description |
|---|---|
list[Point]
|
List of points. |
Source code in src/momapy/geometry.py
get_angle_at_fraction
Get angle at a fraction of the arc length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle in radians. |
Source code in src/momapy/geometry.py
get_intersection_with_line
Get intersection with a line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The line to intersect with. |
required |
Returns:
| Type | Description |
|---|---|
list[Point] | list[Segment]
|
List of intersection points or segments. |
Source code in src/momapy/geometry.py
get_position_and_angle_at_fraction
get_position_and_angle_at_fraction(fraction: float) -> tuple[Point, float]
Get both position and angle at a fraction of the arc length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Point, float]
|
Tuple of (point, angle_in_radians). |
Source code in src/momapy/geometry.py
get_position_at_fraction
get_position_at_fraction(fraction: float) -> Point
Get point at a fraction of the arc length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The point at that fraction. |
Source code in src/momapy/geometry.py
length
reversed
reversed() -> QuadraticBezierCurve
Return a reversed copy of the curve.
Returns:
| Type | Description |
|---|---|
QuadraticBezierCurve
|
A new QuadraticBezierCurve going in reverse direction. |
shortened
shortened(length: float, start_or_end: Literal['start', 'end'] = 'end') -> QuadraticBezierCurve
Return a shortened copy of the curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
Amount to shorten by. |
required |
start_or_end
|
Literal['start', 'end']
|
Which end to shorten from. |
'end'
|
Returns:
| Type | Description |
|---|---|
QuadraticBezierCurve
|
A new shortened QuadraticBezierCurve. |
Source code in src/momapy/geometry.py
split
split(t: float) -> tuple[QuadraticBezierCurve, QuadraticBezierCurve]
Split the curve at parameter t using De Casteljau subdivision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
float
|
Parameter value from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[QuadraticBezierCurve, QuadraticBezierCurve]
|
Tuple of two QuadraticBezierCurves. |
Source code in src/momapy/geometry.py
transformed
transformed(transformation) -> QuadraticBezierCurve
Apply a transformation to this curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
The transformation to apply. |
required |
Returns:
| Type | Description |
|---|---|
QuadraticBezierCurve
|
A new transformed QuadraticBezierCurve. |
Source code in src/momapy/geometry.py
Rotation
dataclass
Rotation(angle: float, point: Point | None = None)
Bases: Transformation
Represents a rotation transformation.
Attributes:
| Name | Type | Description |
|---|---|---|
angle |
float
|
Rotation angle in radians. |
point |
Point | None
|
Optional center of rotation (defaults to origin). |
Examples:
Methods:
| Name | Description |
|---|---|
inverted |
Get the inverse rotation. |
to_matrix |
Convert to a rotation matrix. |
inverted
inverted() -> Transformation
Get the inverse rotation.
Returns:
| Type | Description |
|---|---|
Transformation
|
A rotation by the negative angle. |
to_matrix
Convert to a rotation matrix.
Returns:
| Type | Description |
|---|---|
NDArray
|
A 3x3 rotation matrix. |
Source code in src/momapy/geometry.py
Scaling
dataclass
Bases: Transformation
Represents a scaling transformation.
Attributes:
| Name | Type | Description |
|---|---|---|
sx |
float
|
Scale factor in x direction. |
sy |
float
|
Scale factor in y direction. |
Examples:
Methods:
| Name | Description |
|---|---|
inverted |
Get the inverse scaling. |
to_matrix |
Convert to a scaling matrix. |
inverted
inverted() -> Transformation
to_matrix
Convert to a scaling matrix.
Returns:
| Type | Description |
|---|---|
NDArray
|
A 3x3 scaling matrix. |
Source code in src/momapy/geometry.py
Segment
dataclass
Bases: GeometryObject
Represents a line segment between two points.
Attributes:
| Name | Type | Description |
|---|---|---|
p1 |
Point
|
Start point. |
p2 |
Point
|
End point. |
Examples:
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box of the segment. |
get_angle_at_fraction |
Get angle at a fraction along the segment. |
get_angle_to_horizontal |
Get the angle of the segment relative to horizontal. |
get_distance_to_point |
Get shortest distance from a point to this segment. |
get_intersection_with_line |
Get intersection with a line. |
get_position_and_angle_at_fraction |
Get both position and angle at a fraction. |
get_position_at_fraction |
Get point at a fraction along the segment. |
has_point |
Check if a point lies on this segment. |
length |
Calculate the length of the segment. |
reversed |
Return a reversed copy of the segment. |
shortened |
Return a shortened copy of the segment. |
transformed |
Apply a transformation to this segment. |
bbox
bbox() -> Bbox
get_angle_at_fraction
Get angle at a fraction along the segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle in radians. |
get_angle_to_horizontal
Get the angle of the segment relative to horizontal.
Returns:
| Type | Description |
|---|---|
float
|
Angle in radians. |
get_distance_to_point
get_distance_to_point(point: Point) -> float
Get shortest distance from a point to this segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point to measure from. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The shortest distance. |
Source code in src/momapy/geometry.py
get_intersection_with_line
Get intersection with a line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Line
|
The line to intersect with. |
required |
Returns:
| Type | Description |
|---|---|
list[Point] | list[Segment]
|
List of intersection points or segment if coincident. |
Source code in src/momapy/geometry.py
get_position_and_angle_at_fraction
get_position_and_angle_at_fraction(fraction: float) -> tuple[Point, float]
Get both position and angle at a fraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Point, float]
|
Tuple of (point, angle in radians). |
Source code in src/momapy/geometry.py
get_position_at_fraction
get_position_at_fraction(fraction: float) -> Point
Get point at a fraction along the segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fraction
|
float
|
Fraction from 0 to 1 (0 = start, 1 = end). |
required |
Returns:
| Type | Description |
|---|---|
Point
|
The point at that fraction. |
Source code in src/momapy/geometry.py
has_point
has_point(point: Point, max_distance: float = ROUNDING_TOLERANCE) -> bool
Check if a point lies on this segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point to check. |
required |
max_distance
|
float
|
Maximum allowed distance. |
ROUNDING_TOLERANCE
|
Returns:
| Type | Description |
|---|---|
bool
|
True if point is on the segment within tolerance. |
Source code in src/momapy/geometry.py
length
Calculate the length of the segment.
Returns:
| Type | Description |
|---|---|
float
|
The Euclidean length. |
reversed
reversed() -> Segment
Return a reversed copy of the segment.
Returns:
| Type | Description |
|---|---|
Segment
|
A new Segment with p1 and p2 swapped. |
shortened
shortened(length: float, start_or_end: Literal['start', 'end'] = 'end') -> Segment
Return a shortened copy of the segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
Amount to shorten by. |
required |
start_or_end
|
Literal['start', 'end']
|
Which end to shorten from. |
'end'
|
Returns:
| Type | Description |
|---|---|
Segment
|
A new shortened Segment. |
Source code in src/momapy/geometry.py
transformed
transformed(transformation: Transformation) -> Segment
Apply a transformation to this segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation to apply. |
required |
Returns:
| Type | Description |
|---|---|
Segment
|
A new transformed Segment. |
Source code in src/momapy/geometry.py
Transformation
dataclass
Bases: ABC
Abstract base class for geometric transformations.
Methods:
| Name | Description |
|---|---|
inverted |
Get the inverse transformation. |
to_matrix |
Convert to a 3x3 transformation matrix. |
inverted
abstractmethod
inverted() -> Transformation
Get the inverse transformation.
Returns:
| Type | Description |
|---|---|
Transformation
|
The inverse transformation. |
to_matrix
abstractmethod
Convert to a 3x3 transformation matrix.
Returns:
| Type | Description |
|---|---|
NDArray
|
A 3x3 numpy array. |
Translation
dataclass
Bases: Transformation
Represents a translation transformation.
Attributes:
| Name | Type | Description |
|---|---|---|
tx |
float
|
Translation in x direction. |
ty |
float
|
Translation in y direction. |
Examples:
Methods:
| Name | Description |
|---|---|
inverted |
Get the inverse translation. |
to_matrix |
Convert to a translation matrix. |
inverted
inverted() -> Transformation
to_matrix
Convert to a translation matrix.
Returns:
| Type | Description |
|---|---|
NDArray
|
A 3x3 translation matrix. |
get_normalized_angle
Normalize an angle to [0, 2*pi).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
float
|
Angle in radians. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Normalized angle. |
get_primitives_anchor_point
get_primitives_anchor_point(primitives: list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc], anchor_point: str, center: Point | None = None) -> Point | None
Get an anchor point of geometry primitives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitives
|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
List of geometry primitives. |
required |
anchor_point
|
str
|
Name of anchor point. |
required |
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point | None
|
The anchor point or None. |
Source code in src/momapy/geometry.py
get_primitives_angle
get_primitives_angle(primitives: list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc], angle: float, unit: Literal['degrees', 'radians'] = 'degrees', center: Point | None = None) -> Point | None
Get the border point at a given angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitives
|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
List of geometry primitives. |
required |
angle
|
float
|
The angle. |
required |
unit
|
Literal['degrees', 'radians']
|
Unit of angle ('degrees' or 'radians'). |
'degrees'
|
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point | None
|
The border point or None. |
Source code in src/momapy/geometry.py
get_primitives_border
get_primitives_border(primitives: list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc], point: Point, center: Point | None = None) -> Point | None
Get the border point of geometry primitives in a given direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primitives
|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
List of geometry primitives. |
required |
point
|
Point
|
Direction point. |
required |
center
|
Point | None
|
Optional center point. Defaults to bbox center. |
None
|
Returns:
| Type | Description |
|---|---|
Point | None
|
The border point or None. |
Source code in src/momapy/geometry.py
get_transformation_for_frame
get_transformation_for_frame(origin: Point, unit_x: Point, unit_y: Point) -> MatrixTransformation
Get transformation for a frame defined by origin and axes.
Given a frame F defined by its origin, unit x axis vector, and unit y axis vector, returns the transformation that converts points from F coordinates to reference frame coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin
|
Point
|
Origin of the frame. |
required |
unit_x
|
Point
|
Unit x-axis vector. |
required |
unit_y
|
Point
|
Unit y-axis vector. |
required |
Returns:
| Type | Description |
|---|---|
MatrixTransformation
|
The transformation matrix. |