Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: squidgetx on March 27, 2011, 04:20:33 pm

Title: Trig Challenge....
Post by: squidgetx on March 27, 2011, 04:20:33 pm
All right.

We've got an X-velocity (v) , and a Y-velocity (w) that can both get pretty large (ie, past 256). What's the best way to calculate the total speed (a scalar number) while maintaining at least some accuracy? Pythagorean theorem is out because squaring a number greater than 255 will go over our 65535 limit. (If anyone wants to give me assembly hex that's cool too :))
Title: Re: Trig Challenge....
Post by: Ashbad on March 27, 2011, 04:22:21 pm
Well, does it have to be in some specific format?  If not:

W + V
------
   2

:P
Title: Re: Trig Challenge....
Post by: squidgetx on March 27, 2011, 04:23:02 pm
lol, is that actually a semi-accurate replacement?  O.O

edit: err, i don't think so lol
Title: Re: Trig Challenge....
Post by: Ashbad on March 27, 2011, 04:27:29 pm
well, like I said, it's not in a specific format.  I'll need to know exactly what you're after, if I'm gonna find a solution.

You want average speed, total speed, summed speed, directional speed, sloped speed...? ???
Title: Re: Trig Challenge....
Post by: squidgetx on March 27, 2011, 04:29:04 pm
basically, find square root of v^2+w^2 without using that formula.
Title: Re: Trig Challenge....
Post by: Ashbad on March 27, 2011, 04:35:18 pm
ahh, some form of the distance formula... for speed instead though.

here's one thing to consider, however:  the ratio of v + w to sqrt(v^2 + w^2) is roughly .725... .  I tested this with many numbers before, so I can safely assure you that

5(v + w)
---------
    7

is an extremely fast and accurate subsitute.

EDIT: a slower but even more accurate replacement:

51(v + w)
---------
    70
Title: Re: Trig Challenge....
Post by: squidgetx on March 27, 2011, 04:56:25 pm
Crap, problem: if y=0 and x=70, then that formula yields 51 :( I don't think linear representations will be able to do the trick...
Title: Re: Trig Challenge....
Post by: Ashbad on March 27, 2011, 05:00:47 pm
interesting..  The thing is, why not have 3 different possible equations?  One that works for small numbers, one for large ones, and one for sets where one or both answers are 0?
Title: Re: Trig Challenge....
Post by: squidgetx on March 27, 2011, 05:01:32 pm
That's what I'm doing now lol
Title: Re: Trig Challenge....
Post by: AngelFish on March 27, 2011, 08:36:40 pm
Okay, I after a little bit of thinking and some multivariate analysis, the linear function that most closely approximates the function sqrt(x^2+x^2) over the entire interval is 4266.6486024 + 0.70320236774X + 0.67608766999Y. There's some error and the equation probably isn't optimal, but it should be reasonably close to the best possible linear approximation.

Keep in mind that this is over the entire interval. There will probably be some oddities near 0.
Title: Re: Trig Challenge....
Post by: Ashbad on March 27, 2011, 09:10:44 pm
But, also since this will be transferred to code anyways, this might also work as well:

(W*5-(W*5*(W=0))+(V*5-(V*5(V=0)))
--------------------------------------
                        7

EDIT: and also nice one as well qwerty :)
Title: Re: Trig Challenge....
Post by: Xeda112358 on March 27, 2011, 09:24:38 pm
Out of curiosity, will the numbers exceed 23169?
Title: Re: Trig Challenge....
Post by: Ashbad on March 27, 2011, 09:25:32 pm
From what I can guess, probably not, he was testing numbers up to around 3000.
Title: Re: Trig Challenge....
Post by: Xeda112358 on March 27, 2011, 09:26:37 pm
Okay, I'll see if I can extend an old algorithm to this, but I don't have high hopes :/
Title: Re: Trig Challenge....
Post by: Ashbad on March 27, 2011, 09:27:35 pm
I'm sure you can do it -- if you can't, then the rebellion has lost.
Title: Re: Trig Challenge....
Post by: AngelFish on March 27, 2011, 09:59:56 pm
Oops, messed that interval up. Looks like I'll have to redo the regression... :P
Title: Re: Trig Challenge....
Post by: Quigibo on March 27, 2011, 10:42:34 pm
Isn't just abs(V)+abs(W) close enough?  Its a perfect approximation for angles close to 0 and 90 degrees and only off by about 40% in the worst case of 45 degrees.

Another way you can do this is to store you vector as a magnitude and angle.  It might make some other math complicated, but it makes it super easy to read off the magnitude (its just r).  It depends more on how you plan to use this vector.
Title: Re: Trig Challenge....
Post by: phenomist on March 27, 2011, 11:52:42 pm
Assuming that the angle can be anywhere from 0 to 90 degrees, uniformly distributed, using a bit of calculus we get that the ratio is on average pi/4, or .785398. 11/14 is a sufficient approximation for this. So (abs(V)+abs(W))*11/14 provides a fairly good approximation, erring at most by 10% for angles between 10 and 80 degrees.

If you need a linear approximation that reduces the error necessary, the constant that you are looking for is e^(2C/pi-ln(2)/2) (C being Catalan's constant), or about .789348. 15/19 is a sufficient approximation for this.