-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTools.c
43 lines (40 loc) · 824 Bytes
/
Tools.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Tools.c
*
* Created on: Oct 31, 2014
* Author: chenxiaoyu
*/
#include "Tools.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
void cart2pol(polarCoordinates* pc, float* partX, float* partY){
for (int i = 0; i < M; i++){
pc -> theta[i] = atan2(partY[i], partX[i]);
pc -> rho[i] = sqrt(pow(partX[i], 2) + pow(partY[i], 2));
}
}
void pol2cart(cartCoordinates* cc, float* theta, float* rho){
for (int i = 0; i < M; i++){
cc -> x[i] = rho[i] * cos(theta[i]);
cc -> y[i] = rho[i] * sin(theta[i]);
}
}
void normalizeAngle(float* x){
for (int i = 0; i < M; i++){
if (x[i] > M_PI){
x[i] -= 2*M_PI;
}
else if (x[i] < -M_PI){
x[i] += 2*M_PI;
}
}
for (int i = 0; i < M; i++){
if (x[i] > M_PI){
x[i] -= 2*M_PI;
}
else if (x[i] < -M_PI){
x[i] += 2*M_PI;
}
}
}