-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperations.java
More file actions
84 lines (69 loc) · 1.79 KB
/
Operations.java
File metadata and controls
84 lines (69 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
public class Operations
{
private static double deg2rad(double deg) {
return (deg * Math.PI / 180.0);
}
private static double rad2deg(double rad) {
return (rad * 180 / Math.PI);
}
public static double getDistance(Node node1, Node node2)
{
double theta;
double dist;
theta = node1.lon - node2.lon;
dist = Math.sin(deg2rad(node1.lat)) * Math.sin(deg2rad(node2.lat)) +
Math.cos(deg2rad(node1.lat)) * Math.cos(deg2rad(node2.lat)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist *= 60 * 1.1515;
dist *= 1.609344;
return (dist);
}
public static double getDistanceLatLon(double lat1, double lon1, double lat2, double lon2)
{
double theta;
double dist;
theta = lon1 - lon2;
dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
dist *= 60 * 1.1515;
dist *= 1.609344;
return (dist);
}
public static double getLengthOfWay(Way way)
{
double length;
int i;
if (way.nodes.length == 0)
return getDistance(way.start, way.end);
length = getDistance(way.start, way.nodes[0]);
i = 0;
while (i < way.nodes.length - 1)
{
length += getDistance(way.nodes[i], way.nodes[i + 1]);
i++;
}
length += getDistance(way.nodes[way.nodes.length - 1], way.end);
return (length);
}
public static int getActualSpeed(Way way)
{
return (way.speed_limit - 5);
}
public static double getTimeCostOfNode(Node node)
{
return (10.0);
}
public static double getTimeCostOfEndNode(Way way, boolean takeReverse)
{
if (takeReverse)
return (way.startNodeTime);
return (way.endNodeTime);
}
public static double getTimeToTravelWay(Way way)
{
return (way.length / way.actual_speed * 60.0 * 60.0);
}
}