Table of Contents

Class Ellipse2D

Namespace
CADability.Curve2D
Assembly
CADability.dll

Describes an ellipse in 2D. Implements the ICurve2D interface.

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

Constructors

Ellipse2D()

Creates an uninitialized ellipse: center and axes are zero. The library itself does not use it; use Ellipse2D(GeoPoint2D, GeoVector2D, GeoVector2D) or one of the static factory methods to create a usable ellipse.

public Ellipse2D()

Ellipse2D(GeoPoint2D, GeoVector2D, GeoVector2D)

Constructs an ellipse in 2D. The two axis may not be orthogonal but must not be colinear.

public Ellipse2D(GeoPoint2D center, GeoVector2D axis1, GeoVector2D axis2)

Parameters

center GeoPoint2D

Center of the ellipse

axis1 GeoVector2D

First axis of the ellipse

axis2 GeoVector2D

Second axis of the ellipse

Ellipse2D(GeoPoint2D, GeoVector2D, GeoVector2D, bool, GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D)

Constructs an ellipse in 2D. The major and minor axis must be orthogonal.

public Ellipse2D(GeoPoint2D center, GeoVector2D majorAxis, GeoVector2D minorAxis, bool counterClock, GeoPoint2D left, GeoPoint2D right, GeoPoint2D bottom, GeoPoint2D top)

Parameters

center GeoPoint2D

Center of the ellipse

majorAxis GeoVector2D

Major axis of the ellipse

minorAxis GeoVector2D

Minor axis of the ellipse

counterClock bool

true if the ellipse is oriented counterclockwise, false if clockwise

left GeoPoint2D

left extremum of the ellipse

right GeoPoint2D

right extremum of the ellipse

bottom GeoPoint2D

bottom extremum of the ellipse

top GeoPoint2D

top extremum of the ellipse

Ellipse2D(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected Ellipse2D(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Properties

Center

The center of the ellipse. Setting it moves the ellipse and recomputes the derived data (extreme points, mapping to the unit circle).

public GeoPoint2D Center { get; set; }

Property Value

GeoPoint2D

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

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

MajorAxis

The major axis of the ellipse as a vector from the center to the end of the axis. Read only in effect: the setter throws NotImplementedException, because both axes have to be changed together to stay perpendicular; create a new ellipse instead.

public GeoVector2D MajorAxis { get; set; }

Property Value

GeoVector2D

MinorAxis

The minor axis of the ellipse as a vector from the center to the end of the axis. Read only in effect: the setter throws NotImplementedException, because both axes have to be changed together to stay perpendicular; create a new ellipse instead.

public GeoVector2D MinorAxis { get; set; }

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

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)

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

ClosestPerpendicularFoot(GeoPoint2D)

Returns the point of the full (extended) ellipse which is closest to fromHere. The point is computed with CADability.Curve2D.Ellipse2D.DistanceCandidates(CADability.GeoPoint2D), not with the triangulation based PerpendicularFoot(GeoPoint2D), which is imprecise on flat ellipses. For an EllipseArc2D the result may lie outside of the arc.

protected GeoPoint2D ClosestPerpendicularFoot(GeoPoint2D fromHere)

Parameters

fromHere GeoPoint2D

the point to project

Returns

GeoPoint2D

the closest point of the full ellipse

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

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

FromFivePoints(GeoPoint2D[])

Creates the ellipse through five points by solving the equation of the conic section through them. The result runs counterclockwise. The method does not verify that the conic is an ellipse: for points on a hyperbola or a parabola it may return an ellipse that does not pass through them.

public static Ellipse2D FromFivePoints(GeoPoint2D[] p)

Parameters

p GeoPoint2D[]

five points; only the first five are used

Returns

Ellipse2D

the ellipse, or null when the system of equations is singular or degenerate

FromFivePoints(GeoPoint2D[], bool)

Creates the ellipse through five points (see FromFivePoints(GeoPoint2D[])), oriented so that the points follow each other in the direction of the curve. When isFull is false the result is trimmed to the arc from p[0] through p[2] to p[4] and is an EllipseArc2D.

public static Ellipse2D FromFivePoints(GeoPoint2D[] p, bool isFull)

Parameters

p GeoPoint2D[]

five points on the ellipse in their order along the curve; only the first five are used

isFull bool

true for the full ellipse, false for the arc from the first to the last point

Returns

Ellipse2D

the ellipse or elliptical arc, or null when no ellipse passes through the points

FromPoints(IEnumerable<GeoPoint2D>)

Fits an ellipse to any number of points (at least five) in the least squares sense: the affine map that takes the points as close as possible to the unit circle is found by a Levenberg-Marquardt minimization, and the ellipse is its inverse image of the unit circle.

public static Ellipse2D FromPoints(IEnumerable<GeoPoint2D> points)

Parameters

points IEnumerable<GeoPoint2D>

the points to approximate

Returns

Ellipse2D

the fitted ellipse, or null when the minimization does not converge

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

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

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

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

info SerializationInfo

receives the data

context StreamingContext

the 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

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

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

NewtonPerpendicular(GeoPoint2D, double)

Refines the parameter of a perpendicular foot point from fromHere by a Newton minimization of the squared scalar product of the connection to the curve with the direction of the curve, starting at position. Uses the derivatives from TryPointDeriv3At(double, out GeoPoint2D, out GeoVector2D, out GeoVector2D, out GeoVector2D).

public double NewtonPerpendicular(GeoPoint2D fromHere, double position)

Parameters

fromHere GeoPoint2D

the point to project onto the ellipse

position double

normalized start parameter, close to the expected foot point

Returns

double

the refined normalized parameter; the last evaluated parameter when the minimization fails

PerpendicularFoot(GeoPoint2D)

Overrides PerpendicularFoot(GeoPoint2D). Returns all points of the ellipse where the line to fromHere is perpendicular to the ellipse (up to four), computed exactly in the frame of the axes. An EllipseArc2D returns only those inside the arc.

public override GeoPoint2D[] PerpendicularFoot(GeoPoint2D fromHere)

Parameters

fromHere GeoPoint2D

from this point

Returns

GeoPoint2D[]

the 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

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

Reverse()

Reverses the direction of this curve

public override void Reverse()

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

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

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 deriv1, out GeoVector2D deriv2)

Parameters

position double

the normalized parameter

point GeoPoint2D

the point at the parameter

deriv1 GeoVector2D

the first derivative at the parameter

deriv2 GeoVector2D

the second derivative, the null vector when not available

Returns

bool

true if the second derivative is available, false otherwise

TryPointDeriv3At(double, out GeoPoint2D, out GeoVector2D, out GeoVector2D, out GeoVector2D)

Returns the point and the first three derivatives of the curve with respect to the normalized parameter at position. Used by Newton iterations that need the curvature and its change, e.g. NewtonPerpendicular(GeoPoint2D, double). This base implementation only provides the point and DirectionAt(double) as first derivative, sets the higher derivatives to the null vector and returns false; curves that know their derivatives (e.g. Ellipse2D) override it.

public override bool TryPointDeriv3At(double position, out GeoPoint2D point, out GeoVector2D deriv1, out GeoVector2D deriv2, out GeoVector2D deriv3)

Parameters

position double

the normalized parameter

point GeoPoint2D

the point at the parameter

deriv1 GeoVector2D

the first derivative at the parameter

deriv2 GeoVector2D

the second derivative, the null vector when not available

deriv3 GeoVector2D

the third derivative, the null vector when not available

Returns

bool

true if the second and third derivative are available, false otherwise