1. Re: Trig and the ...

Pete Eberlein wrote:

>On Wed, 6 May 1998, BABOR, JIRI wrote:
>> 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
>
>
>This is pretty cool, and has an absolute error of 0 to -0.5, which I deem
>acceptable for game arithmetic.  Where did you learn that trick, Jiri?
>Bore me, I insist :)

I did not learn that trick anywhere, I just derived it. And since you
insist, it goes something like this:

1. There is almost always a faster way than square root or arctan smile
2.  Using the same symbols as above:

    f = maxspeed / speed = sqrt( maxspeed*maxspeed / speed*speed )

    f = sqrt(vvmax / vv) = sqrt( 1 - (vv-vvmax)/vv )

Are you still with me? Let's make it visually a little bit simpler:

    e = (vv-vvmax)/vv

Then

    f = sqrt( 1-e )

Now the jump: if e is *relatively* small then, approximately

    f = sqrt( 1-e ) = sqrt( (1 - e/2)(1 - e/2) ) = 1 - e/2

simply from

    (1-e/2)(1-e/2) = 1 - e + e*e/4

neglecting the (small) last term.  Jiri

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu