public static bool FromThreePoints(Vector2 a, Vector2 b, Vector2 c, out Circle circle) { Line2D lineA = LineSegment2D.GetBisectorFast(a, b); Line2D lineB = LineSegment2D.GetBisectorFast(b, c); if (Intersect.Lines(lineA, lineB, out circle.center)) { circle.radius = Vector2.Distance(circle.center, a); return(true); } circle = default; return(false); }
public static bool FromPointTangentPoint(Vector2 startPt, Vector2 startTangent, Vector2 endPt, out Circle circle) { Line2D lineA = new Line2D(startPt, startTangent.Rotate90CW()); Line2D lineB = LineSegment2D.GetBisectorFast(startPt, endPt); if (Intersect.Lines(lineA, lineB, out Vector2 pt)) { circle = new Circle(pt, Vector2.Distance(pt, startPt)); return(true); } circle = default; return(false); }
/// <summary>Returns the intersection point of a ray and a line segment (if there is one)</summary> /// <param name="intersectionPoint">The point at which they intersect</param> public static bool RayLineSegment(Ray2D ray, LineSegment2D lineSegment, out Vector2 intersectionPoint) => RayLineSegment(ray.origin, ray.dir, lineSegment.start, lineSegment.end, out intersectionPoint);
/// <summary>Returns the number of intersection points between line segment and a circle</summary> public static int LineSegmentCircle(LineSegment2D lineSegment, Circle circle) => GetLineCircleIntersectionCountFiltered(lineSegment.start, lineSegment.end - lineSegment.start, circle.center, circle.radius, t => BoundsTestLineSegment(t));
/// <summary>Returns whether or not a ray and a line segment intersect</summary> public static bool RayLineSegment(Ray2D ray, LineSegment2D lineSegment) => RayLineSegment(ray.origin, ray.dir, lineSegment.start, lineSegment.end);
/// <summary>Returns the number of intersections and the points at which a line segment and a circle intersect (if they exist)</summary> public static int LineSegmentCircle(LineSegment2D lineSegment, Circle circle, out Vector2 intsctPtA, out Vector2 intsctPtB) => GetLineCircleIntersectionPointsFiltered(lineSegment.start, lineSegment.end - lineSegment.start, circle.center, circle.radius, t => BoundsTestLineSegment(t), out intsctPtA, out intsctPtB);
/// <summary>Returns whether or not a line segment and a line intersect</summary> public static bool LineSegmentLine(LineSegment2D lineSegment, Line2D line) => GetLineLineTValue(line.origin - lineSegment.start, lineSegment.end - lineSegment.start, line.dir, out float tA) && BoundsTestLineSegment(tA);
/// <summary>Returns the intersection point of a line segment and a line (if there is one)</summary> /// <param name="intersectionPoint">The point at which they intersect</param> public static bool LineSegmentLine(LineSegment2D lineSegment, Line2D line, out Vector2 intersectionPoint) => LineSegmentLine(lineSegment.start, lineSegment.end, line.origin, line.dir, out intersectionPoint);
/// <summary>Returns whether or not two line segments intersect</summary> public static bool LineSegments(LineSegment2D a, LineSegment2D b) => LineSegments(a.start, a.end, b.start, b.end);
/// <summary>Returns the intersection point of two line segments (if there is one)</summary> /// <param name="intersectionPoint">The point at which they intersect</param> public static bool LineSegments(LineSegment2D a, LineSegment2D b, out Vector2 intersectionPoint) => LineSegments(a.start, a.end, b.start, b.end, out intersectionPoint);