C# Класс Loyc.Geometry.LineMath

Показать файл Открыть проект

Открытые методы

Метод Описание
ClipTo ( this seg, BoundingBox bbox ) : LineSegment?

Quickly clips a line to a bounding box.

If the bounding box is not normalized (min > max), the result is undefined.

ComputeIntersection ( this P, LineSegment Q, LineType type = LineType.Segment ) : Point?
ComputeIntersection ( this P, LineType pType, LineSegment Q, LineType qType ) : Point?

Computes the intersection point between two lines, rays or line segments.

This method is implemented based on the other overload, ComputeIntersection(LineSegment, LineType, out T, LineSegment, LineType, out T).

ComputeIntersection ( this P, LineSegment Q, T &pFrac, LineType type = LineType.Segment ) : bool
ComputeIntersection ( this P, LineType pType, T &pFrac, LineSegment Q, LineType qType, T &qFrac ) : bool

Computes the location that lines, rays or line segments intersect, expressed as a fraction of the distance along each LineSegment.

This method does not do a bounding-box check. If you are doing calculations with line segments and you expect the majority of your intersection calculations to return false, you may save time by testing whether the bounding boxes of the lines overlap before calling this method. If the input segments contain NaNs, the result is false and pFrac/qFrac will be NaN. If the either of the line segments are degenerate (single points), overlap can still be detected and the LineType of the degenerate line has no effect; the degenerate line is always treated as a point. If both lines are points, the method will return true iff they are the same point, and if true is returned, pFrac will be 0.5f The output fractions pFrac and qFrac will be infinite if the magnitude of the result overflows. If the two line segments are parallel but do not overlap, this method returns false; pFrac and qFrac are both set to NaN. If the two lines are parallel and overlap, a region of overlap is detected and pFrac and qFrac refer to the center of this region of overlap. If, in this case, P and/or Q are rays or infinite lines, this method behaves as though P and/or Q are extended to cover each other. For instance, suppose that P and Q are lines on the X axis, P.A.X=0, P.B.X=6, Q.A.X=10, Q.B.X=16:

 P.A---------------P.B         Q.B---------------------Q.A -2  -1  0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17 
If P and Q are both line segments, there is no overlap and this method will return false. However, if Q is a Ray or an infinite line, it extends toward negative infinity and the minimum overlap between the lines is 0..6. In this case, the region of overlap is considered to be 0..6 if P is a line segment, and 0..16 if P is a ray or an infinite line. If P is a line segment, the midpoint is 3, and pFrac will be set to 0.5, halfway along the line, while qFrac will be 2.333. If P is a ray or an infinite line, the midpoint is 8, pFrac will be 1.333, and qFrac will be 1.333.
DistanceTo ( this p, LineSegment seg, LineType type = LineType.Segment ) : T
GetFractionAlong ( this p, LineSegment seg, LineType type = LineType.Segment ) : T

Gets the projection of a point onto a line, expressed as a fraction where 0 represents the start of the line and 1 represents the end of the line.

This method uses the same technique as ProjectOnto.

GetFractionAlong ( this p, LineSegment seg, LineType type, int &end ) : T
Length ( this seg ) : T
Midpoint ( this seg ) : System.Point

Returns the midpoint, (A + B) >> 1.

PointAlong ( this seg, T frac ) : System.Point

Given a fraction between zero and one, calculates a point between two points (0=point A, 1=point B, 0.5=midpoint).

If you just want the midpoint, call Midpoint() which is faster. If the fraction is outside the range [0,1], the result will be along the infinite extension of the line. If the two points are the same, this method always returns the same point as long as the math doesn't overflow, possibly with slight deviations caused by floating-point rounding.

ProjectOnto ( this p, LineSegment seg ) : System.Point
ProjectOnto ( this p, LineSegment seg, LineType type = LineType.Segment ) : System.Point

Performs projection, which finds the point on a line segment or infinite line that is nearest to a specified point.

This algorithm is fast and accurate, and can be easily adapted to 3D. A special advantage of this approach is that it runs fastest when the point is projected onto one of the endpoints (when infiniteLine is false). Algorithm comes from: http://geomalgorithms.com/a02-_lines.html See section "Distance of a Point to a Ray or Segment"

