00001 #include "vect2.h"
00002
00003 #include <stdlib.h>
00004 #include <math.h>
00005
00006
00007 void vect2_pol2cart(vect2_pol* vp, vect2_cart* vc)
00008 {
00009 if(vp == NULL) return;
00010 if(vc == NULL) return;
00011
00012 vc->x = (Real)( (vp->r)*cos(vp->theta) );
00013 vc->y = (Real)( (vp->r)*sin(vp->theta) );
00014
00015 return;
00016 }
00017
00018
00019 void vect2_cart2pol(vect2_cart* vc, vect2_pol* vp)
00020 {
00021 if(vc == NULL) return;
00022 if(vp == NULL) return;
00023
00024 vp->r = (Real)( sqrt((vc->x)*(vc->x)+(vc->y)*(vc->y)) );
00025 vp->theta = (Real)atan2(vc->y,vc->x);
00026
00027 return;
00028 }
00029
00030
00031
00032 void vect2_add_pol(vect2_pol* vp1, vect2_pol* vp2, vect2_pol* vresult)
00033 {
00034 vect2_cart vc1;
00035 vect2_cart vc2;
00036
00037 vect2_cart vc;
00038
00039 vect2_pol2cart(vp1,&vc1);
00040 vect2_pol2cart(vp2,&vc2);
00041
00042 vect2_add_cart(&vc1,&vc2,&vc);
00043
00044 vect2_cart2pol(&vc,vresult);
00045
00046 return;
00047 }
00048
00049
00050 void vect2_add_cart(vect2_cart* vc1, vect2_cart* vc2, vect2_cart* vresult)
00051 {
00052 vresult->x = vc1->x + vc2->x;
00053 vresult->y = vc1->y + vc2->y;
00054
00055 return;
00056 }
00057
00058
00059
00060 void vect2_sub_pol(vect2_pol* vp1, vect2_pol* vp2, vect2_pol* vresult)
00061 {
00062 vect2_cart vc1;
00063 vect2_cart vc2;
00064
00065 vect2_cart vc;
00066
00067 vect2_pol2cart(vp1,&vc1);
00068 vect2_pol2cart(vp2,&vc2);
00069
00070 vect2_sub_cart(&vc1,&vc2,&vc);
00071
00072 vect2_cart2pol(&vc,vresult);
00073
00074 return;
00075 }
00076
00077
00078 void vect2_sub_cart(vect2_cart* vc1, vect2_cart* vc2, vect2_cart* vresult)
00079 {
00080 vresult->x = vc1->x - vc2->x;
00081 vresult->y = vc1->y - vc2->y;
00082
00083 return;
00084 }
00085
00086
00087
00088 void vect2_scale_cart(vect2_cart* vc1, Real alpha, vect2_cart* vresult)
00089 {
00090 vresult->x = alpha*(vc1->x);
00091 vresult->y = alpha*(vc1->y);
00092
00093 return;
00094 }
00095
00096
00097 void vect2_scale_pol(vect2_pol* vp1, Real alpha, vect2_pol* vresult)
00098 {
00099 vresult->r = alpha*vp1->r;
00100
00101 return;
00102 }