summaryrefslogtreecommitdiff
path: root/trunk/src/nav/processLoc.java
diff options
context:
space:
mode:
authormanut <manut@58fc9717-fb00-483d-b79c-3a878c4e3be5>2007-08-12 11:39:18 +0000
committermanut <manut@58fc9717-fb00-483d-b79c-3a878c4e3be5>2007-08-12 11:39:18 +0000
commit1caba29952307e005eae662fcace54b2252b8c97 (patch)
tree57a5977cedc20b92a9878916c1095cb152fc79e5 /trunk/src/nav/processLoc.java
InitialHEADmaster
git-svn-id: svn+ssh://mecka.net/home/svn/geoc@1 58fc9717-fb00-483d-b79c-3a878c4e3be5
Diffstat (limited to 'trunk/src/nav/processLoc.java')
-rwxr-xr-xtrunk/src/nav/processLoc.java104
1 files changed, 104 insertions, 0 deletions
diff --git a/trunk/src/nav/processLoc.java b/trunk/src/nav/processLoc.java
new file mode 100755
index 0000000..fdcd863
--- /dev/null
+++ b/trunk/src/nav/processLoc.java
@@ -0,0 +1,104 @@
+/*
+ * processLoc.java
+ *
+ * Created on July 14, 2007, 4:59 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package nav;
+
+import java.lang.Thread;
+import javax.microedition.location.*;
+
+import gui.*;
+
+/**
+ *
+ * @author manut
+ */
+public class processLoc extends Thread {
+
+ private geoc gui;
+ private Landmark dest;
+ private Location loc;
+ private Coordinates lastloc;
+ private Coordinates north;
+
+ /** Creates a new instance of processLoc */
+ public processLoc(geoc _gui) {
+ gui = _gui;
+ north = new Coordinates(90, 0, 0);
+ lastloc = null;
+ }
+
+ public void set(Location _loc, Landmark _dest){
+
+ loc = _loc;
+ dest = _dest;
+
+ }
+
+ private double arcsin(double azimuth){
+ double calc;
+ double last_calc = 0;
+
+ for(double i = -1; i <= 1; i=i+0.001){
+ calc = java.lang.Math.sin(i);
+ if ( calc == azimuth ){
+ return i;
+ } else if (last_calc <= azimuth && calc > azimuth){
+ return i;
+ } else
+ last_calc = calc;
+ }
+ return -2;
+ }
+
+ public void run(){
+ // calc course, distance
+ // A = LastPosition
+ // B = Destination
+ // C = Northpole
+ // D = ActPosition
+ // E = going further on straight forward, until you meet BC
+ //
+ // alphaI = arcsin( ( CD * sin(gammaI) ) / AB )
+ // betaI = arcsin( ( CD * sin(gammaII)) / BD )
+ // deltaI = 180 - alphaI - gammaI
+ // deltaII = 180 - deltaI
+ // epsilI = 180 - deltaII - gammaII
+ // epsilII = 180 - epsilI
+ // gesucht = 180 - epsilII - betaI
+ // --> courseCorrection = - 180 - arcsin( (CD * sin(gammaI)) / AB ) - gammaI - gammaII - arcsin( CD * (sin(gammaII)) / BD )
+
+ if( (lastloc!= null) && loc.isValid())
+ {
+
+ float gammaI = lastloc.azimuthTo(loc.getQualifiedCoordinates());
+ float gammaII = loc.getQualifiedCoordinates().azimuthTo(dest.getQualifiedCoordinates());
+ float AB = lastloc.distance(dest.getQualifiedCoordinates());
+ float BD = loc.getQualifiedCoordinates().distance(dest.getQualifiedCoordinates());
+ float CD = loc.getQualifiedCoordinates().distance(north);
+
+ double actC = ( - 180 - arcsin( (CD * java.lang.Math.sin(gammaI)) / AB ) - gammaI - gammaII - arcsin( CD * (java.lang.Math.sin(gammaII)) / BD ) ) % 360;
+ int actCourse = (int) actC;
+ if (actCourse < 0)
+ actCourse = actCourse+360;
+
+ // set GUI
+ gui.get_stringItemActNorth().setText(Coordinates.convert(loc.getQualifiedCoordinates().getLatitude(), 2));
+ gui.get_stringItemActEast().setText(Coordinates.convert(loc.getQualifiedCoordinates().getLongitude(), 2));
+ gui.get_stringItemActHeight().setText(String.valueOf(loc.getQualifiedCoordinates().getAltitude()));
+ if ( (actCourse != 112) )
+ gui.get_stringItemCourse().setText(String.valueOf(actCourse));
+ gui.get_stringItemDistance().setText(String.valueOf(BD));
+
+ }
+
+ if ( loc.isValid() )
+ lastloc = loc.getQualifiedCoordinates();
+ }
+
+}