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)






Sponsor Sponsor



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 (y2y1)/(x2x1).
slope of perpendicular line is
(x2x1)/(y2y1)
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





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






