Table of Contents

Class Geometry

Namespace
CADability
Assembly
CADability.dll

The class Geometry only contains static methods to solve some basic geometric tasks.

public class Geometry
Inheritance
Geometry
Inherited Members

Constructors

Geometry()

Creates an instance. There is no need to do so, all members of this class are static.

public Geometry()

Methods

AxisThroughTriangle(GeoPoint, GeoVector, GeoPoint, GeoPoint, GeoPoint)

Determins wheather an axis, defined by location and direction, goes through a triangle. The axis is infinite in both directions.

public static bool AxisThroughTriangle(GeoPoint axisLoc, GeoVector axisDir, GeoPoint t1, GeoPoint t2, GeoPoint t3)

Parameters

axisLoc GeoPoint

Point on the axis

axisDir GeoVector

Direction of the axis

t1 GeoPoint
  1. point of the triangle
t2 GeoPoint
  1. point of the triangle
t3 GeoPoint
  1. point of the triangle

Returns

bool

true, if the axis passes through the triangle, false otherwise

AxisThrouoghFourLines(GeoPoint[], GeoVector[], out GeoPoint[], out GeoVector[])

Find one ore more axis (point and direction) passing through the 4 provided lines given by p and v. the provided lines should be pairwise non planar

public static bool AxisThrouoghFourLines(GeoPoint[] p, GeoVector[] v, out GeoPoint[] axisPnt, out GeoVector[] axisDir)

Parameters

p GeoPoint[]
v GeoVector[]
axisPnt GeoPoint[]
axisDir GeoVector[]

Returns

bool

true if a solution could be found

BeamThroughTriangle(GeoPoint, GeoVector, GeoPoint, GeoPoint, GeoPoint)

Determins wheather a beam, defined by location and direction, goes through a triangle. The beam starts at axisLoc and extends in direction axisDir. Only the forward direction is checked.

public static bool BeamThroughTriangle(GeoPoint axisLoc, GeoVector axisDir, GeoPoint t1, GeoPoint t2, GeoPoint t3)

Parameters

axisLoc GeoPoint

Startpoint of the beam

axisDir GeoVector

Direction of the beam

t1 GeoPoint
  1. point of the triangle
t2 GeoPoint
  1. point of the triangle
t3 GeoPoint
  1. point of the triangle

Returns

bool

true, if the beam passes through the triangle, false otherwise

CircleFit(GeoPoint2D, GeoPoint2D, GeoPoint2D, out GeoPoint2D, out double)

The circle through three points. Unlike CircleFitLs(GeoPoint2D[], out GeoPoint2D, out double), which minimizes over any number of points, this is the exact solution and needs no iteration. The computation is done relative to p1, which keeps it well conditioned for points far from the coordinate origin.

public static bool CircleFit(GeoPoint2D p1, GeoPoint2D p2, GeoPoint2D p3, out GeoPoint2D center, out double radius)

Parameters

p1 GeoPoint2D

first point on the circle

p2 GeoPoint2D

second point on the circle

p3 GeoPoint2D

third point on the circle

center GeoPoint2D

center of the circle through the three points

radius double

its radius

Returns

bool

false, if the three points are colinear and there is no such circle

CircleFit(GeoPoint2D[], out GeoPoint2D, out double)

tries to find a center and radius for a circle which best fits to the provided points

public static double CircleFit(GeoPoint2D[] points, out GeoPoint2D center, out double radius)

Parameters

points GeoPoint2D[]

points to fit

center GeoPoint2D

center of the circle

radius double

radius of the circle

Returns

double

maximum error

CircleFitLs(GeoPoint2D[], out GeoPoint2D, out double)

Fits a circle to the provided points and returns the sum of the absolute residuals |dist^2 - r^2| (smaller is a better fit), double.MaxValue when no circle could be determined (fewer than three points, or points on a straight line).

Taubin fit: a geometrically (nearly) unbiased algebraic circle fit, working on data centered at the centroid. The Kasa fit used here before minimizes the algebraic distance without that correction, which systematically UNDERESTIMATES the radius as soon as the points cover only a short arc - over 400 noise realisations a 15 degree arc of radius 20 came out 4.0 too small (a fifth of the radius), a 10 degree arc of radius 100 came out 4.7 too small. Taubin keeps those cases below 0.2. For a full circle both agree.

References: G. Taubin, IEEE PAMI 13 (1991); implementation after N. Chernov, "Circular and Linear Regression: Fitting Circles and Lines by Least Squares".

public static double CircleFitLs(GeoPoint2D[] p, out GeoPoint2D c, out double r)

Parameters

p GeoPoint2D[]
c GeoPoint2D
r double

Returns

double

CircleLineDist(Ellipse, GeoPoint, GeoVector)

Finds the points where the distance between a circle and an infinite line is locally extremal, i.e. where the connecting line is perpendicular to both the circle and the line (there are up to four such pairs). The problem is transformed to the unit circle and solved as a quartic equation. circle must be a circle, not an ellipse. The case of a line perpendicular to the plane of the circle is not implemented and yields an empty array. See also CircleLinePerpDist(Ellipse, GeoPoint, GeoVector), an alternative implementation of the same task.

public static GeoPoint[] CircleLineDist(Ellipse circle, GeoPoint lineLocation, GeoVector lineDirection)

Parameters

circle Ellipse

the circle

lineLocation GeoPoint

a point on the line

lineDirection GeoVector

direction of the line

Returns

GeoPoint[]

pairs of points with extremal distance: the point on the circle at index 2i, the corresponding point on the line at index 2i+1; an empty array if none was found

CircleLinePerpDist(Ellipse, GeoPoint, GeoVector)

Finds the points where the distance between a circle and an infinite line is locally extremal, i.e. where the connecting line is perpendicular to both the circle and the line. The parameter on the line is found as the root of a polynomial (according to the Geometric Tools paper "Distance to Circle in 3D"), the point on the circle by intersecting the circle with the plane perpendicular to the line at that parameter. circle must be a circle, not an ellipse. See also CircleLineDist(Ellipse, GeoPoint, GeoVector).

public static GeoPoint[] CircleLinePerpDist(Ellipse circle, GeoPoint lineLocation, GeoVector lineDirection)

Parameters

circle Ellipse

the circle

lineLocation GeoPoint

a point on the line

lineDirection GeoVector

direction of the line

Returns

GeoPoint[]

pairs of points with extremal distance: the point on the circle followed by the corresponding point on the line (in the rare case that the perpendicular plane only touches the circle, the single touching point without a partner); an empty array if none was found

ConnectLines(GeoPoint, GeoVector, GeoPoint, GeoVector, out double, out double)

Find the shortest connection of the two lines

public static void ConnectLines(GeoPoint p1, GeoVector d1, GeoPoint p2, GeoVector d2, out double pos1, out double pos2)

Parameters

p1 GeoPoint

Startpoint of first line

d1 GeoVector

Direction of first line

p2 GeoPoint

Startpoint of second line

d2 GeoVector

Direction of second line

pos1 double

Resulting position on fist line (p1+pos1*d1)

pos2 double

Resulting position on second line (p2+pos2*d2)

Dir2D(GeoVector, GeoVector, GeoVector)

Converts a 3d direction into a 2d direction in the (u,v) system of a surface or plane whose u- and v-axis have the 3d directions dirx and diry: the result (a,b) satisfies adirx + bdiry = the component of toConvert in the plane spanned by dirx and diry, the component along the normal dirx^diry is dropped. Used e.g. to turn the 3d direction of a curve on a surface into a direction in the parameter space of the surface. Throws a ModOpException when dirx and diry are parallel.

public static GeoVector2D Dir2D(GeoVector dirx, GeoVector diry, GeoVector toConvert)

Parameters

dirx GeoVector

3d direction of the u-axis

diry GeoVector

3d direction of the v-axis

toConvert GeoVector

the 3d direction to convert

Returns

GeoVector2D

the direction in the (u,v) system

Dist(GeoPoint, GeoPoint)

Returns the distance of the two 3d points.

public static double Dist(GeoPoint FirstPoint, GeoPoint SecondPoint)

Parameters

FirstPoint GeoPoint
  1. point
SecondPoint GeoPoint
  1. point

Returns

double

distance

Dist(GeoPoint2D, GeoPoint2D)

Returns the distance of the two 2d points.

public static double Dist(GeoPoint2D FirstPoint, GeoPoint2D SecondPoint)

Parameters

FirstPoint GeoPoint2D
  1. point
SecondPoint GeoPoint2D
  1. point

Returns

double

distance

DistLL(GeoPoint, GeoVector, GeoPoint, GeoVector, out double, out double)

Calculates the minimal distance between two lines and the parameter on the lines where the minimal distance occures. If the lines are parallel, the parameters will be double.MaxValue. The point l1Start + par1l1Dir is closest to the second line, and the point l2Start + par2l2Dir is closest to the first line.

public static double DistLL(GeoPoint l1Start, GeoVector l1Dir, GeoPoint l2Start, GeoVector l2Dir, out double par1, out double par2)

Parameters

l1Start GeoPoint

Startpoint of the first line

l1Dir GeoVector

Direction of the first line

l2Start GeoPoint

Startpoint of the second line

l2Dir GeoVector

Direction of the second line

par1 double

Parameter on the first line

par2 double

Parameter on the second line

Returns

double

Minimal distance

DistPL(GeoPoint, Axis)

Returns the distance of a point from the infinite 3d line given by the axis, see DistPL(GeoPoint, GeoPoint, GeoVector).

public static double DistPL(GeoPoint P, Axis ax)

Parameters

P GeoPoint

the point

ax Axis

the line as location and direction

Returns

double

distance, never negative

DistPL(GeoPoint, GeoPoint, GeoPoint)

Returns the distance of a point from a line (3d)

public static double DistPL(GeoPoint P, GeoPoint lstart, GeoPoint lend)

Parameters

P GeoPoint

the point

lstart GeoPoint

startpoint of the line

lend GeoPoint

endpoint of the line

Returns

double

distance

DistPL(GeoPoint, GeoPoint, GeoVector)

Returns the distance of a point from a line (3d)

public static double DistPL(GeoPoint P, GeoPoint lstart, GeoVector ldir)

Parameters

P GeoPoint

the point

lstart GeoPoint

startpoint of the line

ldir GeoVector

direction of the line

Returns

double

distance

DistPL(GeoPoint2D, GeoPoint2D, GeoPoint2D)

Returns the distance of a point from a line (2d), the distance is positive when the point is on the left side of the line, negative on the right side.

public static double DistPL(GeoPoint2D P, GeoPoint2D lstart, GeoPoint2D lend)

Parameters

P GeoPoint2D

the point

lstart GeoPoint2D

startpoint of the line

lend GeoPoint2D

endpoint of the line

Returns

double

distance

DistPL(GeoPoint2D, GeoPoint2D, GeoVector2D)

Returns the distance of a point from a line (2d). This might also be negative

public static double DistPL(GeoPoint2D P, GeoPoint2D lstart, GeoVector2D ldir)

Parameters

P GeoPoint2D

the point

lstart GeoPoint2D

startpoint of the line

ldir GeoVector2D

direction of the line

Returns

double

distance

DropPL(GeoPoint, GeoPoint, GeoPoint)

Returns the perpendicular foot point of point p on the line (s,e)

public static GeoPoint DropPL(GeoPoint p, GeoPoint s, GeoPoint e)

Parameters

p GeoPoint

The source point

s GeoPoint

Startpoint of the line

e GeoPoint

Endpoint of the line

Returns

GeoPoint

Footpoint

DropPL(GeoPoint, GeoPoint, GeoVector)

Returns the perpendicular foot point of point p on the line through s with direction v

public static GeoPoint DropPL(GeoPoint p, GeoPoint s, GeoVector v)

Parameters

p GeoPoint

The source point

s GeoPoint

Startpoint of the line

v GeoVector

Direction of the line

Returns

GeoPoint

Footpoint

DropPL(GeoPoint2D, GeoPoint2D, GeoPoint2D)

Returns the perpendicular foot point of point p on the line (lstart,lend)

public static GeoPoint2D DropPL(GeoPoint2D P, GeoPoint2D lstart, GeoPoint2D lend)

Parameters

P GeoPoint2D

the source point

lstart GeoPoint2D

startpoint of the line

lend GeoPoint2D

endpoint of the line

Returns

GeoPoint2D

footpoint

DropPL(GeoPoint2D, GeoPoint2D, GeoVector2D)

Returns the perpendicular foot point of point p on the line through s with direction v

public static GeoPoint2D DropPL(GeoPoint2D p, GeoPoint2D s, GeoVector2D v)

Parameters

p GeoPoint2D

The source point

s GeoPoint2D

Startpoint of the line

v GeoVector2D

Direction of the line

Returns

GeoPoint2D

Footpoint

FindImplicitPolynomialForm(BoundingRect, ISurface, int)

Unfinished experiment: was intended to find an implicit polynomial f(x,y,z)=0 of the given degree that approximates the surface in the given parameter range. The method computes nothing and has no effect; do not use it.

public static void FindImplicitPolynomialForm(BoundingRect uv, ISurface surface, int maxDegree)

Parameters

uv BoundingRect

parameter range of the surface

surface ISurface

the surface to approximate

maxDegree int

maximum degree of the polynomial

GetPosition(GeoPoint2D, GeoPoint2D, GeoVector2D, GeoVector2D)

Expresses the point p in the 2d coordinate system given by its origin sysLoc and its axis vectors sysDirx and sysDiry, which need not be perpendicular or normalized: finds (u,v) with p = sysLoc + usysDirx + vsysDiry.

public static GeoPoint2D GetPosition(GeoPoint2D p, GeoPoint2D sysLoc, GeoVector2D sysDirx, GeoVector2D sysDiry)

Parameters

p GeoPoint2D

the point in global coordinates

sysLoc GeoPoint2D

origin of the coordinate system

sysDirx GeoVector2D

direction of the x-axis of the coordinate system

sysDiry GeoVector2D

direction of the y-axis of the coordinate system

Returns

GeoPoint2D

the coordinates (u,v) of the point in that system

Exceptions

Geometry.GeometryException

when the axis vectors are linearly dependent

InnerIntersection(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D)

Returns true if the line segments p1->p2 and p3->p4 have an inner intersection, i.e. an intersection point inside the bounds of the line segment. Returns false otherwise, returns false if the intersection point coincides with one of the two lines

public static bool InnerIntersection(GeoPoint2D p1, GeoPoint2D p2, GeoPoint2D p3, GeoPoint2D p4)

Parameters

p1 GeoPoint2D

startpoint of the first line segment

p2 GeoPoint2D

endpoint of the first line segment

p3 GeoPoint2D

startpoint of the second line segment

p4 GeoPoint2D

endpoint of the second line segment

Returns

bool

IntersectCC(GeoPoint2D, double, GeoPoint2D, double)

Returns the intersection points of two circles in 2d. The result may contain 0 to 2 points.

public static GeoPoint2D[] IntersectCC(GeoPoint2D center1, double radius1, GeoPoint2D center2, double radius2)

Parameters

center1 GeoPoint2D

center of the first cricle

radius1 double

radius of the first circle

center2 GeoPoint2D

center of the second cricle

radius2 double

radius of the second circle

Returns

GeoPoint2D[]

intersctione points

IntersectLC(GeoPoint2D, GeoPoint2D, GeoPoint2D, double)

Returns the intersection points of a circle and a line in 2d. The result may contain 0 to 2 points.

public static GeoPoint2D[] IntersectLC(GeoPoint2D lstart, GeoPoint2D lend, GeoPoint2D center, double radius)

Parameters

lstart GeoPoint2D

startpoint of the line

lend GeoPoint2D

endpoint of the line

center GeoPoint2D

center of the cricle

radius double

radius of the circle

Returns

GeoPoint2D[]

intersctione points

IntersectLC(GeoPoint2D, GeoVector2D, GeoPoint2D, double)

Returns the intersection points of a circle and a line in 2d. The result may contain 0 to 2 points.

public static GeoPoint2D[] IntersectLC(GeoPoint2D pointofline, GeoVector2D direction, GeoPoint2D center, double radius)

Parameters

pointofline GeoPoint2D

point of the line

direction GeoVector2D

direction of the line

center GeoPoint2D

center of the cricle

radius double

radius of the circle

Returns

GeoPoint2D[]

intersctione points

IntersectLL(GeoPoint, GeoVector, GeoPoint, GeoVector)

Intersection point of two lines in 3D. This should only be called when the two lines share a common plane. If not, the result will be in the middle of the closest connection of the two points. If the lines are parallel a GeometryException will be thrown.

public static GeoPoint IntersectLL(GeoPoint l1Start, GeoVector l1Dir, GeoPoint l2Start, GeoVector l2Dir)

Parameters

l1Start GeoPoint

Startpoint of first line

l1Dir GeoVector

Direction of first line

l2Start GeoPoint

Startpoint of second line

l2Dir GeoVector

Direction of second line

Returns

GeoPoint

IntersectLL(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D, out GeoPoint2D)

Calculates the intersectionpoint of two lines in 2d. The intersection point may be in any extension of the two lines.

public static bool IntersectLL(GeoPoint2D StartPoint1, GeoPoint2D EndPoint1, GeoPoint2D StartPoint2, GeoPoint2D EndPoint2, out GeoPoint2D IntersectionPoint)

Parameters

StartPoint1 GeoPoint2D

Startpoint of the first line

EndPoint1 GeoPoint2D

Endpoint of the first line

StartPoint2 GeoPoint2D

Startpoint of the second line

EndPoint2 GeoPoint2D

Endpoint of the second line

IntersectionPoint GeoPoint2D

the intersection point

Returns

bool

true, if there is an intersection point, otherwise false

IntersectLL(GeoPoint2D, GeoVector2D, GeoPoint2D, GeoVector2D, out GeoPoint2D)

Calculates the intersectionpoint of two lines in 2d.

public static bool IntersectLL(GeoPoint2D StartPoint1, GeoVector2D dir1, GeoPoint2D StartPoint2, GeoVector2D dir2, out GeoPoint2D IntersectionPoint)

Parameters

StartPoint1 GeoPoint2D

Startpoint of the first line

dir1 GeoVector2D

Direction of the first line

StartPoint2 GeoPoint2D

Startpoint of the second line

dir2 GeoVector2D

Direction of the second line

IntersectionPoint GeoPoint2D

the intersection point

Returns

bool

true, if there is an intersection point, otherwise false

LineFit(GeoPoint2D[], out GeoPoint2D, out GeoVector2D)

Fits a line to the given 2d points by orthogonal least squares: the sum of the squared perpendicular distances is minimal. The line passes through the centroid of the points, its direction is the principal axis of the centered second moments, which in 2d has the closed form angle = atan2(2*sxy, sxx - syy) / 2. Throws an ApplicationException when fewer than two points are given.

public static double LineFit(GeoPoint2D[] points, out GeoPoint2D location, out GeoVector2D direction)

Parameters

points GeoPoint2D[]

the points to fit, at least two

location GeoPoint2D

a point on the fitted line (the centroid of the points)

direction GeoVector2D

direction of the fitted line (normalized)

Returns

double

the maximum distance of a point from the fitted line, 0.0 when the points are exactly collinear

LineFit(GeoPoint[], out GeoPoint, out GeoVector)

Fits a line to the given 3d points by orthogonal least squares: the sum of the squared perpendicular distances is minimal. The line passes through the centroid of the points, its direction is the eigenvector of the largest eigenvalue of the covariance matrix of the centered points. Throws an ApplicationException when fewer than two points are given.

public static double LineFit(GeoPoint[] points, out GeoPoint location, out GeoVector direction)

Parameters

points GeoPoint[]

the points to fit, at least two

location GeoPoint

a point on the fitted line (the centroid of the points)

direction GeoVector

direction of the fitted line (normalized)

Returns

double

the maximum distance of a point from the fitted line, 0.0 when the points are exactly collinear

LinePar(GeoPoint, GeoPoint, GeoPoint)

Returns the parameter of the given point on the (infinite) 3d line through sp and ep, i.e. the factor t for which sp + t*(ep-sp) is the perpendicular foot point of p on the line: 0.0 for the start point, 1.0 for the end point. Unlike the 2d overloads the point need not lie on the line. The result is NaN when start and end point coincide.

public static double LinePar(GeoPoint sp, GeoPoint ep, GeoPoint p)

Parameters

sp GeoPoint

Start point of the line

ep GeoPoint

End point of the line

p GeoPoint

The point whose parameter is requested

Returns

double

The parameter of the foot point

LinePar(GeoPoint, GeoVector, GeoPoint)

Returns the parameter of the given point on the (infinite) 3d line given by sp and dir, i.e. the factor t for which sp + t*dir is the perpendicular foot point of p on the line: 0.0 for the start point, 1.0 for sp+dir. The point need not lie on the line. The result is NaN for a null vector.

public static double LinePar(GeoPoint sp, GeoVector dir, GeoPoint p)

Parameters

sp GeoPoint

Start point of the line

dir GeoVector

Direction of the line (need not be normalized)

p GeoPoint

The point whose parameter is requested

Returns

double

The parameter of the foot point

LinePar(GeoPoint2D, GeoPoint2D, GeoPoint2D)

Returns the parameter of the given point on the (infinite) 2d line through sp and ep, i.e. the factor t with p = sp + t*(ep-sp): 0.0 for the start point, 1.0 for the end point. The point is assumed to lie on the line; for a point off the line only its major coordinate is evaluated, so the result is not the parameter of the perpendicular foot point (see LinePar(GeoPoint2D, GeoVector2D, GeoPoint2D)). Returns 0.5 when start and end point coincide.

public static double LinePar(GeoPoint2D sp, GeoPoint2D ep, GeoPoint2D p)

Parameters

sp GeoPoint2D

