
-----------------------------------
Homer_simpson
Mon May 05, 2003 9:23 pm

Distanse formula
-----------------------------------
ok here's how you caclulate the distanse between 2 dots
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
Mon May 05, 2003 9:53 pm


-----------------------------------
ok i just found the code but it's in C++ and i can't  turn it into turing 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
Mon May 05, 2003 10:05 pm


-----------------------------------
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 :)

-----------------------------------
Homer_simpson
Mon May 05, 2003 10:14 pm


-----------------------------------
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
Mon May 05, 2003 10:33 pm


-----------------------------------
are you looking for a normal?

-----------------------------------
Homer_simpson
Tue May 06, 2003 7:25 am


-----------------------------------
a normal what?

-----------------------------------
Homer_simpson
Tue May 06, 2003 1:43 pm


-----------------------------------
maybe this would help ya
http://www.npac.syr.edu/REU/reu94/williams/ch1/subsection3_2_6.html

-----------------------------------
AsianSensation
Wed May 07, 2003 9:59 pm


-----------------------------------
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
Wed May 07, 2003 10:20 pm


-----------------------------------
ah yes... i know all about how to do it on peace of paper  :roll:  :roll:  :roll: 

but i dunno how to write it in turing code ='(

-----------------------------------
Tony
Wed May 07, 2003 10:47 pm


-----------------------------------
take all your formulas and type them into turing, replacing numbers with variables...

-----------------------------------
Homer_simpson
Wed May 07, 2003 10:52 pm


-----------------------------------
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....
