-
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? :(
-
What do you mean by splitting a line into vector components? Do you mean describing the slope with an angle?
-
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
-
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;
}
-
And, depending on the angle, the resultants can be negative.
-
ah! i forgot that cos sin and tan worked with radians! works like a charm now....thanks guys!