Results 1 to 17 of 17

Thread: Need Help

  1. #1
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default 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) *
    Math.cos(Math.toRadians(b.latitude)) * Math.cos(Math.toRadians(this.latitude));

    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));
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Need Help

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default Re: Need Help

    huh?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Need Help

    Click the links. Read the pages.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default 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
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default 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?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default 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...

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: Need Help

    What are negative degrees?
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default Re: Need Help

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

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Need Help

    Quote Originally Posted by xdrazkalnytex View Post
    ... 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.

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: Need Help

    If you do not know what negative degrees are, how can you use them correctly?
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default Re: Need Help

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

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: Need Help

    Degrees for positions are either: N, S, E or W
    - must be one of those.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default Re: Need Help

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

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    xdrazkalnytex is offline Member
    Join Date
    Mar 2012
    Posts
    34
    Rep Power
    0

    Default Re: Need Help

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

Posting Permissions

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