Click to See Complete Forum and Search --> : any mathematichians out there?


thoand
04-12-2004, 10:30 PM
Can you help me with a simple formular, I droped math at school ;)

I am drawing a line on a map,

the first point is

startX, the starting x cordinate of the line
startY, the starting y cordinate of the line

and the second is

endX, the ending x cordinate of the line
endY, the ending y cordinate of the line

how do I do the math to calculate the length of the line, eg how long it is ?

best regards Thomas

goldbug
04-12-2004, 10:51 PM
a^2 + b^2 = c^2

or, if you use your coords:
(forgive my odd notation)


$hypotenuse = sqrt(pow(abs($x1 - $x2),2) + pow(abs($y1 - $y2),2));

mtimdog
04-13-2004, 08:28 AM
Not to be nitpicky, but since the values are being squared the absolute value of the differences is a wasted step.

thoand
04-13-2004, 08:53 AM
Thanks to goldbug for giving me the formular

a^2 + b^2 = c^2

I realy needed it for a Flash movie and did:


/* Pythagorean theorem -> a^2 + b^2 = c^2
hypotenuse = Math.sqrt((startX - endX) * (startX - endX) + (startY - endY) * (startY - endY));

It worked fine

regards Thomas

goldbug
04-13-2004, 10:08 AM
Originally posted by mtimdog
Not to be nitpicky, but since the values are being squared the absolute value of the differences is a wasted step.

Heh, good catch... next time I won't write out formulas when I'm drowsy :D