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


SRL.LinesIntersect#

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

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;

Returns true if the TPoint ‘Pt’ is in a rect (defined by four points).

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.