6 /* Convert a polar vector to a cartesian one */
7 void vect2_pol2cart(vect2_pol* vp, vect2_cart* vc)
10 if(vc == NULL) return;
12 vc->x = (Real)( (vp->r)*cos(vp->theta) );
13 vc->y = (Real)( (vp->r)*sin(vp->theta) );
18 /* Convert a cartesian vector to a polar one */
19 void vect2_cart2pol(vect2_cart* vc, vect2_pol* vp)
21 if(vc == NULL) return;
22 if(vp == NULL) return;
24 vp->r = (Real)( sqrt((vc->x)*(vc->x)+(vc->y)*(vc->y)) );
25 vp->theta = (Real)atan2(vc->y,vc->x);
31 /* Add 2 polar vectors and return the result */
32 void vect2_add_pol(vect2_pol* vp1, vect2_pol* vp2, vect2_pol* vresult)
39 vect2_pol2cart(vp1,&vc1);
40 vect2_pol2cart(vp2,&vc2);
42 vect2_add_cart(&vc1,&vc2,&vc);
44 vect2_cart2pol(&vc,vresult);
49 /* Add 2 cartesian vectors and return the result */
50 void vect2_add_cart(vect2_cart* vc1, vect2_cart* vc2, vect2_cart* vresult)
52 vresult->x = vc1->x + vc2->x;
53 vresult->y = vc1->y + vc2->y;
59 /* Substract 2 polar vectors and return the result */
60 void vect2_sub_pol(vect2_pol* vp1, vect2_pol* vp2, vect2_pol* vresult)
67 vect2_pol2cart(vp1,&vc1);
68 vect2_pol2cart(vp2,&vc2);
70 vect2_sub_cart(&vc1,&vc2,&vc);
72 vect2_cart2pol(&vc,vresult);
77 /* Substract 2 cartesian vectors and return the result */
78 void vect2_sub_cart(vect2_cart* vc1, vect2_cart* vc2, vect2_cart* vresult)
80 vresult->x = vc1->x - vc2->x;
81 vresult->y = vc1->y - vc2->y;
87 /* Multiply a cartesian vector by a scalar and return the result */
88 void vect2_scale_cart(vect2_cart* vc1, Real alpha, vect2_cart* vresult)
90 vresult->x = alpha*(vc1->x);
91 vresult->y = alpha*(vc1->y);
96 /* Multiply a polar vector by a scalar and return the result */
97 void vect2_scale_pol(vect2_pol* vp1, Real alpha, vect2_pol* vresult)
99 vresult->r = alpha*vp1->r;