Skip to content

Commit c960276

Browse files
A collection of tools for outdoor apps.xs
0 parents  commit c960276

File tree

9 files changed

+397
-0
lines changed

9 files changed

+397
-0
lines changed

.classpath

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Ignore these files
2+
3+
.mtj.tmp/
4+
*.class
5+
*.jar
6+
*.war
7+
*.ear
8+
*.nar
9+
hs_err_pid*
10+
replay_pid*
11+
doc/

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>OutDoorTools</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=15
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=15

src/Main.java

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import TimeTools.TimeDateFormat;
2+
import geoTools.SunriseSunset;
3+
import metroTools.AirPressure;
4+
import metroTools.DewPoint;
5+
6+
/**
7+
* Shows a demo of the various classes....
8+
*
9+
* @author berthold
10+
*
11+
*/
12+
public class Main {
13+
14+
private static final int DAY_OF_YEAR=260;
15+
private static final double LAT=54.2;
16+
private static final double LONG=6.12;
17+
private static final int TIME_ZONE=1;
18+
19+
public static void main(String[] args) {
20+
21+
//
22+
// Test of geo tools
23+
// Show sunrise/ sunset
24+
//
25+
26+
int dayOfYear=DAY_OF_YEAR; //TimeDateFormat.getDayOfCurrentYear();
27+
System.out.println("Day of year:"+dayOfYear);
28+
29+
System.out.println("Timezone:"+TimeDateFormat.getCurrentTimezoneName());
30+
System.out.println("Timezone:"+TimeDateFormat.getCurrentTimezoneOffset());
31+
System.out.println("Timezone GMT +"+TimeDateFormat.getTimeZoneOffsetIn_h());
32+
System.out.println("Longtitute:"+LONG+" Latitute:"+LAT);
33+
34+
double dec=SunriseSunset.getSunDeclinationIn_Rad(DAY_OF_YEAR);
35+
System.out.println("Declination:"+SunriseSunset.toGrad(dec));
36+
37+
double timeOfSunrise=SunriseSunset.getSunriseTimeAtObserversLocationIn_h(LONG, LAT, dayOfYear, TIME_ZONE);
38+
System.out.println("Sunrise:"+timeOfSunrise);
39+
System.out.println("Sunrise:"+TimeDateFormat.getTimeInTwentyFourHourFormat(timeOfSunrise));
40+
41+
double timeOfSunset=SunriseSunset.getSunsetTimeAtObserversLocationIn_h(LONG, LAT, dayOfYear, TIME_ZONE);
42+
System.out.println("Sunset:"+timeOfSunset);
43+
System.out.println("Sunset:"+TimeDateFormat.getTimeInTwentyFourHourFormat(timeOfSunset));
44+
45+
//
46+
// Metro tools
47+
//
48+
49+
// Dew Point
50+
float temperature=28; // Degrees...
51+
float relHum=30; // percent
52+
float dewPoint=DewPoint.dewPointTemperature_C(temperature,relHum );
53+
System.out.println("Dew point:"+dewPoint+" C'");
54+
55+
// Altitute from air pressure
56+
float refferencePressure_hPa=1000f;
57+
float actualPressure_hPa=996;
58+
float alt=AirPressure.altitude(actualPressure_hPa,refferencePressure_hPa);
59+
System.out.println("Altitude (relative to reffernece="+refferencePressure_hPa+")="+alt+" m");
60+
61+
62+
}
63+
64+
}

