Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Distanse formula
Author Message
Homer_simpson

Posted: Mon May 05, 2003 9:23 pm   Post subject: Distanse formula

ok here's how you caclulate the distanse between 2 dots
 code: function distance (x1, y1, x2, y2 : int) : int     result round (((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5) end distance

But can some1 gimme a formula for caclulating the distanse between a line and a dot(knowing that the closest distanse from a xline to a dot is when a line with right angle is drawn toward the xline)

Homer_simpson

Posted: Mon May 05, 2003 9:53 pm   Post subject: (No subject)

ok i just found the code but it's in C++ and i can't turn it into turing code
 code: // dist_Point_to_Line(): get the distance of a point to a line. //    Input:  a Point P and a Line L (in any dimension) //    Return: the shortest distance from P to L float dist_Point_to_Line( Point P, Line L) {     Vector v = L.P1 - L.P0;     Vector w = P - L.P0;     double c1 = dot(w,v);     double c2 = dot(v,v);     double b = c1 / c2;     Point Pb = L.P0 + b * v;     return d(P, Pb); }
can any one atleast do that for me?
Tony

Posted: Mon May 05, 2003 10:05 pm   Post subject: (No subject)

well perpendicular line is a negative reciprocal (is that how you spell it?) Mod Edit: Nope. Fixed it. -Asok That's wrong too...fixed it -Darkness
so slope of the line is (y2-y1)/(x2-x1).

slope of perpendicular line is

-(x2-x1)/(y2-y1)

so now you have a line and a line through a point.

There's a way to find where those two lines intersect... I just cant recall right away. Look it up in math 10 textbook.

Now you have two points and you already know how to find the distance between them
Tony's programming blog. DWITE - a programming contest.
Homer_simpson

Posted: Mon May 05, 2003 10:14 pm   Post subject: (No subject)

i know what yer saying tony and i thought of that before and i know how to find the intersection between 2 lines you gotto put the 2 formulas under eachother and then cross the things out so you'll get one of the coordinates but i have no idea how to do that in turing :S
Catalyst

Posted: Mon May 05, 2003 10:33 pm   Post subject: (No subject)

are you looking for a normal?
Homer_simpson

Posted: Tue May 06, 2003 7:25 am   Post subject: (No subject)

a normal what?
Homer_simpson

Posted: Tue May 06, 2003 1:43 pm   Post subject: (No subject)

maybe this would help ya
http://www.npac.syr.edu/REU/reu94/williams/ch1/subsection3_2_6.html
AsianSensation

Posted: Wed May 07, 2003 9:59 pm   Post subject: (No subject)

from a point to a line:

set up a equation with the negative reciprocal slope out in variable form. then you need to solve for some variable I assume, then just shift everything to one side(or do operations to both sides for all you math technicality freaks), and isolate the variable you are solving for. Plug in the numbers, then you can get the answer, store in a real or integer variable.

Technically, it's not letting the computer doing stuff for you, you actually have to think(The Horror!), but it much more effective this way, and less likely that you will include an error in the calculation.

Homer_simpson

Posted: Wed May 07, 2003 10:20 pm   Post subject: (No subject)

ah yes... i know all about how to do it on peace of paper

but i dunno how to write it in turing code ='(
Tony

Posted: Wed May 07, 2003 10:47 pm   Post subject: (No subject)

take all your formulas and type them into turing, replacing numbers with variables...
Tony's programming blog. DWITE - a programming contest.
Homer_simpson

Posted: Wed May 07, 2003 10:52 pm   Post subject: (No subject)

Belive me i spent more than 2 hours trying to do that but when it comes to putting 2 formulas equal to eachother i dunno what to do..... hmmmmm.... hold on i just got an idea....
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 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: