pygeometry2d
- class pygeometry2d.geometry.Arc(center, radius, start_angle, end_angle)[source]
Bases:
objectA class representing a 2D arc defined by a center, radius, and angles.
- property diameter: float
- is_point_on_edge(point)[source]
Checks if a point lies on the edge of the arc.
- Return type:
bool- Parameters:
point (XY) – The point to check.
- Returns:
True if the point is on the edge, False otherwise.
- Return type:
bool
- property length: float
- class pygeometry2d.geometry.BoundingBox(min_point, max_point)[source]
Bases:
objectA class representing a 2D bounding box defined by two corner points.
- is_point_inside(point)[source]
Checks whether a point lies inside (or on the boundary of) the bounding box, considering a small tolerance defined by _geom_fuzz.
- Return type:
bool- Parameters:
point (XY) – The point to test.
- Returns:
True if the point is inside or on the edges within tolerance.
- Return type:
bool
- class pygeometry2d.geometry.Circle(center, diameter)[source]
Bases:
ArcA class representing a 2D circle, which is a special case of an arc.
- class pygeometry2d.geometry.GeomUtils[source]
Bases:
objectA utility class for geometric operations.
- static angle_to_nearest_orthogonal_angle(angle)[source]
Finds the nearest orthogonal angle to a given angle.
- Return type:
float- Parameters:
angle (float) – The angle in radians.
- Returns:
The nearest orthogonal angle.
- Return type:
float
- static arc_by_3_points(point1, point2, point3)[source]
Computes the arc passing through three points. The points must be in order.
- static circle_by_3_points(point1, point2, point3)[source]
Computes the circle passing through three points.
- static deg_to_rad(angle)[source]
Converts an angle from degrees to radians.
- Return type:
float- Parameters:
angle (float) – The angle in degrees.
- Returns:
The angle in radians.
- Return type:
float
- static get_min_max_point(point_list)[source]
Computes the bounding box of a list of points.
- Return type:
- Parameters:
point_list (list[XY]) – The list of points.
- Returns:
The bounding box.
- Return type:
- static has_same_direction(angle1, angle2)[source]
Checks if two angles have the same direction.
- Return type:
bool- Parameters:
angle1 (float) – The first angle in radians.
angle2 (float) – The second angle in radians.
- Returns:
True if the angles have the same direction, False otherwise.
- Return type:
bool
- static is_horizontal(angle)[source]
Checks if an angle is horizontal.
- Return type:
bool- Parameters:
angle (float) – The angle in radians.
- Returns:
True if the angle is horizontal, False otherwise.
- Return type:
bool
- static is_ortho(angle)[source]
Checks if an angle is either horizontal or vertical.
- Return type:
bool- Parameters:
angle (float) – The angle in radians.
- Returns:
True if the angle is horizontal or vertical, False otherwise.
- Return type:
bool
- static is_vertical(angle)[source]
Checks if an angle is vertical.
- Return type:
bool- Parameters:
angle (float) – The angle in radians.
- Returns:
True if the angle is vertical, False otherwise.
- Return type:
bool
- static normalize_angle(angle)[source]
Normalizes an angle to the range [0, 2π).
- Return type:
float- Parameters:
angle (float) – The angle in radians.
- Returns:
The normalized angle.
- Return type:
float
- class pygeometry2d.geometry.Line(x0, y0, x1=None, y1=None, is_unbound=False)[source]
Bases:
objectA class representing a 2D line segment or an infinite line.
- property angle: float
Returns the normalized angle of the line in radians.
- Returns:
The angle in radians.
- Return type:
float
- distance(point)[source]
Returns the shortest distance from the point to the line.
- Return type:
float- Parameters:
point (XY) – The point to measure the distance from.
- Returns:
The distance from the point to the line.
- Return type:
float
- property general_equation_coefficients: tuple[float, float, float]
Returns the coefficients of the general equation of the line (Ax + By + C = 0).
- Returns:
The coefficients (A, B, C).
- Return type:
tuple[float, float, float]
- has_same_direction(other)[source]
Checks if the line has the same direction as another line or vector.
- intersection(other_line, extend_segments_to_infinity=False)[source]
Finds the intersection point between two lines.
- property inverted_angle: float
Returns the inverted angle of the line in radians.
- Returns:
The inverted angle in radians.
- Return type:
float
- is_consecutive(other_line)[source]
Checks if the end of this line is the start of another line.
- Return type:
bool- Parameters:
other_line (Line) – The other line to check.
- Returns:
True if the lines are consecutive, False otherwise.
- Return type:
bool
- property is_horizontal: bool
Checks if the line is horizontal.
- Returns:
True if the line is horizontal, False otherwise.
- Return type:
bool
- property is_ortho: bool
Checks if the line is either horizontal or vertical.
- Returns:
True if the line is horizontal or vertical, False otherwise.
- Return type:
bool
- is_point_above(point)[source]
Checks if a point is above the line.
- Return type:
bool- Parameters:
point (XY) – The point to check.
- Returns:
True if the point is above the line, False otherwise.
- Return type:
bool
- is_point_in(point)[source]
Checks if a point lies on the line segment.
- Return type:
bool- Parameters:
point (XY) – The point to check.
- Returns:
True if the point is on the line segment, False otherwise.
- Return type:
bool
- property is_vertical: bool
Checks if the line is vertical.
- Returns:
True if the line is vertical, False otherwise.
- Return type:
bool
- property length: float
Returns the length of the line.
- Returns:
The length of the line.
- Return type:
float
- property reduced_equation_coefficients: tuple[float, float]
Returns the coefficients of the reduced equation of the line (y = mx + b).
- Returns:
The coefficients (m, b).
- Return type:
tuple[float, float]
- class pygeometry2d.geometry.Polyline(points)[source]
Bases:
objectA class representing a polyline, which is a sequence of connected line segments.
- property area: float
Returns the absolute area of the polyline.
- Returns:
The absolute area.
- Return type:
float
- enclosing_polyline(offset, end_point_offset=None)[source]
Returns a polyline that encloses the original polyline with a given offset.
- intersection(geometry_object)[source]
Finds the intersection points between the polyline and another geometry object.
- property is_clockwise: bool
Checks if the polyline is oriented clockwise.
- Returns:
True if clockwise, False otherwise.
- Return type:
bool
- property is_closed: bool
Checks if the polyline is closed.
- Returns:
True if the polyline is closed, False otherwise.
- Return type:
bool
- property is_counter_clockwise: bool
Checks if the polyline is oriented counter-clockwise.
- Returns:
True if counter-clockwise, False otherwise.
- Return type:
bool
- is_equivalent(other)[source]
Checks if two polylines are equivalent.
- Return type:
bool- Parameters:
other (Polyline) – The other polyline to compare.
- Returns:
True if the polylines are equivalent, False otherwise.
- Return type:
bool
- is_point_in_edge(point)[source]
Checks if a point lies on any edge of the polyline.
- Return type:
bool- Parameters:
point (XY) – The point to check.
- Returns:
True if the point is on an edge, False otherwise.
- Return type:
bool
- is_point_inside(point)[source]
Checks if a point lies inside or lies on any edge of the polyline.
- Return type:
bool- Parameters:
point (XY) – The point to check.
- Returns:
True if the point is inside, False otherwise.
- Return type:
bool
- is_scaled_equivalent(other)[source]
Checks if two polylines are equivalent after scaling.
- Return type:
bool- Parameters:
other (Polyline) – The other polyline to compare.
- Returns:
True if the polylines are scaled equivalents, False otherwise.
- Return type:
bool
- join(line)[source]
Joins the polyline with another line or polyline. If the ends do not match, return the polyline without modification.
- property length: float
Returns the total length of the polyline.
- Returns:
The total length.
- Return type:
float
- property num_points: int
Returns the number of points in the polyline.
- Returns:
The number of points.
- Return type:
int
- rotated(center, angle)[source]
Returns a copy of the rotated polyline around a center by a given angle.
- scaled(scale_factor, scale_point=None)[source]
Returns a scaled copy of the polyline by a given factor.
- property signed_area: float
Returns the signed area of the polyline.
- Returns:
The signed area.
- Return type:
float
- class pygeometry2d.geometry.Rectangle(corner1, corner2)[source]
Bases:
PolylineA class representing a rectangle, which is a special case of a polyline.
- class pygeometry2d.geometry.XY(x, y)[source]
Bases:
objectA class representing a 2D point or 2D vector with x and y coordinates.
- property angle: float
Returns the normalized angle of the point vector in radians.
- Returns:
The angle in radians.
- Return type:
float
- distance(other_point)[source]
Returns the Euclidean distance between two points.
- Return type:
float- Parameters:
other_point (XY) – The other point.
- Returns:
The distance between the points.
- Return type:
float
- dot_product(v2)[source]
Returns the dot product of two vectors.
- Return type:
float- Parameters:
v2 (XY) – The other vector.
- Returns:
The dot product.
- Return type:
float
- property length: float
Returns the Euclidean length of the point vector.
- Returns:
The length of the vector.
- Return type:
float
- property x: float
- property y: float
- pygeometry2d.geometry.set_precision(decimal_precision)[source]
Sets the global decimal precision for geometric calculations.
- Return type:
None- Parameters:
decimal_precision (int) – The number of decimal places for precision.
- pygeometry2d.geometry.set_temp_precision(decimal_precision)[source]
Temporarily sets the global precision within a context.
- Return type:
Generator[None,None,None]- Parameters:
decimal_precision (int) – The number of decimal places to use within the context.
- Yields:
None – Restores the previous precision after execution.