1. Re: Trig and the ...
- Posted by "BABOR, JIRI" <J.Babor at GNS.CRI.NZ> May 06, 1998
- 479 views
Pete Eberlein wrote: > speed = sqrt((xv*xv)+(yv*yv)) > if speed > maxspeed then > xv = xv* maxspeed / speed > yv = yv * maxspeed / speed > end if This is nice, straight forward and accurate. The square root operation is usually quite expensive, so I'll show you slightly faster, but more complicated way of calculating the scaling factor with sufficient accuracy. Instead of Pete's f = maxspeed / sqrt(xv*xv+yv*yv) you can try vvmax = maxspeed * maxspeed -- known, can be pre-calculated vv = xv*xv + yv*yv -- speed squared f = (vvmax+vv) / (vv+vv) I shall not bore you with the mathematics of it - unless, of course, you insist. Jiri