22 #include <grass/gis.h>
23 #include <grass/glocale.h>
25 static double min4(
double,
double,
double,
double);
26 static double min2(
double,
double);
29 static int projection = 0;
30 static double factor = 1.0;
78 double G_distance(
double e1,
double n1,
double e2,
double n2)
80 if (projection == PROJECTION_LL)
83 return factor * hypot(e1 - e2, n1 - n2);
97 double ax2,
double ay2,
98 double bx1,
double by1,
99 double bx2,
double by2)
106 bx1, by1, bx2, by2, &ra, &rb, &x, &y) > 0)
127 double x1,
double y1,
double x2,
132 double xq, yq, ra, rb;
139 if (dx == 0.0 && dy == 0.0)
142 if (fabs(dy) > fabs(dx)) {
144 yq = (dx / dy) * (xp - xq) + yp;
148 xq = (dy / dx) * (yp - yq) + xp;
160 G_warning(_(
"G_distance_point_to_line_segment: shouldn't happen: "
161 "code=%d P=(%f,%f) S=(%f,%f)(%f,%f)"),
162 t, xp, yp, x1, y1, x2, y2);
167 if (rb >= 0 && rb <= 1.0)
176 static double min4(
double a,
double b,
double c,
double d)
178 return min2(min2(a, b), min2(c, d));
181 static double min2(
double a,
double b)
183 return a < b ? a :
b;
int G_intersect_line_segments(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2, double *ra, double *rb, double *x, double *y)
int G_begin_distance_calculations(void)
Begin distance calculations.
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
double G_distance(double e1, double n1, double e2, double n2)
Returns distance in meters.
int G_begin_geodesic_distance(double a, double e2)
Begin geodesic distance.
double G_distance_between_line_segments(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2)
Returns distance between two line segments in meters.
double G_geodesic_distance(double lon1, double lat1, double lon2, double lat2)
Calculates geodesic distance.
double G_distance_point_to_line_segment(double xp, double yp, double x1, double y1, double x2, double y2)
Returns distance between a point and line segment in meters.
double G_database_units_to_meters_factor(void)
conversion to meters
int G_projection(void)
query cartographic projection