Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Angle from X,Y (http://www.chiefdelphi.com/forums/showthread.php?t=27685)

Astronouth7303 14-04-2004 07:24

Re: Angle from X,Y
 
It was a joke. The prize: Absolutely nothing!

Basically, I'm asking if anyone knows why you would want it on the controller.

Astronouth7303 14-04-2004 18:21

Atan Function
 
Here is my Arc Tangent code:
Code:

#define ATAN_COUNT 64
char rom ATAN_ARRAY[64] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16,
17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34,
36, 37, 39, 41, 43, 46, 48, 50, 53, 56, 59, 62, 66,
69, 74, 78, 83, 88, 95, 101, 109, 118, 128, 140, 154,
171, 192, 218, 253, 299, 367, 473, 663, 1106, 3319};

char atan (char Num)
{
        char Index = 0;
        char Value = 0;
        char IsDone = 0;
       
        LOOP:
                if (ATAN_ARRAY[Index] > Num)
                        Value--;
                if (ATAN_ARRAY[Index] >= Num)
                        IsDone = 255;
                else if (Index >= ATAN_COUNT - 1) //was ATAN_COUNT + 1
                {
                        IsDone = 255;
                        Value = 64;
                }
               
                if (IsDone)
                        goto LOOP_DONE;
                else
                { Value++; Index++; }
                goto LOOP;
        LOOP_DONE:
       
        return Value;
}

The lookup table is compressed. If I were to use a regular variety than it would be 3320 elements long! Instead, I put the location of the element that the value changes. That's why I loop. I think this will work, but I'm not sure.

[edit]that chould be ATAN_COUNT - 1 not ATAN_COUNT + 1 at line 19[/edit]

scottm87 19-04-2004 21:58

Re: Angle from X,Y
 
hmmm you can also use vectors, and find the angle with the formula (u * v)/(|u||v|) (the dot product of u and v divided by the product of the magnitudes). This is useful if you are already using vectors, which are probably better suited for motion and such anyways.

dtk 19-04-2004 22:08

Re: Angle from X,Y
 
Quote:

Originally Posted by scottm87
hmmm you can also use vectors, and find the angle with the formula (u * v)/(|u||v|) (the dot product of u and v divided by the product of the magnitudes). This is useful if you are already using vectors, which are probably better suited for motion and such anyways.


The result of that equation gives you the cos of the angle between the vectors. That is cos(x). You would still need to use an inverse trig function to find the angle (x).

I'm going to have to go ahead and give you -15 points for that one. o_O

-Daniel


All times are GMT -5. The time now is 13:43.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi