HW 9/17/2018
1
#include <stdio.h>
#include <math.h>
int main(void)
{
/* Declare variables and function prototype. */
double x1,y1,z1,x2,y2,z2;
double angle(double x1,double y1,
double z1,double x2,double y2,double z2);
printf("Enter value vectors ");
printf("enter vector 1: \n");
scanf("%lf %lf %lf",&x1,&y1,&z1);
printf("enter vector 2: \n");
scanf("%lf %lf% lf",&x2,&y2,&z2);
printf("angle: %6.2f \n",
angle(x1,y1,z1,x2,y2,z2));
/* Exit program. */
return 0;
}
double angle(double x1,double y1,
double z1,double x2, double y2, double z2)
{
/* Declare variables. */
double dot,n1,n2,gamma;
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
n1 = sqrt(x1*x1 + y1*y1 + z1*z1);
n2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = (acos(dot/(n1*n2))*180/3.141593);
/* Compute and return angle. */
return gamma;
}
4 and 5
4 and 5
#include <stdio.h>
#include <math.h>
#define PI 3.141593
double gc_distanceNNWW(double lat1, double long1, double lat2, double long2);
double gc_distanceNSWW(double lat1, double long1, double lat2, double long2);
double gc_distanceSNWW(double lat1, double long1, double lat2, double long2);
double gc_distanceSSWW(double lat1, double long1, double lat2, double long2);
double gc_distanceNNWE(double lat1, double long1, double lat2, double long2);
double gc_distanceNSWE(double lat1, double long1, double lat2, double long2);
double gc_distanceSNWE(double lat1, double long1, double lat2, double long2);
double gc_distanceSSWE(double lat1, double long1, double lat2, double long2);
double gc_distanceNNEW(double lat1, double long1, double lat2, double long2);
double gc_distanceNSEW(double lat1, double long1, double lat2, double long2);
double gc_distanceSNEW(double lat1, double long1, double lat2, double long2);
double gc_distanceSSEW(double lat1, double long1, double lat2, double long2);
double gc_distanceNNEE(double lat1, double long1, double lat2, double long2);
double gc_distanceNSEE(double lat1, double long1, double lat2, double long2);
double gc_distanceSNEE(double lat1, double long1, double lat2, double long2);
double gc_distanceSSEE(double lat1, double long1, double lat2, double long2);
int main(void)
{
/* Declare variables and function prototype. */
double lat1, long1, lat2, long2;
char direction_lat1, direction_lat2, direction_long1, direction_long2, N = 'n', n = 'n', S = 's', s = 's', W = 'w', w = 'w', E = 'e', e = 'e';
/* Get locations of two points. */
printf("Enter latitude for location 1: \n");
scanf("%lf",&lat1);
printf("N for north, S for south: \n");
scanf(" %c", &direction_lat1);
printf("Enter longitude for location 1: \n");
scanf(" %lf", &long1);
printf("W for west, E for east: \n");
scanf(" %c", &direction_long1);
printf("Enter latitude for location 2: \n");
scanf("%lf",&lat2);
printf("N for north, S for south: \n");
scanf(" %c", &direction_lat2);
printf("Enter longitude for location 2: \n");
scanf("%lf", &long2);
printf("W for west, E for east: \n");
scanf(" %c", &direction_long2);
/* Print great circle distance. */
if (direction_lat1 == 'n' && direction_lat2 == 'n' && direction_long1 == 'w' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNNWW(lat1,long1, lat2,long2));
printf("NNWW");
}
else if (direction_lat1 == 'n' && direction_lat2 == 's' && direction_long1 == 'w' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNSWW(lat1,long1, lat2,long2));
printf("NSWW");
}
else if (direction_lat1 == 's' && direction_lat2 == 'n' && direction_long1 == 'w' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSNWW(lat1,long1, lat2,long2));
printf("SNWW");
}
else if (direction_lat1 == 's' && direction_lat2 == 's' && direction_long1 == 'w' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSSWW(lat1,long1, lat2,long2));
printf("SSWW");
}
//WE
else if (direction_lat1 == 'n' && direction_lat2 == 'n' && direction_long1 == 'w' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNNWE(lat1,long1, lat2,long2));
printf("NNWE");
}
else if (direction_lat1 == 'n' && direction_lat2 == 's' && direction_long1 == 'w' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNSWE(lat1,long1, lat2,long2));
printf("NSWE");
}
else if (direction_lat1 == 's' && direction_lat2 == 'n' && direction_long1 == 'w' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSNWE(lat1,long1, lat2,long2));
printf("SNWE");
}
else if (direction_lat1 == 's' && direction_lat2 == 's' && direction_long1 == 'w' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSSWE(lat1,long1, lat2,long2));
printf("SSWE");
}
//EW
else if (direction_lat1 == 'n' && direction_lat2 == 'n' && direction_long1 == 'e' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNNEW(lat1,long1, lat2,long2));
printf("NNEW");
}
else if (direction_lat1 == 'n' && direction_lat2 == 's' && direction_long1 == 'e' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNSEW(lat1,long1, lat2,long2));
printf("NSEW");
}
else if (direction_lat1 == 's' && direction_lat2 == 'n' && direction_long1 == 'e' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSNEW(lat1,long1, lat2,long2));
printf("SNEW");
}
else if (direction_lat1 == 's' && direction_lat2 == 's' && direction_long1 == 'e' && direction_long2 == 'w')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSSEW(lat1,long1, lat2,long2));
printf("SSEW");
}
//EE
else if (direction_lat1 == 'n' && direction_lat2 == 'n' && direction_long1 == 'e' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNNEE(lat1,long1, lat2,long2));
printf("NNEE");
}
else if (direction_lat1 == 'n' && direction_lat2 == 's' && direction_long1 == 'e' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceNSEE(lat1,long1, lat2,long2));
printf("NSEE");
}
else if (direction_lat1 == 's' && direction_lat2 == 'n' && direction_long1 == 'e' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSNEE(lat1,long1, lat2,long2));
printf("SNEE");
}
else if (direction_lat1 == 's' && direction_lat2 == 's' && direction_long1 == 'e' && direction_long2 == 'e')
{
printf("Great Circle Distance: %.0f miles \n", gc_distanceSSEE(lat1,long1, lat2,long2));
printf("SSEE");
}
else
{
printf ("Please enter valid directions");
}
/* Exit program. */
return 0;
}
/* This function computes the distance between two */
/* points using great circle distances for 2 north latitudes. */
// and 2 wests
double gc_distanceNNWW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 north, 1 south latitude. */
// and 2 wests
double gc_distanceNSWW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 south, 1 north latitudes. */
// and 2 wests
double gc_distanceSNWW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 2 south latitudes. */
// and 2 wests
double gc_distanceSSWW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
//1 WEST, 1 EAST
/* This function computes the distance between two */
/* points using great circle distances for 2 north latitudes. */
// and 1 wests 1 easts
double gc_distanceNNWE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 north, 1 south latitude. */
// and 2 wests
double gc_distanceNSWE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 south, 1 north latitudes. */
double gc_distanceSNWE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 2 south latitudes. */
double gc_distanceSSWE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
//1 EAST 1 WEST
/* This function computes the distance between two */
/* points using great circle distances for 2 north latitudes. */
double gc_distanceNNEW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 north, 1 south latitude. */
double gc_distanceNSEW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 south, 1 north latitudes. */
double gc_distanceSNEW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 2 south latitudes. */
double gc_distanceSSEW(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 2 north latitudes. */
double gc_distanceNNEE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 north, 1 south latitude. */
double gc_distanceNSEE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 - lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 1 south, 1 north latitudes. */
double gc_distanceSNEE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 - lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
/* This function computes the distance between two */
/* points using great circle distances for 2 south latitudes. */
double gc_distanceSSEE(double lat1,double long1, double lat2,double long2)
{
/* Declare variables. */
double rho, phi, theta, gamma, dot, dist1, dist2,x1, y1, z1, x2, y2, z2;
/* Convert latitude,longitude to rectangular coordinates. */
rho = 3960;
phi = (90 + lat1)*(PI/180.0);
theta = (360 - long1*2)*(PI/180.0);
x1 = rho*sin(phi)*cos(theta);
y1 = rho*sin(phi)*sin(theta);
z1 = rho*cos(phi);
phi = (90 + lat2)*(PI/180.0);
theta = (360 - long2*2)*(PI/180.0);
x2 = rho*sin(phi)*cos(theta);
y2 = rho*sin(phi)*sin(theta);
z2 = rho*cos(phi);
/* Compute angle between vectors. */
dot = x1*x2 + y1*y2 + z1*z2;
dist1 = sqrt(x1*x1 + y1*y1 + z1*z1);
dist2 = sqrt(x2*x2 + y2*y2 + z2*z2);
gamma = acos(dot/(dist1*dist2));
/* Compute and return great circle distance. */
return gamma*rho;
}
Comments
Post a Comment