# Need Help

• 04-23-2012, 07:27 AM
xdrazkalnytex
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));
}
}
• 04-23-2012, 09:04 AM
DarrylBurke
Re: Need Help
• 04-23-2012, 06:33 PM
xdrazkalnytex
Re: Need Help
huh?
• 04-23-2012, 07:29 PM
DarrylBurke
Re: Need Help

db
• 04-23-2012, 07:45 PM
Norm
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
• 04-23-2012, 08:20 PM
xdrazkalnytex
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?
• 04-23-2012, 08:23 PM
Norm
Re: Need Help
Quote:

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

Quote:

I dont remember how to do the great circle distance.
It would be important to have the correct formula.
• 04-23-2012, 08:25 PM
xdrazkalnytex
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...
• 04-23-2012, 08:27 PM
Norm
Re: Need Help
What are negative degrees?
• 04-23-2012, 08:30 PM
xdrazkalnytex
Re: Need Help
for Trig functions? If so isn't it Reciprocal? Sin-1 , Cos -1 , Tan -1
• 04-23-2012, 08:31 PM
Fubarable
Re: Need Help
Quote:

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.
• 04-23-2012, 08:38 PM
Norm
Re: Need Help
If you do not know what negative degrees are, how can you use them correctly?
• 04-24-2012, 02:55 AM
xdrazkalnytex
Re: Need Help
i don't remember anything about negative degrees. That's the thing
• 04-24-2012, 02:58 AM
Norm
Re: Need Help
Degrees for positions are either: N, S, E or W
- must be one of those.
• 04-24-2012, 03:22 AM
xdrazkalnytex
Re: Need Help
So negative degrees would be the opposite - N, - S, -E, -W
• 04-24-2012, 03:26 AM
Norm
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?
• 04-24-2012, 03:31 AM
xdrazkalnytex
Re: Need Help
Oh. I got it. Thanks a lot Norm. You were helpful.