1 /*
2 * Copyright (c) 2012-2021, The OSKAR Developers.
3 * See the LICENSE file at the top-level directory of this distribution.
4 */
5
6 #include "math/oskar_rotate.h"
7 #include <math.h>
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
oskar_rotate_sph_f(int num_points,float * x,float * y,float * z,float lon,float lat)13 void oskar_rotate_sph_f(int num_points, float* x, float* y, float* z,
14 float lon, float lat)
15 {
16 int i = 0;
17 const float cos_lon = cosf(lon);
18 const float sin_lon = sinf(lon);
19 const float cos_lat = cosf(lat);
20 const float sin_lat = sinf(lat);
21 for (i = 0; i < num_points; ++i)
22 {
23 const float x_ = x[i];
24 const float y_ = y[i];
25 const float z_ = z[i];
26 x[i] = x_ * cos_lon * cos_lat - y_ * sin_lon - z_ * cos_lon * sin_lat;
27 y[i] = x_ * cos_lat * sin_lon + y_ * cos_lon - z_ * sin_lon * sin_lat;
28 z[i] = x_ * sin_lat + z_ * cos_lat;
29 }
30 }
31
oskar_rotate_sph_d(int num_points,double * x,double * y,double * z,double lon,double lat)32 void oskar_rotate_sph_d(int num_points, double* x, double* y, double* z,
33 double lon, double lat)
34 {
35 int i = 0;
36 const double cos_lon = cos(lon);
37 const double sin_lon = sin(lon);
38 const double cos_lat = cos(lat);
39 const double sin_lat = sin(lat);
40 for (i = 0; i < num_points; ++i)
41 {
42 const double x_ = x[i];
43 const double y_ = y[i];
44 const double z_ = z[i];
45 x[i] = x_ * cos_lon * cos_lat - y_ * sin_lon - z_ * cos_lon * sin_lat;
46 y[i] = x_ * cos_lat * sin_lon + y_ * cos_lon - z_ * sin_lon * sin_lat;
47 z[i] = x_ * sin_lat + z_ * cos_lat;
48 }
49 }
50
51 #ifdef __cplusplus
52 }
53 #endif
54