Table of Contents

Class Path2D

Namespace
CADability.Curve2D
Assembly
CADability.dll

Composition of one or more ICurve2D objects. The contained ICurve2D objects are connected and stored in the right order, i.e. SubCurve[i].EndPoint is identical or close to SubCurve[i+1].StartPoint. Path2D may be open or closed. It also may be self-intersecting.

public class Path2D : GeneralCurve2D, ICurve2D, IQuadTreeInsertable, ISerializable
Inheritance
Path2D
Implements
Inherited Members

Constructors

Path2D(ICurve2D[])

Constructs a path from curves that are already connected in the right order: the end point of each curve must coincide with the start point of the next (according to IsEqual(GeoPoint2D, GeoPoint2D)). The array is copied, the curves themselves are shared with the caller.

public Path2D(ICurve2D[] subCurves)

Parameters

subCurves ICurve2D[]

the connected curves in their order

Exceptions

ApplicationException

when two consecutive curves are not connected

Path2D(ICurve2D[], bool)

Constructs a path from curves in the right order and closes small gaps between them by moving the end point of each curve onto the start point of the next, which modifies the given curves. The value of forceConnection is not examined; this overload always connects.

public Path2D(ICurve2D[] subCurves, bool forceConnection)

Parameters

subCurves ICurve2D[]

the curves in their order

forceConnection bool

not examined, the overload itself selects the behaviour

Path2D(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected Path2D(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Properties

DisplayClosed

Intended to mark the path as closed for display purposes. The value is stored but not used by the library at present.

public bool DisplayClosed { set; }

Property Value

bool

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

GeoVector2D

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

GeoPoint2D

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

bool

this[int]

The curve with the given index, in the order of the path. It is the curve itself, not a copy.

public ICurve2D this[int Index] { get; }

Parameters

Index int

index from 0 to SubCurvesCount-1

Property Value

ICurve2D

the curve

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

double

MiddleDirection

The direction of the curve at the parameter 0.5 (see MiddleDirection), computed by DirectionAt(double).

public override GeoVector2D MiddleDirection { get; }

Property Value

GeoVector2D

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

GeoVector2D

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

GeoPoint2D

SubCurves

The curves the path consists of, in their order, as a copy of the internal array. The curves themselves are not copied, so changing one of them changes the path.

public ICurve2D[] SubCurves { get; }

Property Value

ICurve2D[]

SubCurvesCount

The number of curves the path consists of.

public int SubCurvesCount { get; }

Property Value

int

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

double

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

path GraphicsPath

the path to append to

forward bool

true to append the curve in its own direction, false to append it reversed (from the end point to the start point)

Append(ICurve2D)

Appends a curve at the end of the path. The start point of toAppend is set to the end point of the path, which modifies that curve, so it should already start there or close to it.

public void Append(ICurve2D toAppend)

Parameters

toAppend ICurve2D

the curve to append

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

linesOnly bool
maxError double

Returns

ICurve2D

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

reverse bool

true to reverse the copy, false to copy it as it is

Returns

ICurve2D

the copy

ConnectWith(ICurve2D, double)

Adds a curve at the end or at the beginning of the path if one of its end points is closer than precision to the end point or the start point of the path. The curve is reversed when necessary, and small gaps are closed by moving end points, so toConnect may be modified.

public bool ConnectWith(ICurve2D toConnect, double precision)

Parameters

toConnect ICurve2D

the curve to add

precision double

the maximal distance between the end points to connect

Returns

bool

true if the curve was added, false if it does not connect to either end of the path

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

toCopyFrom ICurve2D

Copies the data of this object

CreateRoundedRectangle(GeoPoint2D, double, double, double, SweepAngle)

Creates a closed rectangle with rounded corners around center, rotated by rotation about that center.

public static Path2D CreateRoundedRectangle(GeoPoint2D center, double width, double height, double cornerRadius, SweepAngle rotation)

Parameters

center GeoPoint2D
width double
height double
cornerRadius double
rotation SweepAngle

Returns

Path2D

DirectionAt(double)

Returns the direction of the curve at the provided normalized position.

public override GeoVector2D DirectionAt(double Position)

Parameters

Position double

Where to get the direction

Returns

GeoVector2D

The direction

Distance(GeoPoint2D)

Returns the distance of the specified point to this curve. If this curve can be extended (e.g. a line or an arc) this method will return the distance to the extended curve. If you need the distance to the unextended curve use MinDistance(GeoPoint2D).

public override double Distance(GeoPoint2D p)

Parameters

p GeoPoint2D

Point to compute the distance to

Returns

double

the distance

Flatten()

Replaces nested Path2D segments by their own sub curves and Polyline2D segments by lines, so that the path consists of simple curves only. Null segments and segments shorter than eps are dropped.

public void Flatten()

GeometricalEqual(double, Path2D)

Rough test whether two paths describe the same curve: both must have the same start and end points, and each inner vertex (junction of two segments) of either path must be closer than precision to the other path. For a path with a single segment its middle point is tested as well. Deviations between the vertices are not detected.

public bool GeometricalEqual(double precision, Path2D other)

Parameters

precision double

the allowed distance

other Path2D

the path to compare with

Returns

bool

true if the paths are considered equal

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)

Returns the signed area swept by the line from p to the moving point of the curve as it runs from the start point to the end point, i.e. the area enclosed by the segment from p to StartPoint, the curve and the segment from EndPoint back to p. The area is positive when this loop runs counterclockwise. Summed over the segments of a closed loop it gives the enclosed area, independent of p, with the sign telling the orientation of the loop; Border and Face use it this way.

public override double GetAreaFromPoint(GeoPoint2D p)

Parameters

p GeoPoint2D

the reference point

Returns

double

the signed area

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

IQuadTreeInsertable

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

toFuseWith ICurve2D

Curve to fuse with

precision double

the fused curve or null

Returns

ICurve2D

GetInflectionPoints()

Finds the inflection points of the curve numerically (see GetInflectionPoints()): the intervals of the triangulation basis (GetTriangulationBasis(out GeoPoint2D[], out GeoVector2D[], out double[])) are scanned for sign changes of the curvature numerator x'*y'' - y'*x'', with the second derivative taken as a central difference of DirectionAt(double), and each sign change is refined by Brent's root finding. Sign changes within the noise of an almost straight curve are ignored. Curves that know their second derivative exactly override it (BSpline2D does).

public override double[] GetInflectionPoints()

Returns

double[]

the normalized parameters of the inflection points in ascending order; empty for a line or a curve without inflection points

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

m ModOp2D

Returns

ICurve2D

GetSelfIntersections()

Returns pairs of double values. Each pair defines the two parameters of the curve of a self intersection. The result is either empty or has an even number of double values.

public override double[] GetSelfIntersections()

Returns

double[]

self intersection parameters

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

Rect BoundingRect
IncludeControlPoints bool

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

IntersectWith ICurve2D

the 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

StartPoint GeoPoint2D

start point of the line

EndPoint GeoPoint2D

end point of the line

Returns

GeoPoint2DWithParameter[]

the intersection points, an empty array when there are none

IsParameterOnCurve(double)

Determines, whether the given parameter denotes a point inside the bounds of the curve. i.e. the parameter must be greater or equal to 0.0 and less than or equal 1.0. The actual interval is a little bit extended according to the eps value.

public override bool IsParameterOnCurve(double par)

Parameters

par double

the parameter to test

Returns

bool

true if on curve

IsValidParameter(double)

Determines, whether the given parameter is valid for this curve. Some curves are restricted to a parameterrange by their nature.

public override bool IsValidParameter(double par)

Parameters

par double

the parameter to test

Returns

bool

true if valid

MakeBorder()

Creates a Border from the curves of this path. A closed border is oriented counterclockwise, so the segments may be reversed; use MakeBorder(out bool) to learn whether that happened.

public Border MakeBorder()

Returns

Border

the border

MakeBorder(out bool)

Creates a Border from the curves of this path and tells whether its orientation was reversed to make a closed border counterclockwise.

public Border MakeBorder(out bool reversed)

Parameters

reversed bool

true if the border runs in the opposite direction of this path

Returns

Border

the border

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

p Plane

the 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

Other ICurve2D

curve to compute the distance to

Returns

double

MinDistance(GeoPoint2D)

Returns the distance of the point to the curve. In opposite to Distance(GeoPoint2D) this method will return the distance to the unextended curve

public override double MinDistance(GeoPoint2D p)

Parameters

p GeoPoint2D

Point to compute the distance to

Returns

double

the distance

Move(double, double)

Move the curve by the given offset

public override void Move(double dx, double dy)

Parameters

dx double
dy double

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

Dist double

the offset distance, positive to the right of the curve

approxSpline bool

true to allow replacing the curve by an approximation of lines and arcs

precision double

the maximal deviation of that approximation

roundAngle double

corners 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

PerpendicularFoot(GeoPoint2D)

Calculates the foot points of the perpendicular projection of the given point on the curve. Perpendicular foot points are points, where the direction of the curve ist perpendicular to the line that connects foot-point to the given point.

public override GeoPoint2D[] PerpendicularFoot(GeoPoint2D FromHere)

Parameters

FromHere GeoPoint2D

from this point

Returns

GeoPoint2D[]

array of foot points

PointAt(double)

Returns the point of the curve at the provided normalized position

public override GeoPoint2D PointAt(double Position)

Parameters

Position double

Where to get the direction

Returns

GeoPoint2D

The point

PositionAtLength(double)

Converts an arc length, measured along the curve from the start point, into the normalized parameter of the point at that length, so that PositionAtLength(Length) is 1.0. Used e.g. to cut a piece of a given length off a curve by Trim(double, double).

public override double PositionAtLength(double position)

Parameters

position double

the arc length from the start point, in the units of the curve

Returns

double

the normalized parameter (0.0 to 1.0) of the point at that length; a length beyond the end of the curve yields 1.0 or a parameter greater than 1.0, depending on the type of the curve

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

p GeoPoint2D

Returns

double

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

fromPlane Plane

the containing plane

toPlane Plane

the projection plane

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

p double

parameter to change

Returns

bool

true if possible, false otherwise

RemoveFirstSegment()

Removes the first curve of the path; the remaining curves stay as they are.

public void RemoveFirstSegment()

ReplaceSubcurve(int, ICurve2D)

Replaces the curve with the given index by another curve with the same start and end points, e.g. by a simpler or a more precise representation of the same segment.

public bool ReplaceSubcurve(int index, ICurve2D curve)

Parameters

index int

index of the curve to replace

curve ICurve2D

the new curve

Returns

bool

true if replaced, false if the start or end point of curve differs from those of the segment

Reverse()

Reverses the direction of this curve

public override void Reverse()

RoundVertices(double)

Returns a copy of this path with all its vertices replaced by arcs of the given radius. A vertex where the two segments meet tangentially, or where the arc would not fit, is left as it is. For a closed path the vertex between the last and the first segment is rounded as well.

public Path2D RoundVertices(double radius)

Parameters

radius double

radius of the rounding arcs

Returns

Path2D

Split(double)

Splits the curve at the given normalized parameter. The curve itself remains unchanged.

public override ICurve2D[] Split(double Position)

Parameters

Position double

the parameter where to split

Returns

ICurve2D[]

two new curves, the part from 0.0 to Position and the part from Position to 1.0; a single copy of the whole curve when Position is not strictly between 0.0 and 1.0

Split(double[])

Splits the path at several normalized parameters at once. The path itself remains unchanged.

public ICurve2D[] Split(double[] positions)

Parameters

positions double[]

the parameters where to split; the array is sorted in place

Returns

ICurve2D[]

the pieces between consecutive parameters, from 0.0 to 1.0, in their order; empty intervals (duplicate parameters, parameters at 0.0 or 1.0) and degenerate pieces are left out

TangentPoints(GeoPoint2D, GeoPoint2D)

Calculates the points where the direction of the curve is parallel to the direction from the given point to the calculated point. For circles and ellipses it reveals all possible solutions, for other curves (e.g. BSpline) it reveals only the closest solution to the point "CloseTo".

public override GeoPoint2D[] TangentPoints(GeoPoint2D FromHere, GeoPoint2D CloseTo)

Parameters

FromHere GeoPoint2D

From this point

CloseTo GeoPoint2D

Find the solution close to this point

Returns

GeoPoint2D[]

array of tangential points

TangentPointsToAngle(Angle, GeoPoint2D)

Calculates the points where the direction of the curve is parallel to the direction of the given angle. For circles and ellipses it reveals all possible solutions, for other curves (e.g. BSpline) it reveals only the closest solution to the point "CloseTo".

public override GeoPoint2D[] TangentPointsToAngle(Angle ang, GeoPoint2D CloseTo)

Parameters

ang Angle

the angle of the tangent

CloseTo GeoPoint2D

Find the solution close to this point

Returns

GeoPoint2D[]

array of tangential points

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

direction GeoVector2D

the direction

Returns

double[]

positions found

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

StartPos double

parameter of the start of the part

EndPos double

parameter of the end of the part

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

position double

the normalized parameter

point GeoPoint2D

the point at the parameter

deriv GeoVector2D
deriv2 GeoVector2D

the second derivative, the null vector when not available

Returns

bool

true if the second derivative is available, false otherwise