Class Arc2D
- Namespace
- CADability.Curve2D
- Assembly
- CADability.dll
Describes a circular Arc in 2D. Implements the ICurve2D interface.
public class Arc2D : Circle2D, ICurve2D, IQuadTreeInsertable, ISerializable
- Inheritance
-
Arc2D
- Implements
- Inherited Members
Constructors
Arc2D(GeoPoint2D, double, Angle, SweepAngle)
Constructs a circular arc in 2D.
public Arc2D(GeoPoint2D center, double radius, Angle start, SweepAngle sweep)
Parameters
centerGeoPoint2DCenter of the arc
radiusdoubleRadius of the Arc
startAngleStartangle of the arc (x-axis is 0)
sweepSweepAngleSweepangle of the arc -2pi<=s<=2pi
Arc2D(GeoPoint2D, double, GeoPoint2D, GeoPoint2D, bool)
Constructs a circular arc from its start point to its end point. Only the directions from the center to the points are
used, so the points need not lie exactly on the circle. The arc runs counterclockwise or clockwise as
counterclock says; when the two points coincide, the arc is a full circle in that direction.
public Arc2D(GeoPoint2D center, double radius, GeoPoint2D StartPoint, GeoPoint2D EndPoint, bool counterclock)
Parameters
centerGeoPoint2Dcenter of the arc
radiusdoubleradius of the arc
StartPointGeoPoint2Dstart point (only its direction from the center is used)
EndPointGeoPoint2Dend point (only its direction from the center is used)
counterclockbooltrue for a counterclockwise arc, false for a clockwise arc
Arc2D(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Arc2D(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Properties
EndDirection
The direction of the curve at the end point (see EndDirection). This base implementation returns the normalized direction at the last base point of the triangulation.
public override GeoVector2D EndDirection { get; }
Property Value
EndParameter
The angle of the end point in radians: StartParameter plus the signed sweep angle. It is not normalized, so it may be negative or exceed 2*pi.
public double EndParameter { get; }
Property Value
EndPoint
The end point of the curve (see EndPoint). This base implementation takes it from the last base point of the triangulation; setting it only replaces that base point and leaves the underlying geometry unchanged, which is acceptable for small corrections only. Curves with their own data override it.
public override GeoPoint2D EndPoint { get; set; }
Property Value
IsClosed
Tells whether the curve is closed (see IsClosed). This base implementation tests whether StartPoint and EndPoint coincide according to IsEqual(GeoPoint2D, GeoPoint2D).
public override bool IsClosed { get; }
Property Value
Length
The arc length of the curve, from its points. Derived classes, which know a closed form or the derivative, should override this. The length used to be taken from an approximation by arcs, which is short by up to some tenths of a percent (e.g. a sine curve, the unrolled miter cut of a tube).
public override double Length { get; }
Property Value
SegmentArea
The area of the circular segment enclosed by the arc and its chord (the line from the start point to the end point): rr(|sweep| - sin(|sweep|))/2. Always positive, regardless of the direction of the arc.
public double SegmentArea { get; }
Property Value
StartDirection
The direction of the curve at the start point (see StartDirection). This base implementation returns the normalized direction at the first base point of the triangulation.
public override GeoVector2D StartDirection { get; }
Property Value
StartParameter
The angle of the start point in radians, measured counterclockwise from the positive x-axis about the center.
public double StartParameter { get; }
Property Value
StartPoint
The start point of the curve (see StartPoint). This base implementation takes it from the first base point of the triangulation; setting it only replaces that base point and leaves the underlying geometry unchanged, which is acceptable for small corrections only. Curves with their own data override it.
public override GeoPoint2D StartPoint { get; set; }
Property Value
Sweep
The total signed change of direction along the curve in radians (see Sweep). This base implementation computes it from an approximation of the curve by circular arcs (Approximate(bool, double)), which is cached; curves with a closed form override it.
public override double Sweep { get; }
Property Value
SweepAngle
The signed sweep angle of the arc, positive for a counterclockwise and negative for a clockwise arc; its magnitude may be up to 2*pi (a full circle). The same value as Sweep, as a SweepAngle.
public SweepAngle SweepAngle { get; }
Property Value
Methods
AddToGraphicsPath(GraphicsPath, bool)
Appends this curve to a GDI+ GraphicsPath, which is used for drawing and printing with GDI+.
public override void AddToGraphicsPath(GraphicsPath path, bool forward)
Parameters
pathGraphicsPaththe path to append to
forwardbooltrue to append the curve in its own direction, false to append it reversed (from the end point to the start point)
Approximate(bool, double)
Approximate this curve and return the approximation. maxError specifies the maximal allowed error, i.e. the maximal deviation of the returned curve from this curve. Is linesOnly ist true, only lines are returned, if linesOnly is false, lines and circular arcs are returned. The result is usually a path consiting of lines and arcs or lines only.
public override ICurve2D Approximate(bool linesOnly, double maxError)
Parameters
Returns
Clone()
Returns an independent copy of this curve of the same type. Modifying the copy does not affect this curve.
public override ICurve2D Clone()
Returns
- ICurve2D
the copy
CloneReverse(bool)
Returns a copy of this curve (see Clone()) which is reversed when reverse is true, i.e.
start point and end point are exchanged and the parameter runs the other way round.
public override ICurve2D CloneReverse(bool reverse)
Parameters
reversebooltrue to reverse the copy, false to copy it as it is
Returns
- ICurve2D
the copy
Complement()
Keeps start and end point but uses the complementary part of the full circle: an arc that sweeps counterclockwise becomes the clockwise arc between the same two points and vice versa.
public void Complement()
Copy(ICurve2D)
Copies the data of the given object to this object. Both objects must be of the same type.
public override void Copy(ICurve2D toCopyFrom)
Parameters
toCopyFromICurve2DCopies the data of this object
DirectionAt(double)
Returns the direction of the curve at the provided normalized position.
public override GeoVector2D DirectionAt(double Position)
Parameters
PositiondoubleWhere to get the direction
Returns
- GeoVector2D
The direction
From2PointsAndTangents(GeoPoint2D, GeoVector2D, GeoPoint2D, GeoVector2D)
Creates the arc from sp to ep whose center is the intersection of the normals to the
given tangent directions at the two points. The radius is the distance from the center to sp, so the arc
is tangential to sd at the start point; it passes through ep only if the data are
consistent, i.e. both points have the same distance from the center.
public static Arc2D From2PointsAndTangents(GeoPoint2D sp, GeoVector2D sd, GeoPoint2D ep, GeoVector2D ed)
Parameters
spGeoPoint2Dstart point
sdGeoVector2Dtangent direction at the start point
epGeoPoint2Dend point
edGeoVector2Dtangent direction at the end point
Returns
- Arc2D
the arc, or null when the two normals are parallel
From3Points(GeoPoint2D, GeoPoint2D, GeoPoint2D)
Creates the arc that starts at sp, passes through mp and ends at ep.
The direction of the arc follows from the position of mp.
public static Arc2D From3Points(GeoPoint2D sp, GeoPoint2D mp, GeoPoint2D ep)
Parameters
spGeoPoint2Dstart point
mpGeoPoint2Da point on the arc between the start point and the end point
epGeoPoint2Dend point
Returns
- Arc2D
the arc, or null when the three points are colinear
GetArea()
Returns the signed area swept by the line from the origin to the moving point of the curve, i.e. GetAreaFromPoint(GeoPoint2D) with the origin as reference point. For a closed curve this is the enclosed area, positive when the curve runs counterclockwise, negative when it runs clockwise.
public override double GetArea()
Returns
- double
the signed area
GetAreaFromPoint(GeoPoint2D)
Overrides GetArea()
public override double GetAreaFromPoint(GeoPoint2D p)
Parameters
Returns
GetExtendedHitTest()
Returns an IQuadTreeInsertable interface. The HitTest Method of this interface returns true if the rectangle coincides with the infinite extension of this curve (unbounded curve). Most curves are not extendable and therefore simply return "this".
public override IQuadTreeInsertable GetExtendedHitTest()
Returns
GetExtent()
Returns the bounding rectangle of the curve (see GetExtent()). This base implementation takes the base points of the triangulation and adds the points where the direction of the curve changes its sign in x or y between two base points, found by a simple interpolation; the result may therefore be slightly imprecise.
public override BoundingRect GetExtent()
Returns
- BoundingRect
the extent
GetFused(ICurve2D, double)
Returnes a new curve of the same type which is the fusion of this curve with the provided curve, e.g. two overlapping lines build a longer line. Returnes null if the fusion is not possible (e.g. a line and an arc or two lines with different direction)
public override ICurve2D GetFused(ICurve2D toFuseWith, double precision)
Parameters
Returns
GetModified(ModOp2D)
Returns a ICurve which is this curve modified by m. The curve can be of different type, e.g. a Circle may return an Ellpse
public override ICurve2D GetModified(ModOp2D m)
Parameters
mModOp2D
Returns
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public override void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
HitTest(ref BoundingRect, bool)
Tests whether the curve touches or crosses the rectangle (see HitTest(ref BoundingRect, bool)). This base implementation tests the triangles of the triangulation and subdivides a hit triangle until the decision is certain.
public override bool HitTest(ref BoundingRect Rect, bool IncludeControlPoints)
Parameters
RectBoundingRectIncludeControlPointsbool
Returns
- bool
true if the curve and the rectangle have a point in common
Intersect(ICurve2D)
Calculates the intersection points of this curve with another curve. Each result carries the point and its parameters
on both curves (par1 on this curve, par2 on
IntersectWith). Depending on the types involved the result may also contain intersections on the
extensions of the curves (e.g. of two lines, or of the full circles of two arcs), recognizable by parameters outside
0.0 to 1.0; use IsParameterOnCurve(double) to filter them. The result is not sorted.
public override GeoPoint2DWithParameter[] Intersect(ICurve2D IntersectWith)
Parameters
IntersectWithICurve2Dthe other curve
Returns
- GeoPoint2DWithParameter[]
the intersection points, an empty array when there are none
Intersect(GeoPoint2D, GeoPoint2D)
Calculates the intersection points of this curve with the line from StartPoint to EndPoint.
Same as Intersect(ICurve2D) with a Line2D: par2 is the
parameter on that line (0.0 at StartPoint, 1.0 at EndPoint), and points on the
extension of the line or of this curve may be included.
public override GeoPoint2DWithParameter[] Intersect(GeoPoint2D StartPoint, GeoPoint2D EndPoint)
Parameters
StartPointGeoPoint2Dstart point of the line
EndPointGeoPoint2Dend point of the line
Returns
- GeoPoint2DWithParameter[]
the intersection points, an empty array when there are none
MakeGeoObject(Plane)
Creates the 3d object that corresponds to this curve placed in the plane p: the 2d coordinates are
taken as coordinates in the coordinate system of the plane (see ToGlobal(GeoPoint2D)). A
Line2D yields a Line, a circle, arc or ellipse an Ellipse, a spline a
BSpline, a path a Path and so on.
public override IGeoObject MakeGeoObject(Plane p)
Parameters
pPlanethe plane to place the curve in
Returns
- IGeoObject
the 3d curve as an IGeoObject
MinDistance(ICurve2D)
Returns the minimal distance between this curve and the other curve given in the parameter. If the two curves intersect, the minimal distance ist 0.
public override double MinDistance(ICurve2D Other)
Parameters
OtherICurve2Dcurve to compute the distance to
Returns
Parallel(double, bool, double, double)
Returns the parallel (offset) curve at the distance Dist. A positive distance offsets to the right of
the direction of the curve (for a counterclockwise arc: outward), a negative distance to the left. Curves which have no exact
parallel of their own type (e.g. BSpline2D) are first approximated by lines and arcs when
approxSpline is true, and throw an exception otherwise. For composed curves (Path2D,
Polyline2D) the offset segments at a convex corner are joined by an arc when the inner angle of the corner
is less than roundAngle, and are extended to their intersection otherwise. A line of zero length
throws a Curve2DException.
public override ICurve2D Parallel(double Dist, bool approxSpline, double precision, double roundAngle)
Parameters
Distdoublethe offset distance, positive to the right of the curve
approxSplinebooltrue to allow replacing the curve by an approximation of lines and arcs
precisiondoublethe maximal deviation of that approximation
roundAngledoublecorners with an inner angle (in radians) below this value are rounded by an arc, others are extended to a sharp corner; 0.0 never rounds. A negative value is used with its absolute value and additionally removes offset segments that fold back onto their predecessor
Returns
- ICurve2D
the parallel curve
PointAt(double)
Returns the point of the curve at the provided normalized position
public override GeoPoint2D PointAt(double Position)
Parameters
PositiondoubleWhere to get the direction
Returns
- GeoPoint2D
The point
PositionOf(GeoPoint2D)
Returns the position of point p on the curve: 0.0 corresponds to the StartPoint 1.0 to the EndPoint
public override double PositionOf(GeoPoint2D p)
Parameters
Returns
Project(Plane, Plane)
The 2d-curve is assumed to reside in plane "fromPlane". It will be projected perpendicular onto the plane "toPlane".
public override ICurve2D Project(Plane fromPlane, Plane toPlane)
Parameters
Returns
- ICurve2D
the projected curve
ReinterpretParameter(ref double)
Some curves especially Arc and EllipseArc have two possibilities to define a parameter of a point outside the curve: either as a parameter less than 0 which means ahead of the startpoint or as a parameter greater than 1 behind the endpoint. This method brings the given parameter into the other system, that means a parameter less than 0 will become greater than 1 and vice versa. Parameters between 0 and 1 will remain unchanged as well as most curves will return false, because the double interpretation isnt meaningfull.
public override bool ReinterpretParameter(ref double p)
Parameters
pdoubleparameter to change
Returns
- bool
true if possible, false otherwise
Reverse()
Reverses the direction of this curve
public override void Reverse()
TangentPointsToAngle(GeoVector2D)
Calculates the points where the direction of the curve is parallel to the given direction. Returns all possible position within the curve (not the extended curve)
public override double[] TangentPointsToAngle(GeoVector2D direction)
Parameters
directionGeoVector2Dthe direction
Returns
- double[]
positions found
ToString()
public override string ToString()
Returns
Trim(double, double)
Returns a new curve of the same type which is the part of this curve between the two normalized parameters. The curve
itself remains unchanged. Normally StartPos is less than EndPos; for a closed curve
(Circle2D, Ellipse2D) reversed parameters select the part that runs across the start point of
the curve, for other curves the behaviour depends on the type (a Line2D or Arc2D returns the
part in reversed direction).
public override ICurve2D Trim(double startPos, double endPos)
Parameters
Returns
- ICurve2D
the trimmed curve, or null when the result would be degenerate (e.g. an arc with zero sweep)
TryPointDeriv2At(double, out GeoPoint2D, out GeoVector2D, out GeoVector2D)
Returns the point and the first two derivatives of the curve with respect to the normalized parameter at
position (see TryPointDeriv2At(double, out GeoPoint2D, out GeoVector2D, out GeoVector2D)). This base implementation only provides the point
and DirectionAt(double) as first derivative, sets the second derivative to the null vector and returns false; curves
that know their second derivative override it.
public override bool TryPointDeriv2At(double position, out GeoPoint2D point, out GeoVector2D deriv, out GeoVector2D deriv2)
Parameters
positiondoublethe normalized parameter
pointGeoPoint2Dthe point at the parameter
derivGeoVector2Dderiv2GeoVector2Dthe second derivative, the null vector when not available
Returns
- bool
true if the second derivative is available, false otherwise