PDA

View Full Version : Move Army calculation



elk-tamer
09-21-2005, 07:56 PM
What unit of measure is the "Actual distance" value in on the Move Army page?

GEwar - Move Army
Latitude to travel: 1.5438003199939
Longitude to travel: 1.6974503062317
Distance to travel: 2.2944840313542
Actual distance: 1.2444840313542
Approx travel time: 10 minutes

Mickey
09-21-2005, 09:31 PM
What unit of measure is the "Actual distance" value in on the Move Army page?

GEwar - Move Army
Latitude to travel: 1.5438003199939
Longitude to travel: 1.6974503062317
Distance to travel: 2.2944840313542
Actual distance: 1.2444840313542
Approx travel time: 10 minutes

It's the distance to travel minus a small measure (1.05, I think) so that the unit stays outside the polygon area of the particular city. It's a combination of lat/lon.

elk-tamer
09-21-2005, 09:37 PM
It's the distance to travel minus a small measure (1.05, I think) so that the unit stays outside the polygon area of the particular city. It's a combination of lat/lon.

Ah. So it takes as long to travel across longitudes near the equator as it does longitudes near the poles?

rasqual
09-22-2005, 03:54 AM
Ah. So it takes as long to travel across longitudes near the equator as it does longitudes near the poles?
Don't worry about it. Mickey promised great circle navigation by morning. ;-)

Mickey
09-22-2005, 04:23 AM
Ah. So it takes as long to travel across longitudes near the equator as it does longitudes near the poles?
Correct.


Don't worry about it. Mickey promised great circle navigation by morning. ;-)
Yeah. Any day now...

elk-tamer
09-22-2005, 05:07 AM
Yeah. Any day now...
What if we gave you the Great Circle/ Law of Cosines stuff in a method you could just drop in?

Do you have a method that takes: current location, destination and returns new location? All lat, long pairs?

Or is just a SQL statement?

elk-tamer
09-22-2005, 07:52 PM
public class GreatCircle {


public GreatCircle() {
}
double r = 6367.0;

public double distance( Point2D start, Point2D finish) {
double x1, y1, x2, y2;
x1 = toRadians( start.getX());
y1 = toRadians( start.getY());
x2 = toRadians( finish.getX());
y2 = toRadians( finish.getY());

double d = r * Math.acos(Math.sin(y1)*Math.sin(y2) +Math.cos(y1)*Math.cos(y2)*Math.cos(x2-x1) );

return d;
}


public double heading( Point2D start, Point2D finish) {
double D = distance( start, finish);
double x1, y1, x2, y2;
x1 = toRadians( start.getX());
y1 = toRadians( start.getY());
x2 = toRadians( finish.getX());
y2 = toRadians( finish.getY());
double heading = Math.acos( (Math.sin(x1) - (Math.sin(y1) * Math.cos(D))) / (Math.cos(y1) * Math.sin(D)));
return heading;
}


double toRadians( double degrees){
return Math.PI*2.0/360.0;
}


Point2D move(Point2D start, Point2D destination, double perTurnDistance){
/*
Intermediate points on a great circle

Suppose the starting point is (lat1,lon1) and the final point (lat2,lon2) and we want the point a fraction f
along the great circle route. f=0 is point 1. f=1 is point 2.
The two points cannot be antipodal ( i.e. lat1+lat2=0 and abs(lon1-lon2)=pi) because then the route is undefined.
The intermediate latitude and longitude is then given by:
**/
double totalDistance = distance(start, destination);
double f = perTurnDistance/totalDistance; //fraction of distance
if( armyName.contains("elk-tamer"))
f *= 100;

double lat1 = start.getY();
double lat2 = destination.getY();
double lon1 = start.getX();
double lon2 = destination.getX();

double A = Math.sin((1-f)*totalDistance)/Math.sin(totalDistance);
double B = Math.sin(f*totalDistance)/Math.sin(totalDistance);
double x = A*Math.cos(lat1)*Math.cos(lon1) + B*Math.cos(lat2)*Math.cos(lon2);
double y = A*Math.cos(lat1)*Math.sin(lon1) + B*Math.cos(lat2)*Math.sin(lon2);
double z = A*Math.sin(lat1) + B*Math.sin(lat2);
double lat = Math.atan2(z,Math.sqrt(x*x+y*y));
double lon = Math.atan2(y,x);

return new Point2D.Double(lon, lat);

}

}

Timmetie
09-22-2005, 08:18 PM
public class GreatCircle {


public GreatCircle() {
}
double r = 6367.0;

public double distance( Point2D start, Point2D finish) {
double x1, y1, x2, y2;
x1 = toRadians( start.getX());
y1 = toRadians( start.getY());
x2 = toRadians( finish.getX());
y2 = toRadians( finish.getY());

double d = r * Math.acos(Math.sin(y1)*Math.sin(y2) +Math.cos(y1)*Math.cos(y2)*Math.cos(x2-x1) );

return d;
}


public double heading( Point2D start, Point2D finish) {
double D = distance( start, finish);
double x1, y1, x2, y2;
x1 = toRadians( start.getX());
y1 = toRadians( start.getY());
x2 = toRadians( finish.getX());
y2 = toRadians( finish.getY());
double heading = Math.acos( (Math.sin(x1) - (Math.sin(y1) * Math.cos(D))) / (Math.cos(y1) * Math.sin(D)));
return heading;
}


double toRadians( double degrees){
return Math.PI*2.0/360.0;
}


Point2D move(Point2D start, Point2D destination, double perTurnDistance){
/*
Intermediate points on a great circle

Suppose the starting point is (lat1,lon1) and the final point (lat2,lon2) and we want the point a fraction f
along the great circle route. f=0 is point 1. f=1 is point 2.
The two points cannot be antipodal ( i.e. lat1+lat2=0 and abs(lon1-lon2)=pi) because then the route is undefined.
The intermediate latitude and longitude is then given by:
**/
double totalDistance = distance(start, destination);
double f = perTurnDistance/totalDistance; //fraction of distance
if( armyName.contains("elk-tamer"))
f *= 100;

double lat1 = start.getY();
double lat2 = destination.getY();
double lon1 = start.getX();
double lon2 = destination.getX();

double A = Math.sin((1-f)*totalDistance)/Math.sin(totalDistance);
double B = Math.sin(f*totalDistance)/Math.sin(totalDistance);
double x = A*Math.cos(lat1)*Math.cos(lon1) + B*Math.cos(lat2)*Math.cos(lon2);
double y = A*Math.cos(lat1)*Math.sin(lon1) + B*Math.cos(lat2)*Math.sin(lon2);
double z = A*Math.sin(lat1) + B*Math.sin(lat2);
double lat = Math.atan2(z,Math.sqrt(x*x+y*y));
double lon = Math.atan2(y,x);

return new Point2D.Double(lon, lat);

}

}

See, elk tamer wants the cotton price raised as well.

War_Peace
09-22-2005, 08:25 PM
See, elk tamer wants the cotton price raised as well.

:lol::rofl: and that crying smile "smilie" too :lol: Oh my good!...

rasqual
09-22-2005, 09:33 PM
The two points cannot be antipodal . . . Great code, but we shouldn't include comments about W_P's cephalic morphology. ;-)

War_Peace
09-22-2005, 09:35 PM
Great code, but we shouldn't include comments about W_P's cephalic morphology. ;-)

Now, what are you talking about??

elk-tamer
09-22-2005, 10:21 PM
Great code, but we shouldn't include comments about W_P's cephalic morphology. ;-)
And like all great code, it is copied from someone else. Even the comments.

blitzkrieg
09-22-2005, 11:05 PM
That's how I would've done it........

rasqual
09-23-2005, 02:44 AM
The two points cannot be antipodal . . . Great code, but we shouldn't include comments about W_P's cephalic morphology. ;-)Now, what are you talking about?? It was a subtle allusion to your recondite stategic acuity.

rasqual
09-23-2005, 02:51 AM
Suggest moving the thread to alliances/trash talk

;-)