I found my old cheat-sheet from when I started my current project about a year or so ago...
<u>Basic 2D Math Functions</u>
Find Velocity:
[pascal]VelX := power * cos(Pi * AngleInRadians);
VelY := power * sin(Pi * AngleInRadians);[/pascal]
Find Distance Between Two Points:
[pascal]Distance := sqrt(sqr(x2 - x1) + sqr(y2 - y1));[/pascal]
Find Rotation:
[pascal]NewX := cos(AngleInRadians) * OldX - sin(AngleInRadians) * OldY;
NewY := sin(AngleInRadians) * OldX + cos(AngleInRadians) * OldY;[/pascal]
Find Angle From One Point To Another:
[pascal]Angle := ArcCos((x2 - x1) / Distance);[/pascal]
You should be able to do quite a bit with these. You should however consider optimizing them a bit. Functions like sqrt and ArcCos cost quite a bit of cpu speed, but at least you can substitute something like [pascal]z := sqr(x);[/pascal] with [pascal]z := x * x;[/pascal]
I hope this is generally useful.
Bookmarks