geom2d.arc¶
Basic 2D arc geometry.
|
Two dimensional immutable circular arc segment. |
- class geom2d.arc.Arc(p1: TPoint, p2: TPoint, radius: float, angle: float, center: TPoint | None = None)¶
Two dimensional immutable circular arc segment.
- Parameters:
p1 – Start point.
p2 – End point.
radius – Arc radius.
angle – Arc angle described by p1->center->p2.
center – Optional center of arc. Will be computed if not specified. Default is None.
- property angle: float¶
The central angle (AKA sweep angle) of this arc.
The sign of the angle determines its direction.
- area() float ¶
The area inside the central angle between the arc and the center.
- direction() int ¶
Return -1 if clockwise or 1 if counter-clockwise.
- distance_to_point(p: TPoint, segment: bool = True) float ¶
Distance from this arc to point.
- Parameters:
p – The point to measure distance to
segment – The point normal projection must lie on this the arc segment if True. Default is True.
- Returns:
The minimum distance from this arc segment to the specified point, or -1 if segment is True and the point normal projection does not lie on this arc segment.
- end_tangent_angle() float ¶
The end direction of this arc segment in radians.
This is the angle of a tangent vector at the arc segment’s end point. Value is between -PI and PI.
- static from_endpoints(p1: TPoint, p2: TPoint, radius: float, large_arc: int, sweep_flag: int) Arc | None ¶
Create a circular arc from SVG-style endpoint parameters.
- Parameters:
p1 – The start point of the arc.
p2 – The end point of the arc.
radius – Arc radius.
large_arc – The large arc flag (0 or 1).
sweep_flag – The sweep flag (0 or 1).
- Returns:
An Arc, or None if the parameters do not describe a valid arc.
- static from_two_points_and_center(p1: TPoint, p2: TPoint, center: TPoint, large_arc: bool = False) Arc | None ¶
Create an Arc given two end points and a center point.
Since this would be ambiguous, a hint must be given as to which way the arc goes using the large_arc flag.
- Parameters:
p1 – Start point.
p2 – End point.
center – Center of arc.
large_arc – If True the Arc will be on the large side (angle > pi). Default is False.
- static from_two_points_and_tangent(p1: TPoint, ptan: TPoint, p2: TPoint, reverse: bool = False) Arc | None ¶
Create an Arc given two points and a tangent vector from p1->ptan.
- Parameters:
p1 – Start point.
ptan – Tangent vector with origin at p1.
p2 – End point.
reverse – Reverse the resulting arc direction if True. Default is False.
- Returns:
An Arc or None if the arc parameters are degenerate (i.e. if the endpoints are coincident or the start point and tangent vector are coincident.)
- height() float ¶
The distance between the chord midpoint and the arc midpoint.
Essentially the Hausdorff distance between the chord and the arc.
- intersect_arc(arc: Arc, on_arc: bool = False) list[P] ¶
The intersection (if any) of this Arc and another Arc.
- Parameters:
arc – An Arc.
on_arc – If True the intersection(s) must lie on both arc segments, otherwise the arcs are treated as circles for purposes of computing the intersections. Default is False.
- Returns:
A list containing zero, one, or two intersections.
- intersect_line(line: Line, on_arc: bool = False, on_line: bool = False) list[P] ¶
Find the intersection (if any) of this Arc and a Line.
- Parameters:
line – A line defined by two points (as a 2-tuple of 2-tuples).
on_arc – If True the intersection(s) must lie on the arc between the two end points. Default is False.
on_line – If True the intersection(s) must lie on the line segment between its two end points. Default is False.
- Returns:
A list containing zero, one, or two intersections as point (x, y) tuples.
- is_clockwise() bool ¶
True if arc direction is clockwise from first point to end point.
- property large_arc_flag: int¶
SVG large arc flag (0, 1).
- length() float ¶
The length of this arc segment.
- mu(p: TPoint) float ¶
Unit distance from first point to point on arc.
The unit distance from the first point of this arc segment to the specified point on the arc segment.
- Parameters:
p – A point on this arc segment.
- Returns:
The unit distance mu where mu >=0 and <= 1.0. If p is does not lie on this arc segment mu may be < 0 or > 1.
- normal_projection_point(p: TPoint, segment: bool = False) P | None ¶
Normal projection of point p to this arc.
- offset(distance: float, preserve_center: bool = True) Arc ¶
Return a copy of this Arc that is offset by distance.
If offset is < 0 the offset line will be towards the center otherwise to the other side of this arc. The central angle will be preserved.
- Parameters:
distance – The distance to offset the line by.
preserve_center – If True the offset arc will have the same center point as this one. Default is True.
- Returns:
An Arc offset by distance from this one.
- point_at(mu: float) P ¶
Point on arc at given unit distance.
- Parameters:
mu – Unit distance along central arc from first point.
- Returns:
mu: along this arc from the start point.
- Return type:
The point at unit distance
- point_at_angle(angle: float, segment: bool = False) P | None ¶
Get a point on this arc given an angle.
- Parameters:
angle – A central angle from start point.
segment – The point must lie on the arc segment if True. Default is False.
- Returns:
The point on this arc given the specified angle from the start point of the arc segment. If
segment
is True and the point would lie outside the arc segment then None. Otherwise, if angle is negative return the first point, or if angle is greater than the central angle then return the end point.
- point_inside(p: TPoint) bool ¶
Test if point is inside the sector defined by this arc.
- Parameters:
p – Point (x, y) to test.
- Returns:
True if the point is inside the sector, otherwise False.
- point_on_arc(p: TPoint) bool ¶
Determine if a point lies on this arc.
- Parameters:
p – Point to test.
- Returns:
True if the point lies on this arc, otherwise False.
- property radius: float¶
The radius of the arc.
- segment_area() float ¶
The area of the arc and a straight line.
The area of the shape limited by the arc and a straight line forming a chord between the two end points.
- start_angle() float ¶
The angle from the arc center between the x axis and the first point.
- start_tangent_angle() float ¶
The start direction of this arc segment in radians.
This is the angle of a tangent vector at the arc segment’s first point. Unlike a chord tangent angle this angle is from the x axis. Value is between -PI and PI.
- subdivide(mu: float) tuple[Arc, Arc] | tuple[Arc] ¶
Subdivide this arc at unit distance :mu: from the start point.
- Parameters:
mu – Unit distance along central arc from first point, where EPSILON < mu < 1.
- Returns:
A tuple containing one or two Arc objects. If mu is out of range (ie. EPSILON >= mu >= 1) a ValueError raised.
- subdivide_at_angle(angle: float) tuple[Arc, Arc] | tuple[Arc] ¶
Split this arc into two arcs at angle.
At the point on this arc given by the specified positive arc angle (0-2pi) from the start point. The angle is relative to the angle of the first point.
- Parameters:
angle – A central angle the arc start point, in radians.
- Returns:
A tuple containing one or two Arc objects. If the angle is zero or greater than this arc’s angle then a tuple containing just this arc will be returned.
- subdivide_at_point(p: TPoint) tuple[Arc, Arc] | tuple[Arc] ¶
Split this arc into two arcs at the specified point.
- Parameters:
p – A point on this arc.
- Returns:
A tuple containing one or two Arc objects.
- property sweep_flag: int¶
SVG sweep flag (0, 1).
- to_svg_path(scale: float = 1, add_prefix: bool = True, add_move: bool = False) str ¶
Arc to SVG path string.
- Parameters:
scale – Scale factor. Default is 1.
add_prefix – Prefix with the command prefix if True. Default is True.
add_move – Prefix with M command if True. Default is False.
A string with the SVG path ‘d’ attribute values that corresponds to this arc.
- transform(matrix: TMatrix) Arc ¶
Apply transform to this Arc.
- Parameters:
matrix – An affine transform matrix. The arc will remain circular.
- Returns:
A copy of this arc with the transform matrix applied to it.
- which_side_angle(angle: float, inline: bool = False) int ¶
Which side of endpoint tangent is vector.
Determine which side of a line tangent to the end point of this arc lies a vector from the end point with the specified direction angle.
- Parameters:
angle – Angle in radians of the vector
inline – If True return 0 if the point is inline.
- Returns:
1 if the vector direction is to the left of arc tangent else -1. If
inline
is True and the point is inline then 0.
- geom2d.arc.calc_center(p1: TPoint, p2: TPoint, radius: float, angle: float) P ¶
Calculate the center point of an arc from endpoints.
Given two endpoints, the radius, and a central angle.
- Parameters:
p1 – Start point
p2 – End point
radius – Radius of arc
angle – The arc’s central angle
- Returns:
The center point as a tuple (x, y).