23 #include <grass/gis.h>
24 #include <grass/gstypes.h>
65 if (strcmp(units,
"meters") == 0) {
69 if (strcmp(units,
"miles") == 0) {
70 return (meters * .0006213712);
73 if (strcmp(units,
"kilometers") == 0) {
74 return (meters * .001);
77 if (strcmp(units,
"feet") == 0) {
78 return (meters * 3.280840);
81 if (strcmp(units,
"yards") == 0) {
82 return (meters * 1.093613);
85 if (strcmp(units,
"rods") == 0) {
86 return (meters * .1988388);
89 if (strcmp(units,
"inches") == 0) {
90 return (meters * 39.37008);
93 if (strcmp(units,
"centimeters") == 0) {
94 return (meters * 100.0);
97 if (strcmp(units,
"millimeters") == 0) {
98 return (meters * 1000.0);
101 if (strcmp(units,
"micron") == 0) {
102 return (meters * 1000000.0);
105 if (strcmp(units,
"nanometers") == 0) {
106 return (meters * 1000000000.0);
109 if (strcmp(units,
"cubits") == 0) {
110 return (meters * 2.187227);
113 if (strcmp(units,
"hands") == 0) {
114 return (meters * 9.842520);
117 if (strcmp(units,
"furlongs") == 0) {
118 return (meters * .004970970);
121 if (strcmp(units,
"nmiles") == 0) {
123 return (meters * .0005399568);
126 if (strcmp(units,
"chains") == 0) {
127 return (meters * .0497097);
149 return (
float)sqrt(x * x + y * y + z * z);
167 return (
float)sqrt(x * x + y * y);
250 n = sqrt(v1[
X] * v1[
X] + v1[
Y] * v1[
Y] + v1[Z] * v1[Z]);
275 n = sqrt(v1[
X] * v1[
X] + v1[
Y] * v1[
Y]);
299 n = sqrt(dv1[
X] * dv1[
X] + dv1[
Y] * dv1[
Y] + dv1[Z] * dv1[Z]);
329 n = sqrt(dx * dx + dy * dy + dz * dz);
335 v2[
X] = v1[
X] + dx /
n;
336 v2[
Y] = v1[
Y] + dy /
n;
337 v2[Z] = v1[Z] + dz /
n;
360 n = sqrt(dx * dx + dy * dy + dz * dz);
363 v3[
X] = v3[
Y] = v3[Z] = 0.0;
391 n = sqrt(dx * dx + dy * dy);
408 v3[
X] = (v1[
Y] * v2[Z]) - (v1[Z] * v2[
Y]);
409 v3[
Y] = (v1[Z] * v2[
X]) - (v1[
X] * v2[Z]);
410 v3[Z] = (v1[
X] * v2[
Y]) - (v1[Y] * v2[
X]);
423 *mag = sqrt(v1[
X] * v1[
X] + v1[
Y] * v1[
Y] + v1[Z] * v1[Z]);
445 static float *entrys =
NULL;
455 entrys = (
float *)G_malloc(4 * nhist *
sizeof(
float));
468 for (i = 0; i < next; i += 4) {
469 if (entrys[i] == p1[0] && entrys[i + 1] == p1[1]
470 && entrys[i + 2] == p2[0] && entrys[i + 3] == p2[1]) {
475 if (len == next / 4) {
479 entrys[next] = p1[0];
480 entrys[next + 1] = p1[1];
481 entrys[next + 2] = p2[0];
482 entrys[next + 3] = p2[1];
void G_free(void *buf)
Free allocated memory.
int GS_v3normalize(float *v1, float *v2)
Change v2 so that v1v2 is a unit vector.
int GS_v3norm(float *v1)
Change v1 so that it is a unit vector (2D)
void GS_v3add(float *v1, float *v2)
Sum vectors.
void GS_v3sub(float *v1, float *v2)
Subtract vectors.
int GS_v3dir(float *v1, float *v2, float *v3)
Get a normalized direction from v1 to v2, store in v3.
void GS_v3cross(float *v1, float *v2, float *v3)
Get the cross product v3 = v1 cross v2.
void GS_v2dir(float *v1, float *v2, float *v3)
Get a normalized direction from v1 to v2, store in v3 (2D)
int GS_v2norm(float *v1)
Change v1 so that it is a unit vector (3D)
double GS_geodistance(double *from, double *to, const char *units)
Calculate distance between 2 coordinates.
void GS_v3mult(float *v1, float k)
Multiple vectors.
double Gs_distance(double *from, double *to)
Calculates distance in METERS between two points in current projection (2D)
void GS_v3eq(float *v1, float *v2)
Copy vector values.
int GS_dv3norm(double *dv1)
Changes v1 so that it is a unit vector.
int GS_coordpair_repeats(float *p1, float *p2, int nhist)
ADD.
float GS_distance(float *from, float *to)
Calculate distance.
float GS_P2distance(float *from, float *to)
Calculate distance in plane.
void GS_v3mag(float *v1, float *mag)
Magnitude of vector.