Fw: Distance between 2 points
Oops, this was only sent to Patrat himself, so I forwarded it to the list.
(and yes, Patrat, I cleaned it up a bit)
>Hello,
>Does any1 know how to calulate the distance and angle from
>point A to point B given their coordinates.
>Thanks
So who's gonna supply us, with the variable dimension routines for angles ?
I know trig, but Im a bit confused about the angles and how sin () and cos()
work in Euphoria.
Any one has any faster suggestions for the sum function ?
Or shouldnt we start another speed/optimization thread ?
function sum (object x)
integer result
if sequence (x) then
result = 0
for index = 1 to length(x) do
result = result + sum (x[index])
end for
return result
else
return x
end for
end function
function distance (sequence a, sequence b)
return sqrt(sum(power(a - b,2)))
end function
-- Voila!
? distance ({ 2, 34, 5} , {3, 5434, 23))
? distance ({2,2} , {4, 4})
? distance ({ 23, 2534, 234, 23, 23}, {24, 23, 32}) -- Last two dimensions
are variable.
Ralf Nieuwenhuijsen
nieuwen at xs4all.nl
"They say truth will set you free, but they dont say how deep the cut will
be, suspicion and paranoia takes its place, and I cant hide!" -- Ten Foot
Pole
|
Not Categorized, Please Help
|
|