ocssw V2020
ll2vec.c
Go to the documentation of this file.
1 #include <math.h>
2 #include "l12_proto.h"
3 static float raddeg = 180. / PI;
4 
5 int ll2vec(float *ll, float *vec)
6 /*******************************************************************
7 
8  ll2vec
9 
10  purpose: convert lat, lon (or az, ele) into vectors in x, y, z
11 
12  Returns type: int - 0 if all is OK
13 
14  Parameters: (in calling order)
15  Type Name I/O Description
16  ---- ---- --- -----------
17  float * ll I latitude longitude pair
18  float * vec O x, y, z vector with x
19  along the 0 lat, lon,
20  y at 0 lat, 90 lon and z
21  at 90 lat
22  (assumed to exist - array passed in)
23 
24  Modification history:
25  Programmer Date Description of change
26  ---------- ---- ---------------------
27  W. Robinson 10 Sep 2010 Original development
28 
29  *******************************************************************/ {
30  int32_t err;
31  float latr, lonr;
32 
33  if ((*ll > 90.) || (*ll < -90.)) {
34  *vec = -999.;
35  *(vec + 1) = -999.;
36  *(vec + 2) = -999.;
37  err = -1;
38  } else {
39  latr = *ll / raddeg;
40  lonr = *(ll + 1) / raddeg;
41  /*
42  * get the components
43  */
44  *vec = cos(lonr) * cos(latr);
45  *(vec + 1) = sin(lonr) * cos(latr);
46  *(vec + 2) = sin(latr);
47  err = 0;
48  }
49  return err;
50 }
51 
52 int vec2ll(float *vec, float *ll)
53 /*******************************************************************
54 
55  vec2ll
56 
57  purpose: convert a vectors in x, y, z into lat, lon (or az, ele)
58 
59  Returns type: int - 0 if all is OK
60 
61  Parameters: (in calling order)
62  Type Name I/O Description
63  ---- ---- --- -----------
64  float * vec I x, y, z vector with x
65  along the 0 lat, lon,
66  y at 0 lat, 90 lon and z
67  at 90 lat
68  float * ll O latitude longitude pair
69  (assumed to exist - array passed in)
70 
71  Modification history:
72  Programmer Date Description of change
73  ---------- ---- ---------------------
74  W. Robinson 10 Sep 2010 Original development
75 
76  *******************************************************************/ {
77  int32_t err;
78  float lonr, latr, vls, vlen;
79 
80  vls = pow(*vec, 2.) + pow(*(vec + 1), 2.) + pow(*(vec + 2), 2.);
81  if (vls <= 0) {
82  *ll = -999.;
83  *(ll + 1) = -999.;
84  err = -1;
85  } else {
86  /*
87  * get the vector lengths for normalization and derive lat, lon
88  */
89  vlen = sqrt(vls);
90  latr = asin(*(vec + 2) / vlen);
91  lonr = atan2(*(vec + 1) / vlen, *vec / vlen);
92 
93  *ll = latr * raddeg;
94  *(ll + 1) = lonr * raddeg;
95  err = 0;
96  }
97  return err;
98 }
int ll2vec(float *ll, float *vec)
Definition: ll2vec.c:5
#define PI
Definition: l3_get_org.c:6
int vec2ll(float *vec, float *ll)
Definition: ll2vec.c:52