Math

Math related methods


SRL.Modulo

function TSRL.Modulo(X, Y: Double): Double; static;
function TSRL.Modulo(X, Y: Int32): Int32; static; overload;

This function returns the remainder from the division of the first argument by the second. It will always returns a result with the same sign as its second operand (or zero).

Example:

  Writeln(SRL.Modulo(a, b));

SRL.CrossProduct

function TSRL.CrossProduct(ry,ry, px,py, qx,qy: Double): Double; static;
function TSRL.CrossProduct(r, p, q: TPoint): Int64; static; overload;

Cross-product of rp and rq vectors.


SRL.DeltaAngle

function TSRL.DeltaAngle(DegA, DegB: Double; R: Double = 360): Double; static;

Returns the shortest difference between two given angles.


SRL.DistToLine

function TSRL.DistToLineEx(pt, sA, sB: TPoint; out Nearest: TPoint): Double; static;
function TSRL.DistToLine(pt, sA, sB: TPoint): Double; static;

Returns the distance to the nearest point on the line sA..sB


TRectangle.NearestEdge

function TRectangle.NearestEdge(P: TPoint): TPoint; constref;

Returns the closest edge point (think Rect.ToTPA.Connect) to the TPoint P.


SRL.LinesIntersect

function TSRL.LinesIntersect(p1,p2, q1,q2:TPoint; out i: TPoint): Boolean; static;

Check if 2 lines cross each other.


SRL.PointInTriangle

function TSRL.PointInTriangle(pt, p1,p2,p3: TPoint): Boolean; static;

Returns True if the TPoint ‘pt’ is inside the triangle


SRL.PointInRect

function TSRL.PointInRect(const pt: TPoint; const A, B, C, D: TPoint): Boolean; static;
function TSRL.PointInRect(pt: TPoint; rect: TRectangle): Boolean; static; overload;

Returns true if the TPoint ‘pt’ is in a rect (defined by four point.

Example:

Writeln(SRL.PointInRect(Point(100, 100), [0,0], [200,1], [201,201], [0,225]));

SRL.PointInCircle

function TSRL.PointInCircle(pt, Center: TPoint; Radius: Double): Boolean; static;

Returns True if the TPoint ‘pt’ is inside the circle


SRL.PointInEllipse

function TSRL.PointInEllipse(pt, Center:TPoint; YRad, XRad: Double): Boolean; static;

Returns True if the TPoint ‘pt’ is inside the ellipse


SRL.PointInPoly

function TSRL.PointInPoly(pt: TPoint; Poly: TPointArray): Boolean; static;

Check if a point is within a polygon/shape by the given outline points (poly) The points must be in order, as if you would draw a line trough each point.

Note

Uses winding number algorithm


SRL.PointInCuboid

function TSRL.PointInCuboid(pt: TPoint; Top, Btm: TRectangle): Boolean; static;

Check if a point is within a cuboid defined by top and bottom rectangle.