Math

Math related methods


srl.Modulo

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

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.Modulo (overload)

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

Integer overload for Modulo.


srl.CrossProduct

function TSRL.CrossProduct(ry,ry, px,py, qx,qy: Double): Double;

Cross-product of rp and rq vectors.


srl.CrossProduct (overload)

function TSRL.CrossProduct(r, p, q: TPoint): Int64; overload;

Cross-product of rp and rq vectors.


srl.DeltaAngle

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

Returns the shortest difference between two given angles.


srl.DistToLine

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

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;

srl.PointInTriangle

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

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;

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;

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


srl.PointInEllipse

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

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


srl.PointInPoly

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

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;

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