1. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Need Help

Im working on a homework assignment, looking for the great distance formula can someone help me? i try it but got the wrong answer

// GeoLocation.java

public class GeoLocation
{
private double latitude;
private double longitude;

// Construct a GeoLocation given the latitude and longitude.
public GeoLocation(double latitude, double longitude)
{
//
this.latitude = latitude;
this.longitude = longitude;
}

// Return the great circle distance between this location and b.
public double distanceTo(GeoLocation b)
{
// TBD
GeoLocation a = this;
double a1 = Math.sin(Math.toRadians(b.latitude - this.latitude) / 2 ) * Math.sin(Math.toRadians(b.latitude - this.latitude) / 2) +
Math.sin(Math.toRadians(b.longitude - this.longitude) / 2 ) * Math.sin(Math.toRadians(b.longitude - this.longitude) / 2) *

return a1;
}

// Is this location the same as b?
public boolean equals(GeoLocation b)
{
// TBD
if(b==this)
return true;
if(b==null)
return false;
GeoLocation a = this;
GeoLocation c = this;
return (a.latitude == b.latitude) && (a.longitude == b.longitude) && (b.latitude == c.latitude) && (b.longitude == c.longitude);
}

// Return a String representation of this location.
public String toString()
{
// TBD
return " " + latitude + " " + longitude + " ";
}

// Test driver.
public static void main(String[] args)
{
GeoLocation a = new GeoLocation(48.87, -2.33);
GeoLocation b = new GeoLocation(37.8, 122.4);
GeoLocation c = new GeoLocation(37.8, 122.4);
System.out.println("Should print 48.87, -2.33: " + a);
System.out.println("Should print 5561.369177680733: " +
a.distanceTo(b));
System.out.println("Should print false: " + a.equals(b));
System.out.println("Should print true: " + b.equals(c));
}
}  Reply With Quote

2. ## Re: Need Help  Reply With Quote

3. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Re: Need Help

huh?  Reply With Quote

4. ## Re: Need Help

db  Reply With Quote

5. ## Re: Need Help

What is the correct equation for computing the great circle distance between two locations?
What does a negative degrees represent? -2.33  Reply With Quote

6. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Re: Need Help

I dont remember how to do the great circle distance.
I think the equation is Math.acos(Math.sin(x1) * Math.sin(x2) + Math.cos(x1) * Math.cos(x2) * Math.cos(y1 - y2));. Not sure if I am writing it right or not in my code. I'm not sure what you mean by negative degree? Are you talking about radians?  Reply With Quote

7. ## Re: Need Help

what you mean by negative degree?
new GeoLocation(48.87, -2.33);

I dont remember how to do the great circle distance.
It would be important to have the correct formula.  Reply With Quote

8. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Re: Need Help

Oh, That's what the output supposed to look like. I got all of the output correct except for the great circle one , which I have no idea how to do and working on it right now. I forgot the great circle distance formula...  Reply With Quote

9. ## Re: Need Help

What are negative degrees?  Reply With Quote

10. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Re: Need Help

for Trig functions? If so isn't it Reciprocal? Sin-1 , Cos -1 , Tan -1  Reply With Quote

11. ## Re: Need Help Originally Posted by xdrazkalnytex ... I forgot the great circle distance formula...
That can be looked up.

*Edit* and shoot, I just found it in 2 seconds on Wikipedia. I'm betting you can too.  Reply With Quote

12. ## Re: Need Help

If you do not know what negative degrees are, how can you use them correctly?  Reply With Quote

13. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Re: Need Help

i don't remember anything about negative degrees. That's the thing  Reply With Quote

14. ## Re: Need Help

Degrees for positions are either: N, S, E or W
- must be one of those.  Reply With Quote

15. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Re: Need Help

So negative degrees would be the opposite - N, - S, -E, -W  Reply With Quote

16. ## Re: Need Help

There are no such thing as negative degrees when designation a location on earth. You use the - to chose either E or W or N or S
What is the -2.33? Is that East or West longitude? Is that in Paris or Brest?
Last edited by Norm; 04-24-2012 at 03:29 AM.  Reply With Quote

17. Member Join Date
Mar 2012
Posts
34
Rep Power
0

## Re: Need Help

Oh. I got it. Thanks a lot Norm. You were helpful.  Reply With Quote

#### Posting Permissions

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