Re: A83: Calculating Distances Fast - any suggestions ?


[Prev][Next][Index][Thread]

Re: A83: Calculating Distances Fast - any suggestions ?





Since I really dont think there is a very good approximation
algorithm for distance (without tons of iterations), perhaps you can
attack the problem in a different manner.  For instance, I doubt when
drawing the lines for the vector based system you really need to know the
length of a straight line between the two points.

I would suggest in your "drawing loop" you increment parallel counters for
X and Y using the slope of the line which could be easily calculated
beforehand. ie. X would increment by one, whereas Y would increment by
abs((y1-y0)/(x1-x0))

you have probably already considered this, but from my experience the
simplest solutions are usually the best ones.

-harper

On Tue, 23 May 2000 AutismUK@aol.com wrote:

> 
> Hi.
> 
> I'm working on a 3D vector graphics engine at the moment ; still not
> sure what it'll be used for. It is a "fix" approximation, but a pretty good
> one.
> 
> I wondered if anyone knew a fast decent approximation to the distance
> calculation Sqrt(x^2+y^2). At present I'm using (|x|+|y|)/2 which is okay
> when objects are roughly scattered, but tends to stuff up any straight
> lines, drawing a boxed outline of objects this approximation morphs it
> into a "star" shape. I don't really want to multiply if possible so
> a couple of iterations of Newton-Rhapson are out.
> 
> Paul Robson.
> 
> 




Follow-Ups: References: