Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Town {
- final int id;
- final String name;
- final double x,y;
- private static final double R= 6378.1370D;
- private static final double CONVERT_DEGREE_TO_RADIANS = Math.PI/180D;
- public Town(int id, String name, double x, double y) {
- this.id = id;
- this.name = name;
- this.x = x*CONVERT_DEGREE_TO_RADIANS;
- this.y = y*CONVERT_DEGREE_TO_RADIANS;
- }
- //distanza dal monumento al monumento inserito
- public double distanceTo(Town b){
- double deltaLat = (b.x - this.x);
- double deltaLon = (b.y-this.y);
- double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2)
- + Math.cos(this.x) * Math.cos(b.x)
- * Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
- double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
- double distance = R * c * 1000;
- return Math.sqrt(distance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement