PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_sphere_project()

static void test_sphere_project ( void  )
static

Definition at line 92 of file cu_geodetic.c.

93{
95 double dir1, dist1, dir2, dist2;
96
97 dir1 = M_PI_2;
98 dist1 = 0.1;
99
100 geographic_point_init(0, 0, &s);
101 sphere_project(&s, dist1, dir1, &e);
102
103 CU_ASSERT_DOUBLE_EQUAL(e.lon, 0.1, 1e-14);
104 CU_ASSERT_DOUBLE_EQUAL(e.lat, 0.0, 1e-14);
105
106 /* Direct and inverse solutions agree */
107 dist2 = sphere_distance(&s, &e);
108 dir2 = sphere_direction(&s, &e, dist1);
109
110 CU_ASSERT_DOUBLE_EQUAL(dist1, dist2, 1e-14);
111 CU_ASSERT_DOUBLE_EQUAL(dir1, dir2, 1e-14);
112
113 dist1 = sphere_distance(&e, &s);
114 dir1 = sphere_direction(&e, &s, dist1);
115 sphere_project(&e, dist1, dir1, &s);
116
117 CU_ASSERT_DOUBLE_EQUAL(s.lon, 0.0, 1e-14);
118 CU_ASSERT_DOUBLE_EQUAL(s.lat, 0.0, 1e-14);
119
120 geographic_point_init(0, 0.2, &e);
121 geographic_point_init(0, 0.4, &s);
122 dist1 = sphere_distance(&s, &e);
123 dir1 = sphere_direction(&e, &s, dist1);
124 /* GeodSolve -i -E -p 16 -e 1 0 --input-string "0.2 0 0.4 0" */
125 CU_ASSERT_DOUBLE_EQUAL(dir1, 0.0, 1e-14);
126 CU_ASSERT_DOUBLE_EQUAL(dist1, 0.0034906585039887, 1e-14);
127
128 geographic_point_init(0, 1, &s); /* same start point for remainder of tests */
129 geographic_point_init(0, 2, &e);
130 dist2 = sphere_distance(&s, &e);
131 dir2 = sphere_direction(&s, &e, dist2);
132 /* GeodSolve -i -E -p 16 -e 1 0 --input-string "1 0 2 0" */
133 CU_ASSERT_DOUBLE_EQUAL(dir2, 0.0, 1e-14);
134 CU_ASSERT_DOUBLE_EQUAL(dist2, 0.0174532925199433, 1e-14);
135
136 geographic_point_init(1, 1, &e);
137 dist2 = sphere_distance(&s, &e);
138 dir2 = sphere_direction(&s, &e, dist2);
139 /* GeodSolve -i -E -p 16 -e 1 0 --input-string "1 0 1 1" */
140 CU_ASSERT_DOUBLE_EQUAL(dir2, 89.991273575329292895136 * M_PI / 180.0, 1e-14);
141 CU_ASSERT_DOUBLE_EQUAL(dist2, 0.0174506342314906, 1e-14);
142
143 geographic_point_init(0, 0, &e);
144 dist2 = sphere_distance(&s, &e);
145 dir2 = sphere_direction(&s, &e, dist2);
146 /* GeodSolve -i -E -p 16 -e 1 0 --input-string "1 0 0 0" */
147 CU_ASSERT_DOUBLE_EQUAL(dir2, M_PI, 1e-14);
148 CU_ASSERT_DOUBLE_EQUAL(dist2, 0.0174532925199433, 1e-14);
149
150 geographic_point_init(-1, 1, &e);
151 dist2 = sphere_distance(&s, &e);
152 dir2 = sphere_direction(&s, &e, dist2);
153 /* GeodSolve -i -E -p 16 -e 1 0 --input-string "1 0 1 -1" */
154 CU_ASSERT_DOUBLE_EQUAL(dir2, -89.991273575329292895136 * M_PI / 180.0, 1e-14);
155 CU_ASSERT_DOUBLE_EQUAL(dist2, 0.0174506342314906, 1e-14);
156
157 geographic_point_init(1, 2, &e);
158 dist2 = sphere_distance(&s, &e);
159 dir2 = sphere_direction(&s, &e, dist2);
160 /* GeodSolve -i -E -p 16 -e 1 0 --input-string "1 0 2 1" */
161 CU_ASSERT_DOUBLE_EQUAL(dir2, 44.978182941465044354783 * M_PI / 180.0, 1e-14);
162 CU_ASSERT_DOUBLE_EQUAL(dist2, 0.0246782972905467, 1e-14);
163
164 geographic_point_init(-1, 0, &e);
165 dist2 = sphere_distance(&s, &e);
166 dir2 = sphere_direction(&s, &e, dist2);
167 /* GeodSolve -i -E -p 16 -e 1 0 --input-string "1 0 0 -1" */
168 CU_ASSERT_DOUBLE_EQUAL(dir2, -134.995636455344851488216 * M_PI / 180.0, 1e-14);
169 CU_ASSERT_DOUBLE_EQUAL(dist2, 0.0246820563917664, 1e-14);
170}
char * s
Definition cu_in_wkt.c:23
int sphere_project(const GEOGRAPHIC_POINT *r, double distance, double azimuth, GEOGRAPHIC_POINT *n)
Given a starting location r, a distance and an azimuth to the new point, compute the location of the ...
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition lwgeodetic.c:180
double sphere_distance(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
Given two points on a unit sphere, calculate their distance apart in radians.
Definition lwgeodetic.c:896
double sphere_direction(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e, double d)
Given two points on a unit sphere, calculate the direction from s to e.
Definition lwgeodetic.c:927
Point in spherical coordinates on the world.
Definition lwgeodetic.h:54

References geographic_point_init(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, s, sphere_direction(), sphere_distance(), and sphere_project().

Referenced by geodetic_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: