Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Math.Distance????????
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xmen




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
recneps




PostPosted: 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
Cervantes




PostPosted: 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
Tony




PostPosted: 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 Rolling Eyes

and btw - if you're writing your own function, use (x2-x1)*(x2-x1) instead of **2. It is faster that way Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Cervantes




PostPosted: 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?? ThinkingConfusedThinking
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
sport




PostPosted: Sat Mar 27, 2004 6:59 pm   Post subject: (No subject)

a squared=a*a
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: