Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Closed Thread
  Search this Thread
Old 11-27-2003, 01:32 PM   #1
LQ Newbie
Registered: Nov 2003
Posts: 13

Rep: Reputation: 0
Calculating Surface Distance!

Can someone show me how to calculate the surface distance using function straight_D and surface_D. Thanks...

#include <stdio.h>
#include <math.h>
#include <string.h>
#define RHO 6367
#define PI 3.141592654

void read_GPS(float *,float *,float *,char *);
float convert_DD(float *, float *, float *);
float calc_SphereCoord_lat( char *, float *);
float calc_SphereCoord_long(char *, float *);
float deg2rad(float *);
float calc_3DCoord(float *, float *);
float straight_D(float *, float *, float *, float *, float *, float *);
int main(void)

float deg_lat_1, min_lat_1, sec_lat_1, deg_long_1, min_long_1, sec_long_1;
float deg_lat_2, min_lat_2, sec_lat_2, deg_long_2, min_long_2, sec_long_2;
float dec_deg_1, dec_deg_2, dec_deg_3, dec_deg_4;
float rad_lat_1, rad_long_1, rad_lat_2, rad_long_2;
float phi_lat_1, theta_long_1, phi_lat_2, theta_long_2;
char s1[10], s2[10], s3[10], s4[10];

printf("Please enter co-ordinates in format of 123 45 30 North\n" );
printf("where 123 = Degrees 45 = minutes 30 = seconds and North = direction.\n");

printf("Please enter in lattitudinal co-ordinates for start point:\n");
dec_deg_1 = convert_DD(&deg_lat_1,&min_lat_1,&sec_lat_1);
rad_lat_1 = calc_SphereCoord_lat(s1, &dec_deg_1);
phi_lat_1 = deg2rad(&rad_lat_1);

printf("Please enter in longitudinal co-ordinates for start point:\n");
dec_deg_2 = convert_DD(&deg_long_1,&min_long_1,&sec_long_1);
rad_long_1 = calc_SphereCoord_long(s2, &dec_deg_2);
theta_long_1 = deg2rad(&rad_long_1);
calc_3DCoord(&phi_lat_1, &theta_long_1);

printf("Please enter lattitudinal co-ordinates for final destination:\n");
dec_deg_3 = convert_DD(&deg_lat_2, &min_lat_2,&sec_lat_2);
rad_lat_2 = calc_SphereCoord_lat(s3, &dec_deg_3);
phi_lat_2 = deg2rad(&rad_lat_2);

printf("Please enter longitudinal co-ordinates for final destination:\n");
dec_deg_4 = convert_DD(&deg_long_2,&min_long_2,&sec_long_2);
rad_long_2 = calc_SphereCoord_long(s4, &dec_deg_4);
theta_long_2 = deg2rad(&rad_long_2);
calc_3DCoord(&phi_lat_2, &theta_long_2);

printf("Degrees:%f \n Minutes: %f \n Seconds:%f \n Direction:%s\n", deg_lat_1,
min_lat_1,sec_lat_1, s1);
printf("%f %f %f %s\n", deg_long_1, min_long_1, sec_long_1,s2);
printf("%f %f %f %s\n", deg_lat_2, min_lat_2, sec_lat_2, s3);
printf("%f %f %f %s\n", deg_long_2, min_long_2, sec_long_2,s4);

printf("%c", getchar());

void read_GPS(float *degrees,float *minutes,float *seconds,char *direction)
scanf("%f%f%f%s", degrees, minutes, seconds, direction);

float convert_DD(float *degrees, float *minutes, float *seconds)
float dec_deg,totalmins;

totalmins = *minutes + (*seconds / 60);
dec_deg = (totalmins /60) + *degrees;
printf("The decimal degree is %f", dec_deg);
printf("%c", getchar());


float calc_SphereCoord_lat(char *direction, float *dec_deg)
int temp_1;
float phi;
char s5[] = "North";
temp_1 = strcasecmp(direction,s5);
if (temp_1 == 0)
phi = 90 - *dec_deg;
phi = 90 + *dec_deg;
printf("The spherical co-ordinate phi is: %f\n", phi);


float calc_SphereCoord_long(char *direction, float *dec_deg)
int temp;
float theta;
char s6[] = "East";
temp = strcasecmp(direction,s6);
if (temp == 0)
theta = *dec_deg;
theta = (-*dec_deg);
printf("The spherical co-ordinate theta is: %f\n", theta);

float deg2rad(float *dec_deg)
float radians;
radians = (*dec_deg * 2 * PI) / 360;
printf("%f as radians is: %f\n", *dec_deg, radians);

float calc_3DCoord(float *phi, float *theta)
float temp_1, temp_2, temp_3;
temp_1 = (RHO * (sin(*phi)) * (cos(*theta)));
temp_2 = (RHO * (sin(*phi)) * (sin(*theta)));
temp_3 = (RHO * (cos(*phi)));
printf("The cartesian co-ordinates are: %f %f %f\n", temp_1, temp_2, temp_3);
Old 11-27-2003, 01:45 PM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How does one test the disk surface of the swap partition? gregmcavoy Linux - Hardware 22 01-17-2005 01:59 AM
administrative distance abirami Linux - Networking 5 09-23-2004 07:02 AM
SDL, handing Surface and Rect from an object to another? gundelgauk Programming 7 09-18-2003 06:57 PM
Disk Surface Scan Routine - Quickie! Svha Linux - Hardware 2 08-08-2003 02:01 PM
bringing this back to the surface... fatpig LQ Suggestions & Feedback 2 01-03-2002 01:28 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration