ini
[aversive.git] / modules / base / math / vect2 / test / main.c
1 #include <vect2.h>
2
3 #include  <stdio.h>
4
5 int main(void)
6 {
7         vect2_pol vP;
8
9         vect2_pol vP2;
10         vect2_pol vP3;
11         
12         vect2_cart vC;
13
14         vect2_cart vC2;
15         vect2_cart vC3;
16         
17
18         Real R = 1.45064930529587234;
19         /* theta must be [0,2*Pi] or fake errors will appears ( because of modulo ) */
20         Real theta = 0.6734390282904231341;
21
22         Real R2 = 120398490.45064930529587234;
23         /* theta2 must be [0,2*Pi] or fake errors will appears ( because of modulo ) */
24         Real theta2 = 0.00001293892147;
25         
26         Real X = 2.5693042;
27         Real Y = 957802.203419598832952903;
28
29         Real X2 = 984.1204192049021;
30         Real Y2 = 0.000034248975923;
31         
32         Real alpha = 93.1240812795;
33
34         
35         /* */
36         
37         vP.r = R;
38         vP.theta = theta;
39
40         /* */
41         
42         printf("\nTesting polar->cartesian->polar convertions...\n");
43         
44         vect2_pol2cart(&vP,&vC);
45
46         vect2_cart2pol(&vC,&vP);
47
48         printf("Error on r = %f%%\nError on theta = %f%%\n",100 - 100*(vP.r)/R,100 - 100*(vP.theta)/theta);
49
50         /* */
51
52         vC.x = X;
53         vC.y = Y;
54
55         /* */
56         
57         printf("\nTesting cartesian->polar->cartesian convertions...\n");
58
59         vect2_cart2pol(&vC,&vP);        
60         vect2_pol2cart(&vP,&vC);
61
62         printf("Error on x = %f%%\nError on y = %f%%\n",100 - 100*(vC.x)/X,100 - 100*(vC.y)/Y); 
63
64
65         vC2.x = X2;
66         vC2.y = Y2;
67
68
69         /* Realise C = A + B puis C - B == A et C - A == B */
70         
71         printf("\nTesting cartesian addition and sub...\nV3 <- V1 + V2\nV3 - V2 == V1\nV3 - V1 == V2\n");
72         
73         vect2_add_cart(&vC,&vC2,&vC3);
74         vect2_sub_cart(&vC3,&vC2,&vC);
75         vect2_sub_cart(&vC3,&vC,&vC2);
76
77         printf("Error on x1 = %f%%\nError on y1 = %f%%\n",100 - 100*(vC.x)/X,100 - 100*(vC.y)/Y);       
78         printf("Error on x2 = %f%%\nError on y2 = %f%%\n",100 - 100*(vC2.x)/X2,100 - 100*(vC2.y)/Y2);           
79         /* */
80         
81         vP.r = R;
82         vP.theta = theta;
83         
84         vP2.r = R2;
85         vP2.theta = theta2;
86         
87         /* */
88         
89         printf("\nTesting polar addition and sub...\nV3 <- V1 + V2\nV3 - V2 == V1\nV3 - V1 == V2\n");
90         
91         vect2_add_pol(&vP,&vP2,&vP3);
92         vect2_sub_pol(&vP3,&vP2,&vP);
93         vect2_sub_pol(&vP3,&vP,&vP2);
94
95         printf("Error on r1 = %f%%\nError on theta1 = %f%%\n",100 - 100*(vP.r)/R,100 - 100*(vP.theta)/theta);   
96         printf("Error on r2 = %f%%\nError on theta2 = %f%%\n",100 - 100*(vP2.r)/R2,100 - 100*(vP2.theta)/theta2);
97
98         /* */
99
100         vC.x = X;
101         vC.y = Y;
102
103         /* */
104         
105         printf("\nTesting cartesian scaling...\nV1 = alpha*V2\n(1/alpha)*V1 == V2\n");
106                 
107         vect2_scale_cart(&vC,alpha,&vC2);
108         vect2_scale_cart(&vC2,1/alpha,&vC);
109
110         printf("Error on x = %f%%\nError on y = %f%%\n",100 - 100*(vC.x)/X,100 - 100*(vC.y)/Y); 
111
112         
113         /* */
114
115         vP.r = R;
116         vP.theta = theta;
117
118         /* */
119         
120         printf("\nTesting polar scaling...\nV1 = alpha*V2\n(1/alpha)*V1 == V2\n");
121
122         vect2_scale_pol(&vP,alpha,&vP2);
123         vect2_scale_pol(&vP2,1/alpha,&vP);
124
125         printf("Error on r = %f%%\nError on theta = %f%%\n",100 - 100*(vP.r)/R,100 - 100*(vP.theta)/theta);     
126
127         
128         return 0;
129 }