src/TimeTools/TimeDateFormat.java

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package TimeTools;
2+
3+
import java.util.Calendar;
4+
import java.util.Date;
5+
import java.util.TimeZone;
6+
7+
/**
8+
* A collection of utilities to format time and date.
9+
*
10+
* @author Berthold
11+
*
12+
*/
13+
public class TimeDateFormat {
14+
15+
/**
16+
* Hours and minutes.
17+
*
18+
* @param Representing the time in hours and minutes.
19+
* @return A String containing the hours and minutes from a double precission
20+
* value providing the time in decimal format.
21+
*/
22+
public static String getTimeInTwentyFourHourFormat(double timeIn_h) {
23+
int hours = (int) timeIn_h;
24+
int minutes = (int) (timeIn_h % 1 * 60);
25+
26+
return String.format("%02d", hours) + ":" + String.format("%02d", minutes);
27+
}
28+
29+
/**
30+
* Day of current year
31+
*
32+
* @return Day of the current year for the current date. 1st of January=1.
33+
*/
34+
public static int getDayOfCurrentYear() {
35+
Calendar cal = Calendar.getInstance();
36+
return cal.get(Calendar.DAY_OF_YEAR);
37+
}
38+
39+
/**
40+
* Current time zone short format.
41+
*
42+
* @return E.g. "Central Europeean Time".
43+
*/
44+
public static String getCurrentTimezoneName() {
45+
TimeZone timeZone = TimeZone.getDefault();
46+
return timeZone.getDisplayName();
47+
}
48+
49+
/**
50+
* Current time zone long format with city.
51+
*
52+
* @return Region/ City. E.g. "Europe/ Berlin"
53+
*/
54+
public static String getCurrentTimezoneOffset() {
55+
TimeZone timeZone = TimeZone.getDefault();
56+
return timeZone.getID();
57+
}
58+
59+
/**
60+
* Offset in hours relative to GMT (Greenwich mean time).
61+
*
62+
* @return Offset in hours.
63+
*/
64+
public static int getTimeZoneOffsetIn_h() {
65+
TimeZone timeZone = TimeZone.getDefault();
66+
return timeZone.getOffset(new Date().getTime()) / 1000 / 60 / 60;
67+
}
68+
69+
/**
70+
* @return Current time in decimal format.
71+
*/
72+
public static double getCurrentTimeInDec() {
73+
Calendar cal = Calendar.getInstance();
74+
double h = cal.get(Calendar.HOUR_OF_DAY);
75+
double m = cal.get(Calendar.MINUTE);
76+
return (h + (m / 60));
77+
78+
}
79+
}

src/geoTools/SunriseSunset.java

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package geoTools;
2+
3+
/**
4+
* Calculates the time of sunrise or sunset
5+
* at a given longitude and latititude.<p>
6+
*
7+
* Formulas are taken from: {@link https://lexikon.astronomie.info/zeitgleichung/index.html}
8+
*
9+
* @author Berthold Fritz
10+
*
11+
*/
12+
public class SunriseSunset {
13+
private static final double sunsetDecIn_Minutes=-0.0145; // Dec of sun below local lat for sunset
14+
private static final double NOON=12;
15+
16+
/**
17+
* Convert degrees to radians.
18+
*
19+
* @param grad
20+
* @return Given angle in degrees converted to radians.
21+
*/
22+
public static double toRad (double grad){
23+
return grad*Math.PI/180;
24+
}
25+
26+
/**
27+
* Convert radians to degrees.
28+
*
29+
* @param rad
30+
* @return Given angle in radians converted to degrees.
31+
*/
32+
public static double toGrad (double rad){
33+
return rad*180/Math.PI;
34+
}
35+
36+
/**
37+
* Time of sunrise at an observers location.
38+
* This is a convenient way to get a quick result whithout
39+
* calling all methods step by step.
40+
*
41+
* @param lng Longitude in degrees.
42+
* @param lat Latitude in degrees.
43+
* @param dayOfYear Day of year (1st of January is 1).
44+
* @param timeZone +/- relative to Greenwich Mean time (east is +, west is -)
45+
* @return Time of sunrise at the given location and timezone.
46+
*/
47+
public static double getSunriseTimeAtObserversLocationIn_h(double lng,double lat,int dayOfYear,int timeZone){
48+
double latIn_rad=toRad(lat);
49+
double longIn_rad=toRad(lng);
50+
51+
double declinationIn_rad=getSunDeclinationIn_Rad(dayOfYear);
52+
double deltaTimeIn_h=SunriseSunset.getDeltaTimeIn_h(declinationIn_rad,latIn_rad);
53+
double trueSunsetTimeIn_h=SunriseSunset.getTrueSunriseTimeIn_h(deltaTimeIn_h,dayOfYear);
54+
return getTimeAtLatitudeAndTimeZoneIn_h(trueSunsetTimeIn_h, longIn_rad, timeZone);
55+
}
56+
57+
/**
58+
* Time of sunset at an observers location.
59+
* This is a convenient way to get a quick result whithout
60+
* calling all methods step by step.
61+
*
62+
* @param lng Longitude in degrees.
63+
* @param lat Latitude in degrees.
64+
* @param dayOfYear Day of year (1st of January is 1).
65+
* @param timeZone +/- relative to Greenwich Mean time (east is +, west is -)
66+
* @return Time of sunset at the given location and timezone.
67+
*/
68+
public static double getSunsetTimeAtObserversLocationIn_h(double lng,double lat,int dayOfYear,int timeZone){
69+
double latIn_rad=toRad(lat);
70+
double longIn_rad=toRad(lng);
71+
72+
double declinationIn_rad=getSunDeclinationIn_Rad(dayOfYear);
73+
double deltaTimeIn_h=SunriseSunset.getDeltaTimeIn_h(declinationIn_rad,latIn_rad);
74+
double trueSunsetTimeIn_h=SunriseSunset.getTrueSunsetTimeIn_h(deltaTimeIn_h,dayOfYear);
75+
return getTimeAtLatitudeAndTimeZoneIn_h(trueSunsetTimeIn_h, longIn_rad, timeZone);
76+
}
77+
78+
/**
79+
* Declination.
80+
*
81+
* @param dayOfYear
82+
* @return Declination of sun in radians at a given day of year (1=1st of january).
83+
*/
84+
public static double getSunDeclinationIn_Rad(int dayOfYear){
85+
return 0.4095*Math.sin(0.016906*(dayOfYear-80.086));
86+
}
87+
88+
/**
89+
* Difference between true local time and avarge local time (time equation).
90+
*
91+
* @param dayOfYear
92+
* @return Time difference in hours.
93+
*/
94+
public static double timeEquation(int dayOfYear){
95+
return -0.171*Math.sin(0.0337*dayOfYear+0.465)-0.1299*Math.sin(0.01787*dayOfYear-0.168);
96+
}
97+
98+
/**
99+
* Time difference.
100+
*
101+
* @param decIn_Rad
102+
* @return Time differnece in hours until sun reaches a given latitude from
103+
* it's zenit.
104+
*/
105+
public static double getDeltaTimeIn_h(double decIn_Rad,double latitudeIn_rad){
106+
return 12*Math.acos((Math.sin(sunsetDecIn_Minutes)-Math.sin(latitudeIn_rad)*Math.sin(decIn_Rad))/(Math.cos(0.9163)*Math.cos(decIn_Rad)))/Math.PI;
107+
}
108+
109+
/**
110+
* True Sunrise time.
111+
*
112+
* @param deltaTimeIn_h
113+
* @return Time of sunrise in hours not compensated for average time at a given location
114+
* (time displayed on an observers watch).
115+
*/
116+
public static double getTrueSunriseTimeIn_h(double deltaTimeIn_h, int dayOfYear){
117+
return NOON-deltaTimeIn_h-timeEquation(dayOfYear);
118+
}
119+
120+
/**
121+
* True Sunset time.
122+
*
123+
* @param deltaTimeIn_h
124+
* @return Time of sunset in hours not compensated for average time at a given location
125+
* (time displayed on an observers watch).
126+
*/
127+
public static double getTrueSunsetTimeIn_h(double deltaTimeIn_h,int dayOfYear){
128+
return NOON+deltaTimeIn_h-timeEquation(dayOfYear);
129+
}
130+
131+
/**
132+
* Time at the latitude and timezone of the observer.
133+
*
134+
* @param gmtTimeIn_h
135+
* @param latitude
136+
* @param timeZoneIn_DeltaToGMTin_h
137+
* @return Time at a given latitude and timezone.
138+
*/
139+
public static double getTimeAtLatitudeAndTimeZoneIn_h(double gmtTimeIn_h,double latitude,int timeZoneIn_DeltaToGMTin_h){
140+
return gmtTimeIn_h-latitude/15+timeZoneIn_DeltaToGMTin_h;
141+
142+
}
143+
}

src/metroTools/AirPressure.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package metroTools;
2+
3+
/**
4+
* Metrological tools.
5+
*
6+
* @author berthold
7+
*
8+
*/
9+
public class AirPressure {
10+
11+
/**
12+
* Calculates the altitude based on the actual pressure mesured at an observers position
13+
* relative to a reffernce pressure. Pressures units are [hPa].
14+
*
15+
* @param actualPressure_hPa Pressure measured.
16+
* @param reffernecePressure_hPA Refference pressure.
17+
* @return Altitide in [m].
18+
*/
19+
public static float altitude (float actualPressure_hPa,float reffernecePressure_hPA){
20+
float pow=1/5.255f;
21+
float alt=(float) ((288.15/0.0065)*(1-(Math.pow((actualPressure_hPa/reffernecePressure_hPA),pow))));
22+
23+
return alt;
24+
}
25+
}

0 commit comments

Comments
 (0)