Start point of the line

ep GeoPoint2D

End point of the line

p GeoPoint2D

The point whose parameter is requested

Returns

double

The parameter of the point

LinePar(GeoPoint2D, GeoVector2D, GeoPoint2D)

Returns the parameter of the given point on the given (infinite) 2d line, i.e. the factor t with p = sp + t*dir. The point is assumed to lie on the line; for a point off the line only its major coordinate is evaluated, so the result is not the parameter of the perpendicular foot point.

public static double LinePar(GeoPoint2D sp, GeoVector2D dir, GeoPoint2D p)

Parameters

sp GeoPoint2D

Start point of the line

dir GeoVector2D

Direction of the line (need not be normalized)

p GeoPoint2D

The point whose parameter is requested

Returns

double

The parameter, e.g. 0.0 for the start point, 1.0 for sp+dir

LinePos(GeoPoint, GeoPoint, double)

Returns the point with the parameter pos on the line through sp and ep, i.e. sp + pos*(ep-sp). The inverse of LinePar(GeoPoint, GeoPoint, GeoPoint).

public static GeoPoint LinePos(GeoPoint sp, GeoPoint ep, double pos)

Parameters

sp GeoPoint

Start point of the line (parameter 0.0)

ep GeoPoint

End point of the line (parameter 1.0)

pos double

The parameter, may be outside [0,1]

Returns

GeoPoint

The point on the line

LinePos(GeoPoint, GeoVector, GeoPoint)

Returns the perpendicular foot point of toProject on the line given by sp and dir, i.e. the point of the line closest to toProject. Same as DropPL(GeoPoint, GeoPoint, GeoVector).

public static GeoPoint LinePos(GeoPoint sp, GeoVector dir, GeoPoint toProject)

Parameters

sp GeoPoint

Start point of the line

dir GeoVector

Direction of the line

toProject GeoPoint

The point to project onto the line

Returns

GeoPoint

The foot point on the line

LinePos(GeoPoint, GeoVector, double)

Returns the point with the parameter pos on the line given by sp and dir, i.e. sp + pos*dir. The inverse of LinePar(GeoPoint, GeoVector, GeoPoint).

public static GeoPoint LinePos(GeoPoint sp, GeoVector dir, double pos)

Parameters

sp GeoPoint

Start point of the line (parameter 0.0)

dir GeoVector

Direction of the line (sp+dir has the parameter 1.0)

pos double

The parameter

Returns

GeoPoint

The point on the line

LinePos(GeoPoint2D, GeoPoint2D, double)

Returns the 2d point with the parameter pos on the line through sp and ep, i.e. sp + pos*(ep-sp). The inverse of LinePar(GeoPoint2D, GeoPoint2D, GeoPoint2D).

public static GeoPoint2D LinePos(GeoPoint2D sp, GeoPoint2D ep, double pos)

Parameters

sp GeoPoint2D

Start point of the line (parameter 0.0)

ep GeoPoint2D

End point of the line (parameter 1.0)

pos double

The parameter, may be outside [0,1]

Returns

GeoPoint2D

The point on the line

NextDouble(double)

Returns the smallest double that is greater than value, i.e. the next representable floating point number in positive direction. Used to round limits up, e.g. for the cubes of an OctTree<T>, so that adjacent intervals have no gaps.

public static double NextDouble(double value)

Parameters

value double

the value

Returns

double

the next greater double

OnLeftSide(GeoPoint2D, GeoPoint2D, GeoPoint2D)

Checks whether the point P is on the left side of the line from lstart to lend (left when looking from lstart towards lend). If the point lies exactly on the line, the result is false. There is no precision or epsilon test.

public static bool OnLeftSide(GeoPoint2D P, GeoPoint2D lstart, GeoPoint2D lend)

Parameters

P GeoPoint2D

The point to test

lstart GeoPoint2D

Startpoint of the line

lend GeoPoint2D

Endpoint of the line

Returns

bool

true, if P is on the left side, false otherwise

OnLeftSide(GeoPoint2D, GeoPoint2D, GeoVector2D)

Checks whether the point P is on the left side of the line given by lstart and ldir. If the point lies exactly on the line, the result is false. There is no precision or epsilon test. Precision

public static bool OnLeftSide(GeoPoint2D P, GeoPoint2D lstart, GeoVector2D ldir)

Parameters

P GeoPoint2D

The point to test

lstart GeoPoint2D

Startpoint of the line

ldir GeoVector2D

Direction of the line

Returns

bool

