Re: Fw: Distance between 2 points

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ralf Nieuwenhuijsen wrote:
> >Hello,
> >Does any1 know how to calulate the distance and angle from
> >point A to point B given their coordinates.
> >Thanks
> 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

try this instead. 1 function call vs 3, should be worlds
faster for atoms and sequences both, i think...
   function distance(object a, object b)
      return sqrt( (a*a)+(b*b) )
   end function
and something that should be benchmarked against the
above 2 distance() functions as well should be:
   function distance(object a, object b)
      return power( (a*a)+(b*b),0.5 )
   end function
to see if power is faster than sqrt.

will work on angle later...
--Hawke'

p.s. see carl? i learning :>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu