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

Function gmtplot_gcircle_sub

src/gmt_plot.c:4929–4982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4927}
4928
4929GMT_LOCAL void gmtplot_gcircle_sub (struct GMT_CTRL *GMT, double lon0, double lat0, double azimuth, double length, struct GMT_SYMBOL *S, struct GMT_CIRCLE *C) {
4930 /* We must determine points A and B, whose great-circle connector is the arc we seek to draw */
4931
4932 int justify = PSL_vec_justify (S->v.status); /* Return justification as 0-3 */
4933 double x, y;
4934 gmt_M_memset (C, 1, struct GMT_CIRCLE); /* Set all to zero */
4935
4936 if (S->v.status & PSL_VEC_JUST_S) { /* Was given coordinates of A and B */
4937 justify = 3;
4938 }
4939 switch (justify) { /* A and B depends on chosen justification */
4940 case 0: /* Was given coordinates of A; determine B */
4941 C->lon[0] = lon0; C->lat[0] = lat0;
4942 gmt_geo_to_cart (GMT, C->lat[0], C->lon[0], C->A, true);
4943 C->r0 = C->r = length / GMT->current.proj.DIST_KM_PR_DEG; /* Arch length in spherical degrees */
4944 if (C->r > 180.0) {C->longway = true; C->r -= 180.0;} /* Temporarily adjust if arcs > 180 degrees are chosen */
4945 gmtlib_get_point_from_r_az (GMT, C->lon[0], C->lat[0], C->r, azimuth, &C->lon[1], &C->lat[1]);
4946 if (C->longway) C->lon[1] += 180.0, C->lat[1] = -C->lat[1]; /* Undo adjustment */
4947 gmt_geo_to_cart (GMT, C->lat[1], C->lon[1], C->B, true); /* Get B */
4948 break;
4949 case 1: /* Was given coordinates of halfway point; determine A and B */
4950 C->r0 = C->r = length / GMT->current.proj.DIST_KM_PR_DEG; /* Arch length in spherical degrees */
4951 if (C->r > 180.0) C->longway = true; /* Temporarily adjust if arcs > 180 degrees are chosen */
4952 gmtlib_get_point_from_r_az (GMT, lon0, lat0, 0.5*C->r, azimuth, &C->lon[1], &C->lat[1]);
4953 gmt_geo_to_cart (GMT, C->lat[1], C->lon[1], C->B, true); /* Get B */
4954 gmtlib_get_point_from_r_az (GMT, lon0, lat0, 0.5*C->r, azimuth+180.0, &x, &y);
4955 C->lon[0] = x; C->lat[0] = y; /* Replace the original A point */
4956 gmt_geo_to_cart (GMT, C->lat[0], C->lon[0], C->A, true); /* Get A */
4957 break;
4958 case 2: /* Was given coordinates of B point; determine A */
4959 C->lon[0] = lon0; C->lat[0] = lat0;
4960 gmt_geo_to_cart (GMT, C->lat[0], C->lon[0], C->B, true);
4961 C->r0 = C->r = length / GMT->current.proj.DIST_KM_PR_DEG; /* Arch length in spherical degrees */
4962 if (C->r > 180.0) {C->longway = true; C->r -= 180.0;} /* Temporarily adjust if arcs > 180 degrees are chosen */
4963 gmtlib_get_point_from_r_az (GMT, C->lon[0], C->lat[0], C->r, azimuth+180.0, &C->lon[1], &C->lat[1]);
4964 if (C->longway) C->lon[1] += 180.0, C->lat[1] = -C->lat[1]; /* Undo adjustment */
4965 gmt_geo_to_cart (GMT, C->lat[1], C->lon[1], C->A, true); /* Get A */
4966 gmt_M_double_swap (C->lon[0], C->lon[1]); gmt_M_double_swap (C->lat[0], C->lat[1]); /* Now A is first and B is second */
4967 break;
4968 case 3: /* Was given coordinates of B instead of azimuth and length; can never be longway */
4969 C->lon[0] = lon0; C->lat[0] = lat0;
4970 C->lat[1] = length; C->lon[1] = azimuth;
4971 gmt_geo_to_cart (GMT, C->lat[0], C->lon[0], C->A, true); /* Get A */
4972 gmt_geo_to_cart (GMT, C->lat[1], C->lon[1], C->B, true); /* Get B */
4973 C->r0 = C->r = d_acosd (gmt_dot3v (GMT, C->A, C->B)); /* Arc length in degrees */
4974 break;
4975 }
4976 gmt_cross3v (GMT, C->A, C->B, C->P); /* Rotation pole */
4977 gmt_normalize3v (GMT, C->P); /* Rotation pole unit vector */
4978
4979 if (C->longway) { /* Want to go the long way */
4980 C->P[0] = -C->P[0], C->P[1] = -C->P[1], C->P[2] = -C->P[2];
4981 }
4982}
4983
4984GMT_LOCAL void gmtplot_scircle_sub (struct GMT_CTRL *GMT, double lon0, double lat0, double angle_1, double angle_2, struct GMT_SYMBOL *S, struct GMT_CIRCLE *C) {
4985 /* We must determine points A and B, whose small-circle connector about pole P is the arc we seek to draw */

Callers 1

Calls 5

gmt_geo_to_cartFunction · 0.85
gmt_dot3vFunction · 0.85
gmt_cross3vFunction · 0.85
gmt_normalize3vFunction · 0.85

Tested by

no test coverage detected