ProjectOnto ( this p, LineSegment seg, LineType type, int &end ) : System.Point
ProjectOntoInfiniteLine ( this p, LineSegment seg ) : System.Point
QuadranceTo ( this p, LineSegment seg ) : T
QuadranceTo ( this p, LineSegment seg, LineType type ) : T

Приватные методы

Метод Описание
GetOverlapRegion ( T pa, T pb, LineType pType, T qa, T qb, LineType qType, T &from, T &to ) : bool
IntersectWithXEquals ( LineSegment &seg, T x ) : System.Point
IntersectWithYEquals ( LineSegment &seg, T y ) : System.Point
Sides ( System.Point p, BoundingBox bbox ) : int

Описание методов

ClipTo() публичный статический Метод

Quickly clips a line to a bounding box.
If the bounding box is not normalized (min > max), the result is undefined.
public static ClipTo ( this seg, BoundingBox bbox ) : LineSegment?
seg this
bbox BoundingBox
Результат LineSegment?

ComputeIntersection() публичный статический Метод

public static ComputeIntersection ( this P, LineSegment Q, LineType type = LineType.Segment ) : Point?
P this
Q LineSegment
type LineType
Результат Point?

ComputeIntersection() публичный статический Метод

Computes the intersection point between two lines, rays or line segments.
This method is implemented based on the other overload, ComputeIntersection(LineSegment, LineType, out T, LineSegment, LineType, out T).
public static ComputeIntersection ( this P, LineType pType, LineSegment Q, LineType qType ) : Point?
P this
pType LineType
Q LineSegment
qType LineType
Результат Point?

ComputeIntersection() публичный статический Метод

public static ComputeIntersection ( this P, LineSegment Q, T &pFrac, LineType type = LineType.Segment ) : bool
P this
Q LineSegment
pFrac T
type LineType
Результат bool

ComputeIntersection() публичный статический Метод

Computes the location that lines, rays or line segments intersect, expressed as a fraction of the distance along each LineSegment.
This method does not do a bounding-box check. If you are doing calculations with line segments and you expect the majority of your intersection calculations to return false, you may save time by testing whether the bounding boxes of the lines overlap before calling this method. If the input segments contain NaNs, the result is false and pFrac/qFrac will be NaN. If the either of the line segments are degenerate (single points), overlap can still be detected and the LineType of the degenerate line has no effect; the degenerate line is always treated as a point. If both lines are points, the method will return true iff they are the same point, and if true is returned, pFrac will be 0.5f The output fractions pFrac and qFrac will be infinite if the magnitude of the result overflows. If the two line segments are parallel but do not overlap, this method returns false; pFrac and qFrac are both set to NaN. If the two lines are parallel and overlap, a region of overlap is detected and pFrac and qFrac refer to the center of this region of overlap. If, in this case, P and/or Q are rays or infinite lines, this method behaves as though P and/or Q are extended to cover each other. For instance, suppose that P and Q are lines on the X axis, P.A.X=0, P.B.X=6, Q.A.X=10, Q.B.X=16:
 P.A---------------P.B         Q.B---------------------Q.A -2  -1  0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17 
If P and Q are both line segments, there is no overlap and this method will return false. However, if Q is a Ray or an infinite line, it extends toward negative infinity and the minimum overlap between the lines is 0..6. In this case, the region of overlap is considered to be 0..6 if P is a line segment, and 0..16 if P is a ray or an infinite line. If P is a line segment, the midpoint is 3, and pFrac will be set to 0.5, halfway along the line, while qFrac will be 2.333. If P is a ray or an infinite line, the midpoint is 8, pFrac will be 1.333, and qFrac will be 1.333.
public static ComputeIntersection ( this P, LineType pType, T &pFrac, LineSegment Q, LineType qType, T &qFrac ) : bool
P this First line segment
pType LineType Type of line P (Segment, Ray, Infinite)
pFrac T Fraction along P of the intersection point. If this /// method returns false, pFrac is still computed. If the hypothetical /// intersection point of the infinite extension of P and Q is beyond the /// P.A side of the line, pFrac is set to an appropriate negative value if /// pType is Infinite and 0 otherwise. If the hypothetical intersection /// is on the P.B side of the line, pFrac is set to 1 if pType is Segment /// and a value above 1 otherwise.
Q LineSegment Second line segment
qType LineType Type of line Q (Segment, Ray, Infinite)
qFrac T Fraction along Q of the intersection point. If this /// method returns false, qFrac may be NaN if the analysis of line /// P already determined that pFrac is beyond the range of line P. In other /// words, if Q is assumed to be an infinite line and P still does not /// intersect with Q, qFrac is set to NaN because the method aborts /// analysis to avoid wasting CPU time. On the other hand, if this method /// determines that P might intersect with Q, but a full analysis shows /// that it does not, the method returns false and sets qFrac to a real /// number. qFrac is set to 0 if the intersection point of the infinite /// extension of Q is on the Q.A side of the line, and 1 if the /// intersection point is on the Q.B side of the line.
Результат bool

DistanceTo() публичный статический Метод

public static DistanceTo ( this p, LineSegment seg, LineType type = LineType.Segment ) : T
p this
seg LineSegment
type LineType
Результат T

GetFractionAlong() публичный статический Метод

Gets the projection of a point onto a line, expressed as a fraction where 0 represents the start of the line and 1 represents the end of the line.
This method uses the same technique as ProjectOnto.
public static GetFractionAlong ( this p, LineSegment seg, LineType type = LineType.Segment ) : T
p this
seg LineSegment
type LineType
Результат T

GetFractionAlong() публичный статический Метод

public static GetFractionAlong ( this p, LineSegment seg, LineType type, int &end ) : T
p this
seg LineSegment
type LineType
end int
Результат T

Length() публичный статический Метод

public static Length ( this seg ) : T
seg this
Результат T

Midpoint() публичный статический Метод

Returns the midpoint, (A + B) >> 1.
public static Midpoint ( this seg ) : System.Point
seg this
Результат System.Point

PointAlong() публичный статический Метод

Given a fraction between zero and one, calculates a point between two points (0=point A, 1=point B, 0.5=midpoint).
If you just want the midpoint, call Midpoint() which is faster. If the fraction is outside the range [0,1], the result will be along the infinite extension of the line. If the two points are the same, this method always returns the same point as long as the math doesn't overflow, possibly with slight deviations caused by floating-point rounding.
public static PointAlong ( this seg, T frac ) : System.Point
seg this
frac T
Результат System.Point

ProjectOnto() публичный статический Метод

public static ProjectOnto ( this p, LineSegment seg ) : System.Point
p this
seg LineSegment
Результат System.Point

ProjectOnto() публичный статический Метод

Performs projection, which finds the point on a line segment or infinite line that is nearest to a specified point.
This algorithm is fast and accurate, and can be easily adapted to 3D. A special advantage of this approach is that it runs fastest when the point is projected onto one of the endpoints (when infiniteLine is false). Algorithm comes from: http://geomalgorithms.com/a02-_lines.html See section "Distance of a Point to a Ray or Segment"
public static ProjectOnto ( this p, LineSegment seg, LineType type = LineType.Segment ) : System.Point
p this The test point to be projected
seg LineSegment The line segment
type LineType
Результат System.Point

ProjectOnto() публичный статический Метод

public static ProjectOnto ( this p, LineSegment seg, LineType type, int &end ) : System.Point
p this
seg LineSegment
type LineType
end int
Результат System.Point

ProjectOntoInfiniteLine() публичный статический Метод

public static ProjectOntoInfiniteLine ( this p, LineSegment seg ) : System.Point
p this
seg LineSegment
Результат System.Point

QuadranceTo() публичный статический Метод

public static QuadranceTo ( this p, LineSegment seg ) : T
p this
seg LineSegment
Результат T

QuadranceTo() публичный статический Метод

public static QuadranceTo ( this p, LineSegment seg, LineType type ) : T
p this
seg LineSegment
type LineType
Результат T