Source: https://love2d.org/forums/viewtopic.php?t=36552&amp
Timestamp: 2019-04-23 15:57:41+00:00

Document:
NOTE: This thread has been moved to here!
MLib is a math and collisions library.
Check out the GitHub to see more information.
v. 2.0.0 -Made mlib.shape and made numberous bug fixes.
v. 1.9.4 -Made mlib.math.prime faster and removed ability to test multiple numbers at once. Thanks Robin!
v. 1.9.2 -Updated to 0.9.0.
v. 1.9.1 -Made mlib.line.closestPoint able to take either two points on the slope or the slope and intercept.
v. 1.8.3 -Changed naming mechanism to be more organized.
v. 1.8.2 -"Fixed" mlib.lineSegmentsIntersect AGAIN!!!!
v. 1.8.1 -Removed a print statement.
v. 1.7.1 -mlib.lineSegmentsIntersect now returns the two places in between where the line segments begin to intersect.
v. 1.6.1 -Employed usage of summations for mlib.getPolygonArea and mlib.getPolygonCentroid and removed area as an argument for mlib.getPolygonCentroid.
v. 1.6.0 -Added several functions.
v. 1.5.0 -Made lots of changes to syntax to make it easier to use (hopefully). I also put out specs.
v. 1.4.1 -Localized mlib. Thanks, Yonaba!
v. 1.3.2 -Made mlib.getPrime take tables as arguments, so you can check all the values of a table.
v. 1.3.0 -Added mlib.get_polygon_area and removed mlib.get_convex_area and mlib.get_triangle_area since they are repetitive.
v. 1.2.2 -Made functions return faster, functions that previously returned tables now return multiple arguments.
v. 1.2.1 -Localized functions, made tables acceptable as arguments, refined function speed, mlib.get_mode now returns number most repeated as well as how many times.
v. 1.0.4 -Fixed get_mode to handle bimodials.
Last edited by davisdude on Tue Dec 23, 2014 6:13 pm, edited 64 times in total.
Why would the prime function return nil if it's true? That's just unpractical.
Yeah, I tried that before. Somehow, it didn't work. Sorry it took so long to reply. I sort of forgot to reply.
Last edited by davisdude on Mon Nov 11, 2013 2:15 am, edited 1 time in total.
I know it's a bit quick on the draw, but while I was waiting I went ahead and did mlib.get_convex_area( ... ) because I can't stand doing nothing.
I'm also currently working on mlib.get_concave_area( ... ), but I'm still working on a formula. If you know please don't tell me. I want to try getting it on my own.
Amazing library! Ive thoroughly abused the quickness of get_distance in about 95% of my projects.
In a project i have a player. The player is made using love.physics.
I needed this player to ALLWAYS be facing the direction of the mouse. Sadly looking around for a get Angle Between Two Known Points didnt turn out well.
I did find the dotProduct method, but on implementing it , i had strange bugs and no idea why i failed at it.
Later i thought up my on method thanks to the sine-rule of triangles.
Anyhow on to the ACTUALK request, could you perhaps provide a function that takes 2 points ([x],[y],optional [z]) and provides the angle between those two points? Im sure this would be helpful to others!
ArchAngel075 wrote: Anyhow on to the ACTUALK request, could you perhaps provide a function that takes 2 points ([x],[y],optional [z]) and provides the angle between those two points? Im sure this would be helpful to others!
As for 3d, you would normally get two angles: azimuth and bearing. Bearing is obtained via X and Y coordinates only, as the name suggests. Azimuth is obtained via same function, using Z as dy, and the magnitude of XY vector as dx.
I'm glad you like my library!
I will work on that function. It shouldn't take too long, I'll post it when I'm available.
On a side note, your bugs might have been caused by using degrees instead of radians.
Updated! Check out the readme on GitHub (link in original post) on how to use!
By the way, I'm now accepting formula for concave area at this point. I tried, and it's HARD!
thanks for the angle function!
Btw, looking at your functions ive noticed you use the default screen width/height... Yet some projects may change the width/height.
Perhaps its best to write it to use the love.graphics.getWidth/Height by default? This not technically break anything and only requires some swapping out.
davisdude wrote: I know it's a bit quick on the draw, but while I was waiting I went ahead and did mlib.get_convex_area( ... ) because I can't stand doing nothing.
Should be able to do in 8 lines of code (or less).

References: v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v. 

v.