Geometry
momapy.geometry
Classes and functions for geometry
Classes:
| Name | Description |
|---|---|
Bbox |
Class for bounding boxes |
BezierCurve |
Class for bezier curves |
EllipticalArc |
Class for elliptical arcs |
GeometryObject |
Base class for geometry objects |
Line |
Class for lines |
MatrixTransformation |
Class for matrix transformations |
Point |
Class for points |
Rotation |
Class for rotations |
Scaling |
Class for scalings |
Segment |
Class for segments |
Transformation |
Base class for transformations |
Translation |
Class for translations |
Bbox
dataclass
Bbox(position: Point, width: float, height: float)
Bases: object
Class for bounding boxes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Point
|
|
required |
width
|
float
|
|
required |
height
|
float
|
|
required |
Methods:
| Name | Description |
|---|---|
anchor_point |
Return a given anchor point of the bounding box |
center |
Return the center anchor point of the bounding box |
east |
Return the east anchor point of the bounding box |
east_north_east |
Return the east north east anchor point of the bounding box |
east_south_east |
Return the east south east anchor point of the bounding box |
from_bounds |
Create and return a bounding box from shaply bounds (min_x, min_y, max_x, max_y) |
isnan |
Return |
north |
Return the north anchor point of the bounding box |
north_east |
Return the north east anchor point of the bounding box |
north_north_east |
Return the north north east anchor point of the bounding box |
north_north_west |
Return the north north west anchor point of the bounding box |
north_west |
Return the north west anchor point of the bounding box |
size |
The size of the bounding box |
south |
Return the south anchor point of the bounding box |
south_east |
Return the south east anchor point of the bounding box |
south_south_east |
Return the south south east anchor point of the bounding box |
south_south_west |
Return the south south west anchor point of the bounding box |
south_west |
Return the south west anchor point of the bounding box |
west |
Return the west anchor point of the bounding box |
west_north_west |
Return the west north west anchor point of the bounding box |
west_south_west |
Return the west south west anchor point of the bounding box |
Attributes:
| Name | Type | Description |
|---|---|---|
x |
float
|
The x coordinate of the bounding box |
y |
float
|
The y coordinate of the bounding box |
anchor_point
anchor_point(anchor_point: str) -> Point
center
center() -> Point
east
east() -> Point
east_north_east
east_north_east() -> Point
east_south_east
east_south_east() -> Point
from_bounds
classmethod
Create and return a bounding box from shaply bounds (min_x, min_y, max_x, max_y)
Source code in src/momapy/geometry.py
isnan
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
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
west
west() -> Point
west_north_west
west_north_west() -> Point
west_south_west
west_south_west() -> Point
BezierCurve
dataclass
Bases: GeometryObject
Class for bezier curves
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Point
|
|
required |
p2
|
Point
|
|
required |
control_points
|
tuple[Point, ...]
|
Built-in immutable sequence. If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items. If the argument is a tuple, the return value is the same object. |
<dynamic>
|
Methods:
| Name | Description |
|---|---|
bbox |
Compute and return the bounding box of the bezier curve |
evaluate |
Compute and return the point at a given parameter value |
evaluate_multi |
Compute and return the points at given parameter values |
get_angle_at_fraction |
Compute and return the angle in radians formed by the tangent of the bezier curve and the horizontal at a given fraction (of the total length) |
get_intersection_with_line |
Compute and return the intersection of the bezier curve with a given line |
get_position_and_angle_at_fraction |
Compute and return the position on the bezier curve at a given fraction and the angle in radians formed of the tangent of the bezier curve and the horizontal at that position |
get_position_at_fraction |
Compute and return the position on the bezier curve at a given fraction (of the total length) |
length |
Compute and return the length of the bezier curve |
reversed |
Compute and return a reversed copy of the bezier curve |
shortened |
Compute and return a copy of the bezier curve shortened by a given length |
to_shapely |
Compute and return a shapely line string reproducing the bezier curve |
transformed |
Compute and return a copy of the bezier curve transformed with a given transformation |
bbox
evaluate
evaluate(s: float) -> Point
evaluate_multi
evaluate_multi(s: ndarray) -> list[Point]
Compute and return the points at given parameter values
get_angle_at_fraction
Compute and return the angle in radians formed by the tangent of the bezier curve and the horizontal at a given fraction (of the total length)
Source code in src/momapy/geometry.py
get_intersection_with_line
Compute and return the intersection of the bezier curve with a given line
get_position_and_angle_at_fraction
Compute and return the position on the bezier curve at a given fraction and the angle in radians formed of the tangent of the bezier curve and the horizontal at that position
Source code in src/momapy/geometry.py
get_position_at_fraction
Compute and return the position on the bezier curve at a given fraction (of the total length)
length
reversed
shortened
shortened(
length: float,
start_or_end: Literal["start", "end"] = "end",
) -> BezierCurve
Compute and return a copy of the bezier curve shortened by a given length
Source code in src/momapy/geometry.py
to_shapely
Compute and return a shapely line string reproducing the bezier curve
Source code in src/momapy/geometry.py
transformed
Compute and return a copy of the bezier curve transformed with a given transformation
EllipticalArc
dataclass
EllipticalArc(
p1: Point,
p2: Point,
rx: float,
ry: float,
x_axis_rotation: float,
arc_flag: int,
sweep_flag: int,
)
Bases: GeometryObject
Class for elliptical arcs
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Point
|
|
required |
p2
|
Point
|
|
required |
rx
|
float
|
|
required |
ry
|
float
|
|
required |
x_axis_rotation
|
float
|
|
required |
arc_flag
|
int
|
|
required |
sweep_flag
|
int
|
|
required |
Methods:
| Name | Description |
|---|---|
bbox |
Compute and return the bounding box of the elliptical arc |
get_angle_at_fraction |
Compute and return the angle in radians formed by the tangent of the elliptical arc and the horizontal at a given fraction (of the total length) |
get_center |
Compute and return the center of the elliptical arc |
get_center_parameterization |
Compute and return the center paramaterizaion of the elliptical arc (cx, cy, rx, ry, sigma, theta1, theta2, delta_theta) |
get_intersection_with_line |
Compute and return the intersection of the elliptical arc with a given line |
get_position_and_angle_at_fraction |
Compute and return the position on the elliptical arc at a given fraction and the angle in radians formed of the tangent of the bezier curve at that position and the horizontal |
get_position_at_fraction |
Compute and return the position on the elliptical arc at a given fraction (of the total length) |
reversed |
Compute and return a reversed copy of the elliptical arc |
shortened |
Compute and return a copy of the elliptical arc shortened by a given length |
to_bezier_curves |
Compute and return a bezier curve reproducing the elliptical arc |
to_shapely |
Compute and return a shapely linestring reproducing the elliptical arc |
transformed |
Compute and return a copy of the elliptical arc transformed by a given transformation |
bbox
bbox() -> Bbox
get_angle_at_fraction
Compute and return the angle in radians formed by the tangent of the elliptical arc and the horizontal at a given fraction (of the total length)
Source code in src/momapy/geometry.py
get_center
get_center() -> Point
get_center_parameterization
Compute and return the center paramaterizaion of the elliptical arc (cx, cy, rx, ry, sigma, theta1, theta2, delta_theta)
Source code in src/momapy/geometry.py
get_intersection_with_line
Compute and return the intersection of the elliptical arc with a given line
get_position_and_angle_at_fraction
get_position_and_angle_at_fraction(
fraction: float,
) -> tuple[Point, float]
Compute and return the position on the elliptical arc at a given fraction and the angle in radians formed of the tangent of the bezier curve at that position and the horizontal
Source code in src/momapy/geometry.py
get_position_at_fraction
get_position_at_fraction(fraction: float) -> Point
Compute and return the position on the elliptical arc at a given fraction (of the total length)
reversed
reversed() -> EllipticalArc
shortened
shortened(
length: float,
start_or_end: Literal["start", "end"] = "end",
) -> EllipticalArc
Compute and return a copy of the elliptical arc shortened by a given length
Source code in src/momapy/geometry.py
to_bezier_curves
to_bezier_curves() -> BezierCurve
to_shapely
Compute and return a shapely linestring reproducing the elliptical arc
Source code in src/momapy/geometry.py
transformed
transformed(
transformation: Transformation,
) -> EllipticalArc
Compute and return a copy of the elliptical arc transformed by a given transformation
GeometryObject
dataclass
Bases: ABC
Base class for geometry objects
Methods:
| Name | Description |
|---|---|
to_shapely |
Compute and return a shapely geometry object that reproduces the geometry object |
to_shapely
abstractmethod
Line
dataclass
Bases: GeometryObject
Class for lines
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Point
|
|
required |
p2
|
Point
|
|
required |
Methods:
| Name | Description |
|---|---|
get_angle_to_horizontal |
Return the angle in radians formed by the line and the horizontal |
get_distance_to_point |
Compute and return the distance of a given point to the line |
get_intersection_with_line |
Compute and return the instersection of the line with another given line |
has_point |
Return |
intercept |
Return the intercept of the line |
is_coincident_to_line |
Return |
is_parallel_to_line |
Return |
reversed |
Return a reversed copy of the line |
slope |
Return the slope of the line |
to_shapely |
Return a shapeply line string reproducing the line |
transformed |
Return a copy of the line transformed with the given transformation |
get_angle_to_horizontal
get_distance_to_point
get_distance_to_point(point: Point) -> float
get_intersection_with_line
Compute and return the instersection of the line with another given line
has_point
has_point(point: Point, max_distance: float = 0.01) -> bool
Return true if a given point is on the line, false otherwise
intercept
is_coincident_to_line
is_coincident_to_line(line: Line) -> bool
Return true if the line is coincident to another given line, and false otherwise
is_parallel_to_line
is_parallel_to_line(line: Line) -> bool
Return true if the line is parallel to another given line, and false otherwise
reversed
reversed() -> Line
slope
to_shapely
transformed
transformed(transformation: Transformation) -> Line
Return a copy of the line transformed with the given transformation
MatrixTransformation
dataclass
Bases: Transformation
Class for matrix transformations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
ndarray[tuple[Any, ...], dtype[TypeVar]]
|
|
required |
Methods:
| Name | Description |
|---|---|
inverted |
Compute and return the inverse of the matrix transformation |
to_matrix |
Return a matrix representation of the matrix transformation |
inverted
inverted() -> Transformation
Point
dataclass
Bases: GeometryObject
Class for points
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
|
required |
y
|
float
|
|
required |
Methods:
| Name | Description |
|---|---|
bbox |
Return the bounding box of the point |
from_fortranarray |
Return a point from a numpy fortran array representation |
from_shapely |
Return a point reproducing a given shapely point |
from_tuple |
Return a point from a tuple representation |
get_angle_to_horizontal |
Return the angle in radians formed by the line passing through the origin and the point and the horizontal |
get_intersection_with_line |
Compute and return a list of the intersections of the point and a given line |
isnan |
Return |
reversed |
Return a reversed copy of the point |
to_fortranarray |
Return a numpy fortran array representation of the point |
to_matrix |
Return a |
to_shapely |
Return a shapely point that reproduces the point |
to_tuple |
Return a tuple representation of the point |
transformed |
Return a copy of the the point transformed by the given transformation |
bbox
bbox() -> Bbox
from_fortranarray
classmethod
Return a point from a numpy fortran array representation
from_shapely
classmethod
from_tuple
classmethod
get_angle_to_horizontal
Return the angle in radians formed by the line passing through the origin and the point and the horizontal
get_intersection_with_line
Compute and return a list of the intersections of the point and a given line
isnan
reversed
reversed() -> Point
to_fortranarray
to_matrix
to_shapely
to_tuple
transformed
transformed(transformation: Transformation) -> Point
Return a copy of the the point transformed by the given transformation
Rotation
dataclass
Rotation(angle: float, point: Point | None = None)
Bases: Transformation
Class for rotations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
float
|
|
required |
point
|
Point | None
|
|
None
|
Methods:
| Name | Description |
|---|---|
inverted |
Compute and return the inverse of the rotation |
to_matrix |
Compute and return a matrix representation of the rotation |
inverted
inverted() -> Transformation
to_matrix
Compute and return a matrix representation of the rotation
Source code in src/momapy/geometry.py
Scaling
dataclass
Bases: Transformation
Class for scalings
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sx
|
float
|
|
required |
sy
|
float
|
|
required |
Methods:
| Name | Description |
|---|---|
inverted |
Compute and return the inverse of the scaling |
to_matrix |
Return a matrix representation of the scaling |
inverted
inverted() -> Transformation
to_matrix
Return a matrix representation of the scaling
Segment
dataclass
Bases: GeometryObject
Class for segments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Point
|
|
required |
p2
|
Point
|
|
required |
Methods:
| Name | Description |
|---|---|
bbox |
Compute and return the bounding box of the segment |
from_shapely |
Compute and return the segment reproducing a shapely line string |
get_angle_at_fraction |
Compute and return the angle in radians formed by the segment and the horizontal at a given fraction (of the total length) |
get_angle_to_horizontal |
Compute and return the angle formed by the segment and the horizontal |
get_distance_to_point |
Return the distance of a given point to the segment |
get_intersection_with_line |
Compute and return the intersection of the segment with a given line |
get_position_and_angle_at_fraction |
Compute and return the position on the segment at a given fraction and the angle in radians formed of the segment and the horizontal at that position |
get_position_at_fraction |
Compute and return the position on the segment at a given fraction (of the total length) |
has_point |
Return |
length |
Return the length of the segment |
reversed |
Compute and return a reversed copy of the segment |
shortened |
Compute and return a copy of the segment shortened by a given length |
to_shapely |
Return a shapely line string reproducing the segment |
transformed |
Compute and return a copy of the segment transformed with a given transformation |
bbox
bbox() -> Bbox
from_shapely
classmethod
Compute and return the segment reproducing a shapely line string
Source code in src/momapy/geometry.py
get_angle_at_fraction
Compute and return the angle in radians formed by the segment and the horizontal at a given fraction (of the total length)
get_angle_to_horizontal
get_distance_to_point
get_distance_to_point(point: Point) -> float
get_intersection_with_line
Compute and return the intersection of the segment with a given line
get_position_and_angle_at_fraction
get_position_and_angle_at_fraction(
fraction: float,
) -> tuple[Point, float]
Compute and return the position on the segment at a given fraction and the angle in radians formed of the segment and the horizontal at that position
Source code in src/momapy/geometry.py
get_position_at_fraction
get_position_at_fraction(fraction: float) -> Point
Compute and return the position on the segment at a given fraction (of the total length)
has_point
has_point(point: Point, max_distance: float = 0.01) -> bool
Return true if the given point is on the segment, false otherwise
length
reversed
reversed() -> Segment
shortened
shortened(
length: float,
start_or_end: Literal["start", "end"] = "end",
) -> Segment
Compute and return a copy of the segment shortened by a given length
to_shapely
transformed
transformed(transformation: Transformation) -> Segment
Compute and return a copy of the segment transformed with a given transformation
Transformation
dataclass
Bases: ABC
Base class for transformations
Methods:
| Name | Description |
|---|---|
inverted |
Compute and return the inverse transformation |
to_matrix |
Return a matrix representation of the transformation |
inverted
abstractmethod
inverted() -> Transformation
Translation
dataclass
Bases: Transformation
Class for translations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tx
|
float
|
|
required |
ty
|
float
|
|
required |
Methods:
| Name | Description |
|---|---|
inverted |
Compute and return the inverse of the translation |
to_matrix |
Return a matrix representation of the translation |
inverted
inverted() -> Transformation