Definition at line 12 of file SUMOLane.java.
Public Member Functions | |
| double | getLength () |
| Point | getPositionWithin (double pos) |
| SUMOLane (String id) | |
Data Fields | |
| String | id |
| List< Point > | points = new LinkedList<Point>() |
Private Attributes | |
| double | length = -1 |
| de::psi::telco::sumoplayer::SUMOLane::SUMOLane | ( | String | id | ) | [inline] |
| double de::psi::telco::sumoplayer::SUMOLane::getLength | ( | ) | [inline] |
Definition at line 23 of file SUMOLane.java.
References length, and points.
Referenced by getPositionWithin().
00023 { 00024 if (length == -1){ 00025 length = 0; 00026 Iterator i = points.iterator(); 00027 Point a = null; 00028 Point b = null; 00029 while (i.hasNext()){ 00030 if (a == null){ 00031 a = (Point)i.next(); 00032 continue; 00033 } 00034 b = (Point)i.next(); 00035 00036 length += GeoCalc.distance(a, b); 00037 00038 a = b; 00039 } 00040 return length; 00041 }else{ 00042 return length; 00043 } 00044 }
| Point de::psi::telco::sumoplayer::SUMOLane::getPositionWithin | ( | double | pos | ) | [inline] |
Definition at line 46 of file SUMOLane.java.
References de::psi::telco::sumoplayer::util::PointImpl::add(), de::psi::telco::sumoplayer::util::PointImpl::distance(), getLength(), de::psi::telco::sumoplayer::util::Vector::getX(), de::psi::telco::sumoplayer::util::Vector::getY(), and points.
00046 { 00047 //System.out.println("GetPosWithin: laneId:"+this.id+" - req pos: "+pos+" - cal len:"+this.getLength()); 00048 if (this.getLength()<=pos){ // near end. returning last point 00049 return points.get(points.size()-1); // just return last point 00050 } 00051 try{ 00052 int idx = 0; 00053 double len = 0; 00054 Iterator i = points.iterator(); 00055 Point a = null; 00056 Point b = null; 00057 boolean foundWithin = false; 00058 while (i.hasNext()){ 00059 if (a == null){ 00060 a = (Point)i.next(); 00061 continue; 00062 } 00063 00064 b = (Point)i.next(); 00065 if (len+GeoCalc.distance(a,b)<pos){ 00066 len += GeoCalc.distance(a,b); 00067 idx++; 00068 }else{ 00069 foundWithin = true; 00070 break; 00071 } 00072 00073 a = b; 00074 } 00075 00076 // sometimes requested positions lies a bit outside the lane. dont know why. 00077 if (foundWithin){ // TODO: check if this is just a sumo mistake 00078 PointImpl startPos = new PointImpl(points.get(idx).getX(),points.get(idx).getY()); 00079 PointImpl endPos = new PointImpl(points.get(idx+1).getX(),points.get(idx+1).getY()); 00080 double partialLen = startPos.distance(endPos); 00081 double rest = pos-len; 00082 double fact = rest/partialLen; 00083 00084 Vector out = startPos.add((endPos.sub(startPos).scale(fact))); 00085 return new PointImpl(out.getX(),out.getY()); 00086 }else{ 00087 return points.get(points.size()-1); // just return last point 00088 } 00089 00090 }catch(Exception e){ 00091 e.printStackTrace(); 00092 return new PointImpl(0,0); 00093 } 00094 }
Definition at line 14 of file SUMOLane.java.
double de::psi::telco::sumoplayer::SUMOLane::length = -1 [private] |
| List<Point> de::psi::telco::sumoplayer::SUMOLane::points = new LinkedList<Point>() |
1.5.6