MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtplot_great_circle_arc

Function gmtplot_great_circle_arc

src/gmt_plot.c:4819–4847  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4817}
4818
4819GMT_LOCAL uint64_t gmtplot_great_circle_arc (struct GMT_CTRL *GMT, double *A, double *B, double step, bool longway, double **xp, double **yp) {
4820 /* Given vectors A and B, return great circle path sampled every step. Shorest path is selected unless longway is true */
4821 /* Determine unit vector pole of great circle or use the one given by small circle pole and its opening rot */
4822 uint64_t k, n;
4823 double P[3], X[3], R[3][3], R0[3][3], c, w, *xx = NULL, *yy = NULL;
4824
4825 gmt_cross3v (GMT, A, B, P); /* Parallel to rotation pole */
4826 gmt_normalize3v (GMT, P); /* Rotation pole unit vector */
4827 c = d_acosd (gmt_dot3v (GMT, A, B)); /* opening angle in degrees */
4828
4829 if (longway) { /* Want to go the long way */
4830 c = 360.0 - c;
4831 P[0] = -P[0], P[1] = -P[1], P[2] = -P[2];
4832 }
4833 if (gmt_M_is_zero (step)) step = GMT->current.map.path_step; /* Use default map-step if given as 0 */
4834 n = lrint (ceil (c / step)) + 1; /* Number of segments needed for smooth curve from A to B inclusive */
4835 step = D2R * c / (n - 1); /* Adjust step for exact fit, convert to radians */
4836 gmt_M_malloc2 (GMT, xx, yy, n, NULL, double); /* Allocate space for arrays */
4837 gmtlib_init_rot_matrix (R0, P); /* Get partial rotation matrix since no actual angle is applied yet */
4838 for (k = 0; k < n; k++) { /* March along the arc */
4839 w = k * step; /* Opening angle from A to this point X */
4840 gmt_M_memcpy (R, R0, 9, double); /* Get a copy of the "0-angle" rotation matrix */
4841 gmtlib_load_rot_matrix (w, R, P); /* Build the actual rotation matrix for this angle */
4842 gmt_matrix_vect_mult (GMT, 3U, R, A, X); /* Rotate point A towards B and get X */
4843 gmt_cart_to_geo (GMT, &yy[k], &xx[k], X, true); /* Get lon/lat of this point along arc */
4844 }
4845 *xp = xx; *yp = yy;
4846 return (n);
4847}
4848
4849GMT_LOCAL uint64_t gmtplot_small_circle_arc (struct GMT_CTRL *GMT, double *A, double step, double P[], double rot, double **xp, double **yp) {
4850 /* Given vectors A and B, return small circle path sampled every step. */

Callers 1

Calls 7

gmt_cross3vFunction · 0.85
gmt_normalize3vFunction · 0.85
gmt_dot3vFunction · 0.85
gmtlib_init_rot_matrixFunction · 0.85
gmtlib_load_rot_matrixFunction · 0.85
gmt_cart_to_geoFunction · 0.85
gmt_matrix_vect_multFunction · 0.70

Tested by

no test coverage detected