Module moonMath

Remove multiple occurrences of pairs { {x, y}, {x, y} }.

Functions

addPoint (t, x, y) Adds a point to a table.
removeDuplicatePointsFlat (t) Remove duplicates from a flat table.
validateNumber (n) checks if a number is valid
getGreatestPoint (points, offset) Gets the greatest/least points with an offset
isWithinBounds (min, n, max) Checks if a number is within given bounds
distance2 (x1, y1, x2, y2) calculates the distance between two points
getQuadraticRoots (a, b, c, table) Math gets the quadratic roots of an equation
rotatePoint (x, y, rot, ox, oy) Rotate a point [tested]
scalePoint (x, y, scale, ox, oy) scales a point [tested]
polarToCartesian (radius, theta, offsetRadius, offsetTheta) From polar to cartesian [tested]
cartesianToPolar (x, y, ox, oy) From cartesian to polar [tested]
getLength (x1, y1, x2, y2) Gets the leght of a line
getMidPoint (x1, y1, x2, y2) gets the midpoint of a line
getSlope (x1, y1, x2, y2) gets the slope of a line
getPerpendicularSlope (input) gives the perpendicular slope of a line
getYIntercept (x, y, ...) gets the y-intercept of a line
getLineLineIntersection (...) gets the intersection of two lines
getClosestPoint (...) gets the closest point on a line to a point
getLineSegmentIntersection (...) gets the intersection of a line and a line segment
checkLinePoint (x, y, x1, y1, x2, y2) checks if a point is on a line
getCircleLineIntersection (circleX, circleY, radius, x1, y1, x2, y2) gets the intersection of a line and a circle
getPolygonLineIntersection (x1, y1, x2, y2, ...) checks whether or not a line intersects a polygon
getPerpendicularBisector (x1, y1, x2, y2) gets the perpendicular bisector of a line (https://www.youtube.com/watch?v=A86COO8KC58)
checkSegmentPoint (px, py, x1, y1, x2, y2) checks hether or not a point lies on a line segment
addPoints (t, x, y) adds point to a table
getSegmentSegmentIntersection (x1, y1, x2, y2, x3, y3, x4, y4) gets the point of intersection between two line segments
isPointOnCircle (x, y, circleX, circleY, radius) checks if a point is on a circle
checkCirclePoint (x, y, circleX, circleY, radius) checks if a point is within the radius of a circle
getCircleSegmentIntersection (circleX, circleY, radius, x1, y1, x2, y2) gets the type of intersection of a line segment
getPolygonSegmentIntersection (x1, y1, x2, y2, ...) checks if the line segment intersects the polygon
isSegmentCompletelyInsideCircle (circleX, circleY, circleRadius, x1, y1, x2, y2) checks if a line-segment is entirely within a circle
checkPolygonPoint (px, py, ...) checks if the point lies inside the polygon not on the polygon
isSegmentCompletelyInsidePolygon (x1, y1, x2, y2, ...) checks if a segment is completely inside a polygon
getLineSegmentIntersection (...) gets the intersection of a line and a line segment


Functions

addPoint (t, x, y)
Adds a point to a table.

Parameters:

  • t table
  • x number
  • y number

Returns:

    table t
removeDuplicatePointsFlat (t)
Remove duplicates from a flat table.

Parameters:

Returns:

    table newt Byg Fixed see issue : https://github.com/davisdude/mlib/issues/17
validateNumber (n)
checks if a number is valid

Parameters:

  • n number

Returns:

    bool validity
getGreatestPoint (points, offset)
Gets the greatest/least points with an offset

Parameters:

  • points table
  • offset number

Returns:

    table {greatest, least}
isWithinBounds (min, n, max)
Checks if a number is within given bounds

Parameters:

  • min number
  • n number
  • max number

Returns:

    bool
distance2 (x1, y1, x2, y2)
calculates the distance between two points

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    number
getQuadraticRoots (a, b, c, table)
Math gets the quadratic roots of an equation

Parameters:

  • a number
  • b number
  • c number
  • table number
rotatePoint (x, y, rot, ox, oy)
Rotate a point [tested]

Parameters:

  • x number
  • y number
  • rot number
  • ox number
  • oy number

Returns:

    table {x, y}
scalePoint (x, y, scale, ox, oy)
scales a point [tested]

Parameters:

  • x number
  • y number
  • scale number
  • ox number
  • oy number

Returns:

    table {x, y}
polarToCartesian (radius, theta, offsetRadius, offsetTheta)
From polar to cartesian [tested]

Parameters:

  • radius number
  • theta number
  • offsetRadius number
  • offsetTheta number

Returns:

    table {x, y}
cartesianToPolar (x, y, ox, oy)
From cartesian to polar [tested]

Parameters:

  • x number
  • y number
  • ox number
  • oy number

Returns:

    table {radius, theta}
getLength (x1, y1, x2, y2)
Gets the leght of a line

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    number
getMidPoint (x1, y1, x2, y2)
gets the midpoint of a line

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    number
getSlope (x1, y1, x2, y2)
gets the slope of a line

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    number
getPerpendicularSlope (input)
gives the perpendicular slope of a line

Parameters:

  • input table {x1, y1, x2, y2} or slope

Returns:

    slope
getYIntercept (x, y, ...)
gets the y-intercept of a line

Parameters:

  • x number
  • y number
  • ... table {x2, y2} or slope

Returns:

    table {number, bool}
getLineLineIntersection (...)
gets the intersection of two lines

Parameters:

  • ... table {slope1, slope2, x1, y1, x2, y2} or {slope1, intercept1, slope2, intercept2} or {x1, y1, x2, y2, x3, y3, x4, y4}

Returns:

    table {x, y}
getClosestPoint (...)
gets the closest point on a line to a point

Parameters:

  • ... table {perpendicularX, perpendicularY, x1, y1, x2, y2} or {perpendicularX, perpendicularY, slope, intercept}

Returns:

    table {x, y}
getLineSegmentIntersection (...)
gets the intersection of a line and a line segment

Parameters:

  • ... table {x1, y1, x2, y2, x3, y3, x4, y4} or {x1, y1, x2, y2, slope, intercept}

Returns:

    table {x, y}
checkLinePoint (x, y, x1, y1, x2, y2)
checks if a point is on a line

Parameters:

  • x number
  • y number
  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    bool
getCircleLineIntersection (circleX, circleY, radius, x1, y1, x2, y2)
gets the intersection of a line and a circle

Parameters:

  • circleX number
  • circleY number
  • radius number
  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    table { ratio, ... }
getPolygonLineIntersection (x1, y1, x2, y2, ...)
checks whether or not a line intersects a polygon

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number
  • ... number

Returns:

    bool
getPerpendicularBisector (x1, y1, x2, y2)
gets the perpendicular bisector of a line (https://www.youtube.com/watch?v=A86COO8KC58)

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    midx, midy, perpendicularSlope
checkSegmentPoint (px, py, x1, y1, x2, y2)
checks hether or not a point lies on a line segment

Parameters:

  • px number
  • py number
  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    bool
addPoints (t, x, y)
adds point to a table

Parameters:

  • t table
  • x number
  • y number
getSegmentSegmentIntersection (x1, y1, x2, y2, x3, y3, x4, y4)
gets the point of intersection between two line segments

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number
  • x3 number
  • y3 number
  • x4 number
  • y4 number

Returns:

    bool
isPointOnCircle (x, y, circleX, circleY, radius)
checks if a point is on a circle

Parameters:

  • x number
  • y number
  • circleX number
  • circleY number
  • radius number

Returns:

    bool
checkCirclePoint (x, y, circleX, circleY, radius)
checks if a point is within the radius of a circle

Parameters:

  • x number
  • y number
  • circleX number
  • circleY number
  • radius number

Returns:

    bool
getCircleSegmentIntersection (circleX, circleY, radius, x1, y1, x2, y2)
gets the type of intersection of a line segment

Parameters:

  • circleX number
  • circleY number
  • radius number
  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    table {circularSeg, ...}
getPolygonSegmentIntersection (x1, y1, x2, y2, ...)
checks if the line segment intersects the polygon

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number
  • ... number

Returns:

    bool
isSegmentCompletelyInsideCircle (circleX, circleY, circleRadius, x1, y1, x2, y2)
checks if a line-segment is entirely within a circle

Parameters:

  • circleX number
  • circleY number
  • circleRadius number
  • x1 number
  • y1 number
  • x2 number
  • y2 number

Returns:

    bool
checkPolygonPoint (px, py, ...)
checks if the point lies inside the polygon not on the polygon

Parameters:

  • px number
  • py number
  • ... number

Returns:

    bool
isSegmentCompletelyInsidePolygon (x1, y1, x2, y2, ...)
checks if a segment is completely inside a polygon

Parameters:

  • x1 number
  • y1 number
  • x2 number
  • y2 number
  • ... table

Returns:

    bool
getLineSegmentIntersection (...)
gets the intersection of a line and a line segment

Parameters:

  • ... table {x1, y1, x2, y2, x3, y3, x4, y4} or {x1, y1, x2, y2, slope, intercept}

Returns:

    table {x, y}
generated by LDoc 1.5.0 Last updated 2023-06-17 16:37:22