-----------------------------------
xmen
Fri Mar 26, 2004 4:35 pm
Math.Distance????????
-----------------------------------
wut is it??
cuz when i tried out some programs from this forum it gaves me this error "'Distance' is not in the export of 'Math'"
so wuts the problem??
or is there other syntax that can represent Math.Distance??
p.s.: my program is about balls bouncing with ball collisions
-----------------------------------
Tony
Fri Mar 26, 2004 4:37 pm
-----------------------------------
Math.Distance returns the distance between two points on a 2D plane.
you need turing v4.0.5 to use it. Link is up on MX page
-----------------------------------
recneps
Fri Mar 26, 2004 7:34 pm
-----------------------------------
or just use the distance formula (where x1,y1 is point 1 and x2,y2 is point2)
d=((x2-x1)**2+(y2-y1)**2)**0.5
**2 is same as squared and **0.5 is same as sqrt :)
-----------------------------------
Cervantes
Sat Mar 27, 2004 10:39 am
-----------------------------------
easiest thing to do is insert this snipit of code into your program (preferably near the top: before any time you want to use Math.Distance)
function MathDistance (x1, y1, x2, y2 : int) : int
result round ((((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5))
end MathDistance
now whenever you want to use Math.Distance, you can. just take out the "."
eg.
function MathDistance (x1, y1, x2, y2 : int) : int
result round ((((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5))
end MathDistance
for i : 1 .. 300
drawfilloval (300, 100, 15, 15, red)
drawfilloval (300, i, 15, 15, black)
delay (10)
exit when MathDistance (300, 100, 300, i)