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
axisLocGeoPointPoint on the axis
axisDirGeoVectorDirection of the axis
t1GeoPoint- point of the triangle
t2GeoPoint- point of the triangle
t3GeoPoint- 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
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
axisLocGeoPointStartpoint of the beam
axisDirGeoVectorDirection of the beam
t1GeoPoint- point of the triangle
t2GeoPoint- point of the triangle
t3GeoPoint- 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
p1GeoPoint2Dfirst point on the circle
p2GeoPoint2Dsecond point on the circle
p3GeoPoint2Dthird point on the circle
centerGeoPoint2Dcenter of the circle through the three points
radiusdoubleits 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
pointsGeoPoint2D[]points to fit
centerGeoPoint2Dcenter of the circle
radiusdoubleradius 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
pGeoPoint2D[]cGeoPoint2Drdouble
Returns
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
circleEllipsethe circle
lineLocationGeoPointa point on the line
lineDirectionGeoVectordirection 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
circleEllipsethe circle
lineLocationGeoPointa point on the line
lineDirectionGeoVectordirection 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
p1GeoPointStartpoint of first line
d1GeoVectorDirection of first line
p2GeoPointStartpoint of second line
d2GeoVectorDirection of second line
pos1doubleResulting position on fist line (p1+pos1*d1)
pos2doubleResulting 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
dirxGeoVector3d direction of the u-axis
diryGeoVector3d direction of the v-axis
toConvertGeoVectorthe 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
Returns
- double
distance
Dist(GeoPoint2D, GeoPoint2D)
Returns the distance of the two 2d points.
public static double Dist(GeoPoint2D FirstPoint, GeoPoint2D SecondPoint)
Parameters
FirstPointGeoPoint2D- point
SecondPointGeoPoint2D- 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
l1StartGeoPointStartpoint of the first line
l1DirGeoVectorDirection of the first line
l2StartGeoPointStartpoint of the second line
l2DirGeoVectorDirection of the second line
par1doubleParameter on the first line
par2doubleParameter 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
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
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
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
PGeoPoint2Dthe point
lstartGeoPoint2Dstartpoint of the line
lendGeoPoint2Dendpoint 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
PGeoPoint2Dthe point
lstartGeoPoint2Dstartpoint of the line
ldirGeoVector2Ddirection 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
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
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
PGeoPoint2Dthe source point
lstartGeoPoint2Dstartpoint of the line
lendGeoPoint2Dendpoint 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
pGeoPoint2DThe source point
sGeoPoint2DStartpoint of the line
vGeoVector2DDirection 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
uvBoundingRectparameter range of the surface
surfaceISurfacethe surface to approximate
maxDegreeintmaximum 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
pGeoPoint2Dthe point in global coordinates
sysLocGeoPoint2Dorigin of the coordinate system
sysDirxGeoVector2Ddirection of the x-axis of the coordinate system
sysDiryGeoVector2Ddirection 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
p1GeoPoint2Dstartpoint of the first line segment
p2GeoPoint2Dendpoint of the first line segment
p3GeoPoint2Dstartpoint of the second line segment
p4GeoPoint2Dendpoint of the second line segment
Returns
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
center1GeoPoint2Dcenter of the first cricle
radius1doubleradius of the first circle
center2GeoPoint2Dcenter of the second cricle
radius2doubleradius 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
lstartGeoPoint2Dstartpoint of the line
lendGeoPoint2Dendpoint of the line
centerGeoPoint2Dcenter of the cricle
radiusdoubleradius 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
pointoflineGeoPoint2Dpoint of the line
directionGeoVector2Ddirection of the line
centerGeoPoint2Dcenter of the cricle
radiusdoubleradius 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
l1StartGeoPointStartpoint of first line
l1DirGeoVectorDirection of first line
l2StartGeoPointStartpoint of second line
l2DirGeoVectorDirection of second line
Returns
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
StartPoint1GeoPoint2DStartpoint of the first line
EndPoint1GeoPoint2DEndpoint of the first line
StartPoint2GeoPoint2DStartpoint of the second line
EndPoint2GeoPoint2DEndpoint of the second line
IntersectionPointGeoPoint2Dthe 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
StartPoint1GeoPoint2DStartpoint of the first line
dir1GeoVector2DDirection of the first line
StartPoint2GeoPoint2DStartpoint of the second line
dir2GeoVector2DDirection of the second line
IntersectionPointGeoPoint2Dthe 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
pointsGeoPoint2D[]the points to fit, at least two
locationGeoPoint2Da point on the fitted line (the centroid of the points)
directionGeoVector2Ddirection 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
pointsGeoPoint[]the points to fit, at least two
locationGeoPointa point on the fitted line (the centroid of the points)
directionGeoVectordirection 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
spGeoPointStart point of the line
epGeoPointEnd point of the line
pGeoPointThe 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
spGeoPointStart point of the line
dirGeoVectorDirection of the line (need not be normalized)
pGeoPointThe 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
spGeoPoint2DStart point of the line
epGeoPoint2DEnd point of the line
pGeoPoint2DThe 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
spGeoPoint2DStart point of the line
dirGeoVector2DDirection of the line (need not be normalized)
pGeoPoint2DThe 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
spGeoPointStart point of the line (parameter 0.0)
epGeoPointEnd point of the line (parameter 1.0)
posdoubleThe 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
spGeoPointStart point of the line
dirGeoVectorDirection of the line
toProjectGeoPointThe 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
spGeoPointStart point of the line (parameter 0.0)
dirGeoVectorDirection of the line (sp+dir has the parameter 1.0)
posdoubleThe 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
spGeoPoint2DStart point of the line (parameter 0.0)
epGeoPoint2DEnd point of the line (parameter 1.0)
posdoubleThe 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
valuedoublethe 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
PGeoPoint2DThe point to test
lstartGeoPoint2DStartpoint of the line
lendGeoPoint2DEndpoint 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
PGeoPoint2DThe point to test
lstartGeoPoint2DStartpoint of the line
ldirGeoVector2DDirection 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
p1GeoPoint2Dfirst testpoint
p2GeoPoint2Dsecond testpoint
p3GeoPoint2Dfirst linepoint
p4GeoPoint2Dsecond 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
p0GeoPoint2Dfirst testpoint
p1GeoPoint2Dsecond testpoint
p2GeoPoint2Dpoint on the line
v2GeoVector2Ddirection 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
p0GeoPoint2Dfirst testpoint
p1GeoPoint2Dsecond testpoint
p2GeoPoint2Dfirst linepoint
p3GeoPoint2Dsecond 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
cpGeoPoint2D[]the vertices of the convex polygon
pGeoPoint2Dthe 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
cpGeoPoint2D[]the vertices of the polygon, which is closed implicitly
pGeoPoint2Dthe 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
p1GeoPoint2Dfirst vertex of the triangle
p2GeoPoint2Dsecond vertex of the triangle
p3GeoPoint2Dthird vertex of the triangle
pGeoPoint2Dthe 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
coeffdouble[]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
Returns
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
toRebaseGeoVectorthe vector to express in the base
sysDirxGeoVectorfirst base vector
sysDiryGeoVectorsecond base vector
sysDirzGeoVectorthird 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
p0GeoPoint2Dfirst line startpoint
p1GeoPoint2Dfirst line endpoint
p2GeoPoint2Dsecond line startpoint
p3GeoPoint2Dsecond 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
p0GeoPoint2Dfirst line startpoint
p1GeoPoint2Dfirst line endpoint
p2GeoPoint2Dsecond line startpoint
p3GeoPoint2Dsecond 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
pointsGeoPoint[]the points to fit
centerGeoPointthe center of the fitted sphere, Invalid when the fit fails
radiusdoublethe 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
c1GeoPoint2Dr1doublec2GeoPoint2Dr2double
Returns
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
center1GeoPoint2Dradius1doublecenter2GeoPoint2Dradius2double
Returns
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
pGeoPoint2Dthe point from which the tangents start, must be outside of the circle
cGeoPoint2Dcenter of the circle
radiusdoubleradius of the circle
Returns
- GeoPoint2D[]
the two touching points (which coincide when
pis on the circle), or an empty array whenpis inside the circle or coincides with its center