Author Topic: Trig Challenge....  (Read 7255 times)

0 Members and 1 Guest are viewing this topic.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Trig Challenge....
« 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 :))

Ashbad

  • Guest
Re: Trig Challenge....
« Reply #1 on: March 27, 2011, 04:22:21 pm »
Well, does it have to be in some specific format?  If not:

W + V
------
   2

:P
« Last Edit: March 27, 2011, 04:22:41 pm by Ashbad »

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig Challenge....
« Reply #2 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
« Last Edit: March 27, 2011, 04:25:41 pm by squidgetx »

Ashbad

  • Guest
Re: Trig Challenge....
« Reply #3 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...? ???

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig Challenge....
« Reply #4 on: March 27, 2011, 04:29:04 pm »
basically, find square root of v^2+w^2 without using that formula.

Ashbad

  • Guest
Re: Trig Challenge....
« Reply #5 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
« Last Edit: March 27, 2011, 04:41:25 pm by Ashbad »

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig Challenge....
« Reply #6 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...

Ashbad

  • Guest
Re: Trig Challenge....
« Reply #7 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?

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig Challenge....
« Reply #8 on: March 27, 2011, 05:01:32 pm »
That's what I'm doing now lol

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Trig Challenge....
« Reply #9 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.
« Last Edit: March 27, 2011, 08:38:02 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Ashbad

  • Guest
Re: Trig Challenge....
« Reply #10 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 :)
« Last Edit: March 27, 2011, 09:11:13 pm by Ashbad »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Trig Challenge....
« Reply #11 on: March 27, 2011, 09:24:38 pm »
Out of curiosity, will the numbers exceed 23169?

Ashbad

  • Guest
Re: Trig Challenge....
« Reply #12 on: March 27, 2011, 09:25:32 pm »
From what I can guess, probably not, he was testing numbers up to around 3000.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Trig Challenge....
« Reply #13 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 :/

Ashbad

  • Guest
Re: Trig Challenge....
« Reply #14 on: March 27, 2011, 09:27:35 pm »
I'm sure you can do it -- if you can't, then the rebellion has lost.