On a unit I used to be on at my Real Job they just did this:
Take the smaller of xlength or ylength, multiply it time 3, divide
by 2, and add the result to the larger of xlength or ylength. The
result is a close approximation of the square root of the sum of
the squares.
They needed to do it that way since they were doing it in hardware
at high speeds on a stream of data.
jeff hendrix wrote:
> I'm working hard to try and finish up space wars that will run on space duel
> hardware.
> I've got most things in it working, except I'm having trouble with the
> gravity.
> I'm implementing the following procedure:
>
> // calculate distance from the sun
> xLen = sunPos.x - objPos.x;
> yLen = sunPos.y - objPos.y;
> lengthsqr = (xLen * xLen) + (yLen * yLen);
> length = sqrt(lengthsqr);
> // calculate unit vector
> unitX = xLen / length;
> unitY = yLen / length;
> // gravity is inverse r squared
> unitX = unitX/lengthsqr;
> unitY = unitY/lengthsqr;
> // update object speed
> speed.x += unitX;
> speed.y += unitY;
>
> I have everything figured out except how to get the square root of
> lengthsqr.
> Is there any easy or fast way to calculate the square root of a 16 bit
> number on a 6502?
> Or is there another way to calculate the pull of gravity, separated into x
> and y components, that still follows the rule of the inverse of the square
> of the distance?
>
> -jeff
>
> ps. I might soon have a "incomplete" version that can be played on MAME.
Received on Wed Oct 27 17:02:15 1999
This archive was generated by hypermail 2.1.8 : Fri Aug 01 2003 - 00:32:47 EDT