true, if P is on the left side, false otherwise

OnSameSide(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D)

Returns true, if p1 an p2 are on the same side of the line given by p3 and p4. Also returns true if one of the two points p1 and p2 coincide with the line (p3,p4)

public static bool OnSameSide(GeoPoint2D p1, GeoPoint2D p2, GeoPoint2D p3, GeoPoint2D p4)

Parameters

p1 GeoPoint2D

first testpoint

p2 GeoPoint2D

second testpoint

p3 GeoPoint2D

first linepoint

p4 GeoPoint2D

second linepoint

Returns

bool

true if on the same side

OnSameSide(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoVector2D)

Returns true, if p0 and p1 are on the same side of the line through p2 with the direction v2. Also returns true if one of the two points lies on the line (within a small tolerance relative to the length of v2). Same as OnSameSide(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D) with the line given by a point and a direction.

public static bool OnSameSide(GeoPoint2D p0, GeoPoint2D p1, GeoPoint2D p2, GeoVector2D v2)

Parameters

p0 GeoPoint2D

first testpoint

p1 GeoPoint2D

second testpoint

p2 GeoPoint2D

point on the line

v2 GeoVector2D

direction of the line

Returns

bool

true if on the same side

OnSameSideStrict(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D)

Returns true, if p0 and p1 are strictly on the same side of the line through p2 and p3. Unlike OnSameSide(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D) the result is false when one of the two points lies on the line, within a tolerance of 1e-6 relative to the length of the line. Currently not used.

public static bool OnSameSideStrict(GeoPoint2D p0, GeoPoint2D p1, GeoPoint2D p2, GeoPoint2D p3)

Parameters

p0 GeoPoint2D

first testpoint

p1 GeoPoint2D

second testpoint

p2 GeoPoint2D

first linepoint

p3 GeoPoint2D

second linepoint

Returns

bool

true if strictly on the same side

PointInsideConvexPolygon(GeoPoint2D[], GeoPoint2D)

Checks whether the point p lies inside the convex polygon with the vertices cp (in either orientation, the polygon is closed implicitly): the point is inside when it lies on the same side of all edges. This is only correct for convex polygons, use PointInsidePolygon(GeoPoint2D[], GeoPoint2D) for arbitrary polygons. There is no epsilon test.

public static bool PointInsideConvexPolygon(GeoPoint2D[] cp, GeoPoint2D p)

Parameters

cp GeoPoint2D[]

the vertices of the convex polygon

p GeoPoint2D

the point to test

Returns

bool

true, if the point is inside the polygon

PointInsidePolygon(GeoPoint2D[], GeoPoint2D)

Computes the winding number of the closed polygon with the vertices cp around the point p. The polygon may be arbitrary (concave or self intersecting). The result is 0 when the point is outside, +1 inside a counterclockwise polygon, -1 inside a clockwise polygon, and other values where the polygon winds around the point more than once.

public static int PointInsidePolygon(GeoPoint2D[] cp, GeoPoint2D p)

Parameters

cp GeoPoint2D[]

the vertices of the polygon, which is closed implicitly

p GeoPoint2D

the point to test

Returns

int

the winding number, 0 for a point outside

PointInsideTriangle(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D)

Checks whether the point p lies inside the triangle with the vertices p1, p2 and p3, which may be given in either orientation: the point is inside when it lies on the same side of all three edges. There is no epsilon test, a point exactly on an edge may be reported either way.

public static bool PointInsideTriangle(GeoPoint2D p1, GeoPoint2D p2, GeoPoint2D p3, GeoPoint2D p)

Parameters

p1 GeoPoint2D

first vertex of the triangle

p2 GeoPoint2D

second vertex of the triangle

p3 GeoPoint2D

third vertex of the triangle

p GeoPoint2D

the point to test

Returns

bool

true, if the point is inside the triangle

PolynomialRoots(params double[])

Finds all real roots of a polynomial of arbitrary degree. The first coefficient is the one with the highest degree. Uses the Jenkins–Traub algorithm.

public static double[] PolynomialRoots(params double[] coeff)

Parameters

coeff double[]

coefficients of the polynom

Returns

double[]

the roots

ReBase(GeoVector, GeoVector, GeoVector, GeoVector)

Computes the vector toRebase in the base given by sysDirx, sysDiry and sysDirz.

public static GeoVector ReBase(GeoVector toRebase, GeoVector sysDirx, GeoVector sysDiry, GeoVector sysDirz)

Parameters

toRebase GeoVector
sysDirx GeoVector
sysDiry GeoVector
sysDirz GeoVector

Returns

GeoVector

ReBaseX(GeoVector, GeoVector, GeoVector, GeoVector)

Expresses the vector toRebase in the base given by the three vectors, i.e. finds (a,b,c) with toRebase = asysDirx + bsysDiry + c*sysDirz by solving the linear system. Unlike ReBase(GeoVector, GeoVector, GeoVector, GeoVector) this is also correct for a base whose vectors are not perpendicular to each other. The base vectors must be linearly independent.

public static GeoVector ReBaseX(GeoVector toRebase, GeoVector sysDirx, GeoVector sysDiry, GeoVector sysDirz)

Parameters

toRebase GeoVector

the vector to express in the base

sysDirx GeoVector

first base vector

sysDiry GeoVector

second base vector

sysDirz GeoVector

third base vector

Returns

GeoVector

the coefficients (a,b,c) as a vector

Exceptions

Geometry.GeometryException

when no solution is found

SegmentInnerIntersection(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D)

Same as SegmentIntersection(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D), but returns true only if the intersection happens in the inside of the two segments, not at the endpoints

public static bool SegmentInnerIntersection(GeoPoint2D p0, GeoPoint2D p1, GeoPoint2D p2, GeoPoint2D p3)

Parameters

p0 GeoPoint2D

first line startpoint

p1 GeoPoint2D

first line endpoint

p2 GeoPoint2D

second line startpoint

p3 GeoPoint2D

second line endpoint

Returns

bool

true if segment intersection

SegmentIntersection(GeoPoint2D, GeoPoint2D, GeoPoint2D, GeoPoint2D)

Returns true, if the two line segments given by (p0,p1) and (p2,p3) have a common intersection. The intersection point is noct calculated. This Method is intended as a fast check for intersection or not. Returns true, if one segment starts or ends on the other segment.

public static bool SegmentIntersection(GeoPoint2D p0, GeoPoint2D p1, GeoPoint2D p2, GeoPoint2D p3)

Parameters

p0 GeoPoint2D

first line startpoint

p1 GeoPoint2D

first line endpoint

p2 GeoPoint2D

second line startpoint

p3 GeoPoint2D

second line endpoint

Returns

bool

true if segment intersection

SphereFit(GeoPoint[], out GeoPoint, out double)

Fits a sphere through the given points by an algebraic least squares method (as in the Geometric Tools library). At least four points that do not lie in a common plane are needed. For an iterative fit with a start value see SphereFit(IArray<GeoPoint>, GeoPoint, double, double, out SphericalSurface).

public static double SphereFit(GeoPoint[] points, out GeoPoint center, out double radius)

Parameters

points GeoPoint[]

the points to fit

center GeoPoint

the center of the fitted sphere, Invalid when the fit fails

radius double

the radius of the fitted sphere, MaxValue when the fit fails

Returns

double

the sum of the absolute distances of the points from the sphere (0.0 for a perfect fit), or MaxValue when the points do not determine a sphere, e.g. because they are coplanar

TangentCC(GeoPoint2D, double, GeoPoint2D, double)

Computes all external and internal tangents between two circles. Returns a list of point pairs (on circle1 and circle2 respectively) that define the tangents.

public static GeoPoint2D[] TangentCC(GeoPoint2D c1, double r1, GeoPoint2D c2, double r2)

Parameters

c1 GeoPoint2D
r1 double
c2 GeoPoint2D
r2 double

Returns

GeoPoint2D[]

TangentCCOld(GeoPoint2D, double, GeoPoint2D, double)

Tangential lines to two circles, returned as pairs of points

public static GeoPoint2D[] TangentCCOld(GeoPoint2D center1, double radius1, GeoPoint2D center2, double radius2)

Parameters

center1 GeoPoint2D
radius1 double
center2 GeoPoint2D
radius2 double

Returns

GeoPoint2D[]

TangentPointCircle(GeoPoint2D, GeoPoint2D, double)

Computes the points on the circle with the center c and the radius radius where the tangents through the point p touch the circle.

public static GeoPoint2D[] TangentPointCircle(GeoPoint2D p, GeoPoint2D c, double radius)

Parameters

p GeoPoint2D

the point from which the tangents start, must be outside of the circle

c GeoPoint2D

center of the circle

radius double

radius of the circle

Returns

GeoPoint2D[]

the two touching points (which coincide when p is on the circle), or an empty array when p is inside the circle or coincides with its center