RiverRat  - An MIT iCampus project http://web.mit.edu/riverrat/

Main Page | Software Documentation | Hardware Documentation | People | Contact | Wiki

Main Page | Class Hierarchy | Class List | File List | Class Members

RaceObject.java

00001 package riverrat;
00002 
00003 import java.util.Vector;
00004 
00012 public class RaceObject {
00013         static final boolean DEBUG = false;
00014 
00015         Fix thefix;
00016         Vector track;
00017         int id;
00018         int sn;
00019         int tracklength = 5000;
00020         
00026         public RaceObject() {
00027                 id = -1;
00028                 thefix = new Fix();
00029                 track = new Vector();
00030         }
00031         
00038         public RaceObject(int newid) {
00039                 id = newid;
00040                 thefix = new Fix();
00041                 track = new Vector();
00042         }
00043         
00050         public Vector getTrack() {
00051                 return track;
00052         }
00053         
00059         public void setTrackLength(int length) {
00060                 tracklength = length;
00061         }
00062         
00068         public float getHeading() {
00069                 return thefix.getHeading();
00070         }
00071         
00077         public Fix getFix() {
00078                 return thefix;
00079         }
00080         
00087         public float getLat() {
00088                 return thefix.getLat();
00089         }
00090         
00097         public float getLon() {
00098                 return thefix.getLon();
00099         }
00100         
00106         public int getID() {
00107                 return id;
00108         }
00109         
00115         public int getSN() {
00116                 return sn;
00117         }
00118         
00124         public void setSN(int newsn) {
00125                 sn = newsn;
00126         }
00127         
00138         public void update(Fix newfix) {
00139                 if (newfix.getHeading() == -1.0f) {
00140                         //use arctan function to convert from lat/lon differences to radian heading
00141                         float tempheading = (float) (Math.atan2(newfix.getLat()-thefix.getLat(),newfix.getLon()-thefix.getLon()));
00142                         //tempheading is in radians (plus or minus) from the x-axis, where the + direction is ccw
00143                         tempheading = (-tempheading) + (float) (Math.PI/2.0f);
00144                         //shifted, zero now corresponds to y-axis (north) but range is from -Pi/2 to +3Pi/2
00145                         if(tempheading < 0) {
00146                                 tempheading = tempheading+(float) (2.0f*Math.PI);
00147                         } //range now goes from 0 to 2Pi, where zero corresponds to north
00148                         newfix.setHeading(tempheading);
00149                         if(DEBUG) System.out.println("update(): heading has been set to "+newfix.getHeading());
00150                 }
00151                 track.addElement(newfix); //add new value to the bottom of the vector
00152                 if(track.size() > tracklength) {
00153                         track.removeElementAt(0); //remove oldest value from the top of the vector
00154                 }
00155                 thefix = newfix; //set the current position to the new value
00156                 if(DEBUG) {
00157                         System.out.println("update(): track has been changed to");
00158                         for(int i = 0; i < track.size() ; i++) {
00159                                 System.out.println("update(): rank "+i+" is "+((Fix)track.elementAt(i)).fixToString());
00160                         }
00161                 }
00162         }
00163         
00169         public String objectToString() {
00170                 return ("RaceObject "+id+": "+thefix.fixToString()+"  "+(int) (((360.0f*thefix.getHeading())/(2.0f*Math.PI)))+"¡");
00171         }
00172 }
 

Brought to you by the RiverRat team.