Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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

Tony

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.
recneps

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
Cervantes

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
Tony

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
Tony's programming blog. DWITE - a programming contest.
Cervantes

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??
Tony

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.
sport

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

a squared=a*a
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 8 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: