|
-
Jan 7th, 2003, 04:53 PM
#1
Thread Starter
Frenzied Member
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?
-
Jan 7th, 2003, 04:57 PM
#2
Good Ol' Platypus
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)
-
Jan 7th, 2003, 05:02 PM
#3
Thread Starter
Frenzied Member
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
-
Jan 7th, 2003, 05:39 PM
#4
Frenzied Member
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;
}
-
Jan 7th, 2003, 05:41 PM
#5
Frenzied Member
And, depending on the angle, the resultants can be negative.
-
Jan 7th, 2003, 08:49 PM
#6
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|