Home

Awesome

MLib

MLib is a math and shape-intersection detection library written in Lua. It's aim is to be robust and easy to use.

NOTE:

If you are looking for a library that handles updating/collision responses for you, take a look at hxdx. It uses MLib functions as well as Box2d to handle physics calculations.

Downloading

You can download the latest stable version of MLib by downloading the latest release. You can download the latest working version of MLib by downloading the latest commit. Documentation will only be updated upon releases, not upon commits.

Implementing

To use MLib, simply place mlib.lua inside the desired folder in your project. Then use the require 'path.to.mlib' to use any of the functions.

Examples

If you don't have LÖVE installed, you can download the .zip of the demo from the Executables folder and extract and run the .exe that way. You can see some examples of the code in action here. All examples are done using the awesome engine of LÖVE. To run them properly, download the .love file and install LÖVE to your computer. After that, make sure you set .love files to open with "love.exe". For more, see here.

When should I use MLib?

When should I not use MLib?

Specs

Alternatively, you can find the tests here. Keep in mind that you may need to change certain semantics to suit your OS. You can run them via Telescope and type the following command in the command-line of the root folder:

tsc -f specs.lua

If that does not work, you made need to put a link to Lua inside of the folder for telescope and run the following command:

lua tsc -f specs.lua

If you encounter further errors, try to run the command line as an administrator (usually located in C:\Windows\System32\), then right-click on cmd.exe and select Run as administrator, then do

cd C:\Path\to\telescope\

And then run one of the above commands. If none of those work, just take my word for it that all the tests pass and look at this picture. ![Success](Reference Pictures/Success.png)

Functions

mlib.line

mlib.line.checkPoint
mlib.line.getClosestPoint
mlib.line.getYIntercept
mlib.line.getIntersection
mlib.line.getLength
mlib.line.getMidpoint
mlib.line.getPerpendicularSlope
mlib.line.getSegmentIntersection
mlib.line.getSlope

mlib.segment

mlib.segment.checkPoint
mlib.segment.getPerpendicularBisector
mlib.segment.getIntersection

mlib.polygon

mlib.polygon.checkPoint
mlib.polygon.getCentroid
mlib.polygon.getCircleIntersection
local tab = _.polygon.getCircleIntersection( 5, 5, 1, 4, 4, 6, 4, 6, 6, 4, 6 )
for i = 1, # tab do
	print( i .. ':', unpack( tab[i] ) )
end
-- 1: 	tangent		5		4
-- 2: 	tangent		6 		5
-- 3: 	tangent 	5		6
-- 4: 	tagnent 	4		5
mlib.polygon.getLineIntersection
mlib.polygon.getPolygonArea
mlib.polygon.getPolygonIntersection
mlib.polygon.getSegmentIntersection
mlib.polygon.getSignedPolygonArea
mlib.polygon.getTriangleHeight
mlib.polygon.isCircleInside
mlib.polygon.isCircleCompletelyInside
mlib.polygon.isPolygonInside
mlib.polygon.isPolygonCompletelyInside
mlib.polygon.isSegmentInside
mlib.polygon.isSegmentCompletelyInside

mlib.circle

mlib.circle.checkPoint
mlib.circle.getArea
mlib.circle.getCircleIntersection
mlib.circle.getCircumference
mlib.circle.getLineIntersection
mlib.circle.getSegmentIntersection
mlib.circle.isCircleCompletelyInside
mlib.circle.isCircleCompletelyInsidePolygon
mlib.circle.isPointOnCircle
mlib.circle.isPolygonCompletelyInside

mlib.statistics

mlib.statistics.getCentralTendency
mlib.statistics.getDispersion
mlib.statistics.getMean
mlib.statistics.getMedian
mlib.statistics.getMode
mlib.statistics.getRange
mlib.statistics.getStandardDeviation
mlib.statistics.getVariance
mlib.statistics.getVariationRatio

mlib.math

mlib.math.getAngle
mlib.math.getPercentage
mlib.math.getPercentOfChange
mlib.math.getQuadraticRoots
mlib.math.getRoot
local a = mlib.math.getRoot( 4, 2 ) -- Same as saying 'math.pow( 4, .5 )' or 'math.sqrt( 4 )' in this case.
local b = mlib.math.getRoot( 27, 3 )

print( a, b ) --> 2, 3
mlib.math.getSummation
mlib.math.isPrime
mlib.math.round

Aliases

AliasCorresponding Function
milb.line.getDistancemlib.line.getLength
mlib.line.getCircleIntersectionmlib.circle.getLineIntersection
milb.line.getPolygonIntersectionmlib.polygon.getLineIntersection
mlib.line.getLineIntersectionmlib.line.getIntersection
mlib.segment.getCircleIntersectionmlib.circle.getSegmentIntersection
milb.segment.getPolygonIntersectionmlib.pollygon.getSegmentIntersection
mlib.segment.getLineIntersectionmlib.line.getSegmentIntersection
mlib.segment.getSegmentIntersectionmlib.segment.getIntersection
milb.segment.isSegmentCompletelyInsideCirclemlib.circle.isSegmentCompletelyInside
mlib.segment.isSegmentCompletelyInsidePolygonmlib.polygon.isSegmentCompletelyInside
mlib.circle.getPolygonIntersectionmlib.polygon.getCircleIntersection
mlib.circle.isCircleInsidePolygonmlib.polygon.isCircleInside
mlib.circle.isCircleCompletelyInsidePolygonmlib.polygon.isCircleCompletelyInside
mlib.polygon.isCircleCompletelyOvermlib.circleisPolygonCompletelyInside

License

zlib license. See LICENSE.md