Math.Distance????????
Author |
Message |
xmen
|
Posted: Fri Mar 26, 2004 4:35 pm Post subject: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Fri Mar 26, 2004 4:37 pm Post subject: (No subject) |
|
|
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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
recneps
![](http://www.fcpocanada.com/canada1.gif)
|
Posted: Fri Mar 26, 2004 7:34 pm Post subject: (No subject) |
|
|
or just use the distance formula (where x1,y1 is point 1 and x2,y2 is point2)
code: | d=((x2-x1)**2+(y2-y1)**2)**0.5
|
**2 is same as squared and **0.5 is same as sqrt ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Mar 27, 2004 10:39 am Post subject: (No subject) |
|
|
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)
code: |
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.
code: |
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) <= 30
drawfilloval (300, i, 15, 15, white)
end for
|
|
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sat Mar 27, 2004 1:34 pm Post subject: (No subject) |
|
|
aggrr... I think you're all missing the point that Distance is a function of the new Math module found in turing v4.0.5
and btw - if you're writing your own function, use (x2-x1)*(x2-x1) instead of **2. It is faster that way ![Wink Wink](images/smiles/icon_wink.gif) |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Mar 27, 2004 2:34 pm Post subject: (No subject) |
|
|
oh i understand that perfectly. I was just providing another option if he doesn't want to download 4.0.5.
and just a question. how is multiplying it by itself faster than squaring it? if you square it does the prog have to go back a bit to remember what its squareing or something?? ![Thinking Thinking](http://compsci.ca/v3/images/smiles/eusa_think.gif) ![Confused Confused](images/smiles/icon_confused.gif) ![Thinking Thinking](images/smiles/eusa_think.gif) |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Sat Mar 27, 2004 3:16 pm Post subject: (No subject) |
|
|
it's just the way ** operator works. It's not simple multiplication to account for decimal places, so the function ends up taking longer to execute then a simple multiplication. If you want, set up a test case for each, time it and see how much faster one is over the other |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
sport
![](http://www.members.shaw.ca/rfolz/e17661eqn7y.jpg)
|
Posted: Sat Mar 27, 2004 6:59 pm Post subject: (No subject) |
|
|
a squared=a*a |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|