/* * 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(); } }