1. Member
Join Date
Jun 2014
Posts
30
Rep Power
0

## Return value NaN

Hello, I am working on this new project where we are using the great distance formula
but everytime I run my ending result is NaN. I was researching, and people say its because you divide by 0.
I think I have my formula correct. any suggestions?

Java Code:
```
public class testingFormula {

public static void main(String[] args) {
double lat = 34.01858902;
double lon = -118.2817688;
double lat2 =33.94530869;
double lon2 = -118.3994904;

System.out.println("Distance =" + greatCircleArea(lat,lon,lat2,lon2));

}

static double greatCircleArea(double lat, double lon, double lat2, double lon2){

angle1 = Math.toDegrees(angle1);

double distance1 = 60 * angle1;
return distance1;
}
}```

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Return value NaN

I believe your formula is incorrect. Check it out here --> Great-circle distance - Wikipedia, the free encyclopedia.

You might also want to pay special attention to the computational formulas that apply to programming algorithms.

Regards,
Jim
Last edited by jim829; 03-17-2015 at 10:49 PM.

3. Member
Join Date
Jun 2014
Posts
30
Rep Power
0

## Re: Return value NaN

ah! Yes!
Easy mistake :(
Thanks Jim

Can I post another question regarding my project? Or Shall I create a new thread?

4. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Return value NaN

Probably best to post another thread. It keeps the topics separate. Even if it is the same application.

Regards,
Jim

5. Member
Join Date
Jun 2014
Posts
30
Rep Power
0

## Re: Return value NaN

ah. Easy Mistake :(
Thanks again Jim

Could I possible ask for further assistance in my project? Or should I create a new thread?

6. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: Return value NaN

Oh, and what is the 60 for in your final conversion. I noticed you converted to degrees before multiplying by the radius. I believe the angle should still be kept in radians.

Regards,
Jim

7. Member
Join Date
Jun 2014
Posts
30
Rep Power
0

## Re: Return value NaN

I was doing a small tutorial that had this example, it stated that every degree on a great circle of Earth is 60 nautical miles

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•