Try my new website:
www.urcho.com
- the new SIMPLE social network
Sign up
|
357
members |
125
snippets
Search for:
ALL
POPULAR
File Controls
Multiplayer Code
2D Effects
3D Effects
Oldskool demos
Basic Functions
Maths/Physics
Sound
Tutorials
Misc
Username:
Password:
Sign up
Useful functions
[
back
]
Author:
Nullium
| Viewed:
1638
times | Language:
BlitzMax
| Category:
Maths/Physics
Function GetDistance:Float(x1:Float,y1:Float,x2:Float,y2:Float) Return(Sqr(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)))) ' returns a 'faster' distance formula End Function Function GetAngle:Float(x1:Float,y1:Float,x2:Float,y2:Float) Return((ATan2((y2 - y1),(x2 - x1)) + 360) Mod 360) ' returns the angle from one point to another, in the range from 0 - 360 (i think?) End Function Function DistanceToLine:Float(x1:Float,y1:Float,x2:Float,y2:Float,px:float,py:float) Return(((y1 - py) * (x2 - x1)) + ((px - x1) * (y2-y1))) / Sqr(((y2 - y1) * (y2 - y1)) + ((x2 - x1) * (x2 - x1))) ' returns the distance from a point to a line End Function
Author Comments:
Here are some random functions that many people find very useful, but have to look up everytime they need it. ;)
Login or
create an account
to comment on this snippet