Pular para o conteúdo principal

raygeo.geo.shape.circle

Circle geometry queries.

Provides circle-circle and circle-rectangle intersection detection, line-segment-vs-circle intersection points, circle-rectangle full-containment checks, line-segment-vs-circle intersection, and point projection onto a circle's circumference.

Functions

does_circle_intersect_rect()

does_circle_intersect_rect(
center: types.Point,
radius: float,
rect: types.Rect,
) -> bool

Check if a circle intersects a rectangle.

ParameterTypeDescription
centertypes.PointCircle center (x, y).
radiusfloatCircle radius.
recttypes.RectRectangle (x_min, y_min, x_max, y_max).
ReturnsboolTrue if the circle intersects the rectangle.
ComplexityO(1) time, O(1) space

find_tangent_circle_centers()

find_tangent_circle_centers(
pass_through: types.Point,
seg_a: types.Point,
seg_b: types.Point,
radius: float,
) -> list[tuple[types.Point, types.Point]]

Find circle centres that pass through a point and are tangent to a segment.

ParameterTypeDescription
pass_throughtypes.PointPoint the circle must pass through (x, y).
seg_atypes.PointStart of the tangent segment (x, y).
seg_btypes.PointEnd of the tangent segment (x, y).
radiusfloatCircle radius.
Returnslist[tuple[types.Point, types.Point]]List of (centre, tangent_point) pairs.
ComplexityO(1) time, O(1) space

Find circles tangent to a segment through a given point

Find circles tangent to a segment through a given point

get_circle_circle_intersections()

get_circle_circle_intersections(
c1: types.Point,
r1: float,
c2: types.Point,
r2: float,
) -> types.Polygon

Get intersection points of two circles.

ParameterTypeDescription
c1types.PointCenter of first circle (x, y).
r1floatRadius of first circle.
c2types.PointCenter of second circle (x, y).
r2floatRadius of second circle.
Returnstypes.PolygonList of intersection points (x, y).
ComplexityO(1) time, O(1) space

Circle-circle and line-circle intersection points

Circle-circle and line-circle intersection points

get_line_circle_intersections()

get_line_circle_intersections(
p1: types.Point,
p2: types.Point,
center: types.Point,
radius: float,
) -> types.Polygon

Get intersection points of a line segment with a circle.

ParameterTypeDescription
p1types.PointStart point of the line segment (x, y).
p2types.PointEnd point of the line segment (x, y).
centertypes.PointCircle center (x, y).
radiusfloatCircle radius.
Returnstypes.PolygonList of intersection points (x, y).
ComplexityO(1) time, O(1) space

is_circle_inside_rect()

is_circle_inside_rect(
center: types.Point,
radius: float,
rect: types.Rect,
) -> bool

Check if a circle is inside a rectangle.

ParameterTypeDescription
centertypes.PointCircle center (x, y).
radiusfloatCircle radius.
recttypes.RectRectangle (x_min, y_min, x_max, y_max).
ReturnsboolTrue if the circle is fully inside the rectangle.
ComplexityO(1) time, O(1) space

line_segment_intersects_circle()

line_segment_intersects_circle(
p1: types.Point,
p2: types.Point,
circle_center: types.Point,
circle_radius: float,
) -> bool

Check if a line segment intersects a circle.

ParameterTypeDescription
p1types.PointStart point of the line segment (x, y).
p2types.PointEnd point of the line segment (x, y).
circle_centertypes.PointCircle center (x, y).
circle_radiusfloatCircle radius.
ReturnsboolTrue if the line segment intersects the circle.
ComplexityO(1) time, O(1) space

nearest_tangent_circle_on_polyline()

nearest_tangent_circle_on_polyline(
point: types.Point,
polyline: types.Polygon,
radius: float,
from_end: bool,
containment: types.Polygon,
) -> Optional[tuple[types.Point, types.Point, int]]

Find nearest circle through a point tangent to a polyline.

Searches segments of polyline for a circle of radius that passes through point, is tangent to a segment, and has its centre inside containment. Returns the one whose tangent point is closest to the searched end.

ParameterTypeDescription
pointtypes.PointPoint the circle must pass through (x, y).
polylinetypes.PolygonPolyline segments to search.
radiusfloatCircle radius.
from_endboolTrue to search from last vertex; False from first.
containmenttypes.PolygonCentre must be inside this polygon.
ReturnsOptional[tuple[types.Point, types.Point, int]](centre, tangent_point, segment_index) or None.

Nearest tangent circle on a polyline

Nearest tangent circle on a polyline

project_point_onto_circle()

project_point_onto_circle(
point: types.Point,
center: types.Point,
radius: float,
) -> Optional[types.Point]

Project a point onto a circle.

ParameterTypeDescription
pointtypes.PointPoint to project (x, y).
centertypes.PointCircle center (x, y).
radiusfloatCircle radius.
ReturnsOptional[types.Point]Projected point on the circle (x, y).
ComplexityO(1) time, O(1) space