Struct Arc2
A directed arc on a circle in 2D space: a curve tracing part of a circle's circumference from a start point to a target point in a specified direction (clockwise or counter-clockwise).
An arc is defined by three things:
- The Circle it lies on.
- A StartDirection — the direction from the circle's centre to the start of the arc.
- An ArcAngle — a signed sweep angle. Positive means counter-clockwise (CCW); negative means clockwise (CW).
From these, all other properties — StartPosition, TargetPosition, ArcLength, and TargetRay — are derived automatically.
Arc2 is a readonly record struct: value-type, immutable,
and equality-by-value.
public readonly record struct Arc2 : IEquatable<Arc2>
- Implements
- Inherited Members
- Extension Methods
Examples
// Quarter-circle arc: unit circle, starting East, sweeping 90° counter-clockwise to North
var arc = new Arc2(
new Circle2(LengthPoint2.Origin, new Radius(Length.FromMeters(1))),
Direction2.East,
Angle.FromDegrees(90));
Length len = arc.ArcLength; // π/2 ≈ 1.5708 m
ArcDirection dir = arc.Direction; // CounterClockwise
// Use PointAt for parametric traversal
var pt = arc.PointAt(Ratio.FromPercent(50)); // Point at 45°
// Use CalculateArcSegments for rendering
IList<LengthSegment2> segments = arc.CalculateArcSegments(8); // 8-segment polyline
Constructors
Arc2(Circle2, Direction2, Angle)
Constructs an Arc2 from a start direction and a signed sweep angle.
public Arc2(Circle2 circle, Direction2 startDirection, Angle arcAngle)
Parameters
circleCircle2The circle the arc lies on.
startDirectionDirection2The direction from the circle centre to the arc's start point.
arcAngleAngleThe signed sweep angle. Positive = counter-clockwise, negative = clockwise. Automatically normalized to (−360°, 360°].
Examples
var circle = new Circle2(LengthPoint2.FromMeters(0, 0), Radius.FromMeters(1));
var arc = new Arc2(circle, Direction2.East, Angle.FromDegrees(90));
// Starts at (R, 0), sweeps 90° CCW, ends at (0, R)
Arc2(Circle2, LengthPoint2, LengthPoint2, ArcDirection)
Constructs an Arc2 from two positions on the circle and an explicit sweep direction.
The arc sweeps from startPosition to targetPosition
in the specified arcDirection. The shorter or longer path is selected
based on the direction: CCW always sweeps the CCW way, even if it is the long way around.
public Arc2(Circle2 circle, LengthPoint2 startPosition, LengthPoint2 targetPosition, ArcDirection arcDirection)
Parameters
circleCircle2The circle the arc lies on.
startPositionLengthPoint2Start point (must be on the circle's circumference).
targetPositionLengthPoint2Target point (must be on the circle's circumference).
arcDirectionArcDirectionThe sweep direction.
Examples
var circle = new Circle2(LengthPoint2.FromMeters(0, 0), Radius.FromMeters(1));
var start = LengthPoint2.FromMeters(1, 0); // East
var target = LengthPoint2.FromMeters(0, 1); // North
var arc = new Arc2(circle, start, target, ArcDirection.CounterClockwise); // 90° CCW
Arc2(Circle2, LengthPoint2, Angle)
Constructs an Arc2 from a start position on the circle and a signed sweep angle.
public Arc2(Circle2 circle, LengthPoint2 startPosition, Angle arcAngle)
Parameters
circleCircle2The circle the arc lies on.
startPositionLengthPoint2A point on the circle's circumference where the arc begins.
arcAngleAngleThe signed sweep angle. Positive = counter-clockwise, negative = clockwise.
Examples
var circle = new Circle2(LengthPoint2.FromMeters(0, 0), Radius.FromMeters(1));
var start = LengthPoint2.FromMeters(1, 0); // East on unit circle
var arc = new Arc2(circle, start, Angle.FromDegrees(-90)); // 90° clockwise to South
Properties
ArcAngle
The signed sweep angle of the arc.
Positive values indicate a counter-clockwise sweep; negative values indicate clockwise. The magnitude equals the angle subtended at the centre. Normalised to (−360°, 360°] via NormalizeToSigned(Angle).
public Angle ArcAngle { get; }
Property Value
- Angle
ArcLength
The arc length: the distance along the arc from StartPosition to TargetPosition.
Computed as Radius × |ArcAngle| (in radians). Always non-negative.
public Length ArcLength { get; }
Property Value
- Length
Center
The centre position of this arc (the centre of its underlying circle).
Alias for Circle.Center. Provides the standardised Center
contract shared by all shape types.
public LengthPoint2 Center { get; }
Property Value
Circle
The circle on which this arc lies. The arc's endpoints are on the circumference of this circle.
public Circle2 Circle { get; }
Property Value
Direction
Whether the arc sweeps clockwise or counter-clockwise.
Derived from the sign of ArcAngle: positive → CCW, non-positive → CW.
public ArcDirection Direction { get; }
Property Value
StartDirection
The direction from the circle's centre to the start of the arc.
Multiply by the radius to get StartPosition:
StartPosition = Circle.Center + StartDirection * Circle.Radius.
public Direction2 StartDirection { get; }
Property Value
StartPosition
The point on the circle's circumference where the arc begins.
public LengthPoint2 StartPosition { get; }
Property Value
TargetDirection
The direction from the circle's centre to the end of the arc.
public Direction2 TargetDirection { get; }
Property Value
TargetPosition
The point on the circle's circumference where the arc ends.
public LengthPoint2 TargetPosition { get; }
Property Value
TargetRay
A LengthRay2 tangent to the arc at the target point, pointing in the direction of travel at that endpoint.
For a CCW arc the tangent at the target is 90° CCW from the target radius direction; for a CW arc it is 90° CW. This ray is useful for chaining arcs and tangent lines together (e.g. Dubins paths in robotics).
public LengthRay2 TargetRay { get; }
Property Value
Methods
CalculateArcPoints(int)
Calculates a list of points sampled uniformly along the arc.
Returns segmentCount + 1 points: one at each segment boundary,
starting at StartPosition (t=0) and ending at TargetPosition (t=1).
public IList<LengthPoint2> CalculateArcPoints(int segmentCount)
Parameters
segmentCountintThe number of segments (minimum 1). The returned list will have segmentCount + 1 points.
Returns
- IList<LengthPoint2>
An IList of points sampled uniformly along the arc.
CalculateArcSegments(int?)
Returns a polyline approximation of the arc as a list of LengthSegment2.
When segmentCount is null (the default), the number
of segments is automatically chosen as ⌈ArcLength.Meters⌉ — roughly one segment
per metre, giving a smooth approximation at typical game-world scales.
Pass an explicit count for fine or coarse rendering control.
public IList<LengthSegment2> CalculateArcSegments(int? segmentCount = null)
Parameters
segmentCountint?The number of line segments in the approximation, or null to use the adaptive default (
⌈ArcLength.Meters⌉, minimum 1).
Returns
- IList<LengthSegment2>
A list of LengthSegment2 whose endpoints all lie on the arc's circle. An empty list is returned if the arc has zero length.
Examples
var circle = new Circle2(LengthPoint2.FromMeters(0, 0), Radius.FromMeters(1));
var arc = new Arc2(circle, Direction2.East, Angle.FromDegrees(90));
// Automatic resolution (≈ 2 segments for a π/2 ≈ 1.57 m arc on a 1 m radius circle)
var auto = arc.CalculateArcSegments();
// Explicit 8-segment high-quality approximation
var fine = arc.CalculateArcSegments(8);
FromPoints(Circle2, LengthPoint2, LengthPoint2)
Constructs an Arc2 on the given circle passing through two specified points, selecting the shorter of the two possible arcs.
public static Arc2 FromPoints(Circle2 circle, LengthPoint2 startPoint, LengthPoint2 targetPoint)
Parameters
circleCircle2The circle the arc lies on.
startPointLengthPoint2The start point (must be on the circle's circumference).
targetPointLengthPoint2The target point (must be on the circle's circumference).
Returns
- Arc2
An arc with the shorter angular span connecting the two points.
FromPoints(LengthPoint2, LengthPoint2, LengthPoint2)
Constructs an Arc2 from three points: a start, a through-point, and an end.
The arc passes through all three points in order, and the sweep direction is inferred
automatically from the winding of start → through → end.
If the signed area of the triangle formed by the three points is positive, the winding is counter-clockwise (CCW); if negative, it is clockwise (CW). This eliminates the need to compute a cross-product manually at the call site.
public static Arc2 FromPoints(LengthPoint2 start, LengthPoint2 through, LengthPoint2 end)
Parameters
startLengthPoint2The point where the arc begins.
throughLengthPoint2A point the arc passes through between start and end.
endLengthPoint2The point where the arc ends.
Returns
Examples
var p1 = LengthPoint2.FromMeters(1, 0);
var p2 = LengthPoint2.FromMeters(0, 1);
var p3 = LengthPoint2.FromMeters(-1, 0);
var arc = Arc2.FromPoints(p1, p2, p3);
// arc.Direction == ArcDirection.CounterClockwise
// arc.PointAt(0.5) ≈ (0, 1)
Exceptions
- ArgumentException
Thrown when the three points are collinear (no unique circle passes through them).
GetClosestPoint(LengthPoint2)
Returns the point on the arc (or its endpoints) that is closest to
position.
If the projection of position onto the circle's circumference falls
within the arc's angular span, the closest point is that projection. Otherwise the
closest arc endpoint (start or target) is returned.
public LengthPoint2 GetClosestPoint(LengthPoint2 position)
Parameters
positionLengthPoint2The query point in world space.
Returns
- LengthPoint2
The closest point on or at the ends of the arc.
Examples
var circle = new Circle2(LengthPoint2.FromMeters(0, 0), Radius.FromMeters(1));
var arc = new Arc2(circle, Direction2.East, Angle.FromDegrees(90));
LengthPoint2 closest = arc.GetClosestPoint(LengthPoint2.FromMeters(0.7, 0.7));
// Returns approximately (0.707, 0.707) — the 45° point on the circle
MoveCenterTo(LengthPoint2)
Returns a new Arc2 with its centre moved to
newCenter, preserving all other properties.
public Arc2 MoveCenterTo(LengthPoint2 newCenter)
Parameters
newCenterLengthPoint2The new centre position.
Returns
Examples
var moved = shape.MoveCenterTo(LengthPoint2.FromMeters(5, 0));
PointAt(double)
Returns the point on the arc at the specified normalized parameter t.
t = 0 returns StartPosition; t = 1 returns
TargetPosition.
public LengthPoint2 PointAt(double t)
Parameters
tdoubleNormalized parameter in [0, 1].
Returns
- LengthPoint2
The point on the arc at that parameter.
PointAt(Ratio)
Returns the point on the arc at the specified normalized parameter t.
t = 0 returns StartPosition; t = 1 returns
TargetPosition. The point is computed by rotating from StartDirection
by ArcAngle * t.
public LengthPoint2 PointAt(Ratio t)
Parameters
tRatioNormalized parameter as a UnitsNet.Ratio (0–1).
Returns
- LengthPoint2
The point on the arc at that parameter.
TangentAt(double)
Returns the forward direction (tangent) of the arc at the specified parameter t.
public Direction2 TangentAt(double t)
Parameters
tdoubleNormalized parameter in [0, 1].
Returns
- Direction2
The unit tangent direction at that point on the arc.
TangentAt(Ratio)
Returns the forward direction (tangent) of the arc at the specified parameter t.
The tangent is perpendicular to the radius at that point, signed by the arc direction: positive (CCW) means 90° counterclockwise from the radius; negative (CW) means 90° clockwise.
public Direction2 TangentAt(Ratio t)
Parameters
tRatioNormalized parameter as a UnitsNet.Ratio (0–1).
Returns
- Direction2
The unit tangent direction at that point on the arc.
Operators
operator +(Arc2, LengthVector2)
Returns a new Arc2 translated by right.
The arc angle and radius are preserved; the circle's centre moves.
public static Arc2 operator +(Arc2 left, LengthVector2 right)
Parameters
leftArc2The arc to translate.
rightLengthVector2The displacement vector.