Results 1 to 6 of 6

Thread: vectors using odd angles

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    vectors using odd angles

    don't know why but i just can't get anything to work here:

    I have an angle (goes over 360, positive and negetive), its a float, so I can't use mod.
    all I want to do is split my line into the vector components. How would I do this with such odd angles?

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    What do you mean by splitting a line into vector components? Do you mean describing the slope with an angle?
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    example:

    if I have a vector of 16 at 33 degrees. the two components (like 2 legs on a triangle) making up that line would be 8.7 and 13.4

  4. #4
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    It's called polar coordinates -

    Don't forget this code works in radians

    Code:
    #include <math.h>
    
    struct vector{
         float x;
         float y;
    };
    
    int main(){
           struct vector test;
           float angle = 33/ (2*M_PI); // radians
           float magnitude = 16;
           test.x=0;
           test.y=0;
           test=PolarToXY(angle,magnitude,test);
           printf("%f, %f\n",test.x,test.y);
           return 0;
    }
    struct vector  PolarToXY(float angle, float magnitude,
                                             struct vector src){
           src.x=cos(angle)*magnitude;
           src.y=sin(angle)*magnitude;
           return src;
    
    }

  5. #5
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    And, depending on the angle, the resultants can be negative.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    ah! i forgot that cos sin and tan worked with radians! works like a charm now....thanks guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width