#include <GeomHelper.h>
Definition at line 47 of file GeomHelper.h.
Static Public Member Functions | |
| static SUMOReal | Angle2D (SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2) |
| static SUMOReal | closestDistancePointLine (const Position2D &point, const Position2D &lineStart, const Position2D &lineEnd, Position2D &outIntersection) |
| static Position2D | crossPoint (const Boundary &b, const Position2DVector &v) |
| static SUMOReal | distancePointLine (const Position2D &point, const Position2D &lineStart, const Position2D &lineEnd) |
| static Position2D | extrapolate_first (const Position2D &p1, const Position2D &p2, SUMOReal length) |
| static Position2D | extrapolate_second (const Position2D &p1, const Position2D &p2, SUMOReal length) |
| static SUMOReal | getCCWAngleDiff (SUMOReal angle1, SUMOReal angle2) throw () |
| Returns the distance of second angle from first angle counter-clockwise. | |
| static SUMOReal | getCWAngleDiff (SUMOReal angle1, SUMOReal angle2) throw () |
| Returns the distance of second angle from first angle clockwise. | |
| static SUMOReal | getMaxAngleDiff (SUMOReal angle1, SUMOReal angle2) throw () |
| Returns the maximum distance (clockwise/counter-clockwise) between both angles. | |
| static SUMOReal | getMinAngleDiff (SUMOReal angle1, SUMOReal angle2) throw () |
| Returns the minimum distance (clockwise/counter-clockwise) between both angles. | |
| static std::pair< SUMOReal, SUMOReal > | getNormal90D_CW (const Position2D &beg, const Position2D &end, SUMOReal wanted_offset) |
| static std::pair< SUMOReal, SUMOReal > | getNormal90D_CW (const Position2D &beg, const Position2D &end, SUMOReal length, SUMOReal wanted_offset) |
| static Position2D | interpolate (const Position2D &p1, const Position2D &p2, SUMOReal length) |
| static Position2D | intersection_position (const Position2D &p11, const Position2D &p12, const Position2D &p21, const Position2D &p22) |
| static bool | intersects (const Position2D &p11, const Position2D &p12, const Position2D &p21, const Position2D &p22) |
| static bool | intersects (SUMOReal x1b, SUMOReal y1b, SUMOReal x1e, SUMOReal y1e, SUMOReal x2b, SUMOReal y2b, SUMOReal x2e, SUMOReal y2e) |
| static SUMOReal | nearest_position_on_line_to_point (const Position2D &l1, const Position2D &l2, const Position2D &p) |
| static Position2D | transfer_to_side (Position2D &p, const Position2D &lineBeg, const Position2D &lineEnd, SUMOReal amount) |
| SUMOReal GeomHelper::Angle2D | ( | SUMOReal | x1, | |
| SUMOReal | y1, | |||
| SUMOReal | x2, | |||
| SUMOReal | y2 | |||
| ) | [static] |
Definition at line 168 of file GeomHelper.cpp.
Referenced by Position2DVector::around(), NGRandomNetBuilder::checkAngles(), and Position2DVector::move2side().
00168 { 00169 SUMOReal dtheta,theta1,theta2; 00170 00171 theta1 = atan2(y1,x1); 00172 theta2 = atan2(y2,x2); 00173 dtheta = theta2 - theta1; 00174 while (dtheta > (SUMOReal) PI) 00175 dtheta -= (SUMOReal)(2.0*PI); 00176 while (dtheta < (SUMOReal) -PI) 00177 dtheta += (SUMOReal)(2.0*PI); 00178 00179 return(dtheta); 00180 }
| SUMOReal GeomHelper::closestDistancePointLine | ( | const Position2D & | point, | |
| const Position2D & | lineStart, | |||
| const Position2D & | lineEnd, | |||
| Position2D & | outIntersection | |||
| ) | [static] |
Return the distance from point to line as well as the intersection point. If intersection does not lie within the line segment, the start or end point of the segment is returned
Definition at line 244 of file GeomHelper.cpp.
References Position2D::distanceTo(), Position2D::set(), SUMOReal, Position2D::x(), and Position2D::y().
Referenced by traci::TraCIServer::convertCartesianToRoadMap().
00247 { 00248 Position2D directVec(lineEnd.x()-lineStart.x(), lineEnd.y()-lineStart.y()); 00249 SUMOReal u = (((point.x() - lineStart.x()) * directVec.x()) + 00250 ((point.y() - lineStart.y()) * directVec.y())) / 00251 (directVec.x() * directVec.x() + 00252 directVec.y() * directVec.y()); 00253 00254 // if closest point does not fall within the line segment 00255 // return line start or line end 00256 00257 if (u >= 0.0f && u <= 1.0f) { 00258 outIntersection.set( 00259 lineStart.x() + u * directVec.x(), 00260 lineStart.y() + u * directVec.y()); 00261 } else { 00262 if (u < 0.0f) { 00263 outIntersection = lineStart; 00264 } 00265 if (u > 1.0f) { 00266 outIntersection = lineEnd; 00267 } 00268 } 00269 return point.distanceTo(outIntersection); 00270 }
| Position2D GeomHelper::crossPoint | ( | const Boundary & | b, | |
| const Position2DVector & | v | |||
| ) | [static] |
Definition at line 316 of file GeomHelper.cpp.
References Position2DVector::intersects(), Position2DVector::intersectsAtPoint(), Boundary::xmax(), Boundary::xmin(), Boundary::ymax(), and Boundary::ymin().
Referenced by NIVissimConnectionCluster::getPositionForEdge().
00316 { 00317 if (v.intersects(Position2D(b.xmin(), b.ymin()), Position2D(b.xmin(), b.ymax()))) { 00318 return v.intersectsAtPoint( 00319 Position2D(b.xmin(), b.ymin()), 00320 Position2D(b.xmin(), b.ymax())); 00321 } 00322 if (v.intersects(Position2D(b.xmax(), b.ymin()), Position2D(b.xmax(), b.ymax()))) { 00323 return v.intersectsAtPoint( 00324 Position2D(b.xmax(), b.ymin()), 00325 Position2D(b.xmax(), b.ymax())); 00326 } 00327 if (v.intersects(Position2D(b.xmin(), b.ymin()), Position2D(b.xmax(), b.ymin()))) { 00328 return v.intersectsAtPoint( 00329 Position2D(b.xmin(), b.ymin()), 00330 Position2D(b.xmax(), b.ymin())); 00331 } 00332 if (v.intersects(Position2D(b.xmin(), b.ymax()), Position2D(b.xmax(), b.ymax()))) { 00333 return v.intersectsAtPoint( 00334 Position2D(b.xmin(), b.ymax()), 00335 Position2D(b.xmax(), b.ymax())); 00336 } 00337 throw 1; 00338 }
| SUMOReal GeomHelper::distancePointLine | ( | const Position2D & | point, | |
| const Position2D & | lineStart, | |||
| const Position2D & | lineEnd | |||
| ) | [static] |
by Damian Coventry
Definition at line 227 of file GeomHelper.cpp.
References Position2D::distanceSquaredTo(), Position2D::distanceTo(), SUMOReal, Position2D::x(), and Position2D::y().
Referenced by NGRandomNetBuilder::canConnect(), Position2DVector::pruneFromBeginAt(), Position2DVector::pruneFromEndAt(), and Position2DVector::removeColinearPoints().
00229 { 00230 SUMOReal u = (((point.x() - lineStart.x()) * (lineEnd.x() - lineStart.x())) + 00231 ((point.y() - lineStart.y()) * (lineEnd.y() - lineStart.y())) 00232 ) / lineStart.distanceSquaredTo(lineEnd); 00233 if (u < 0.0f || u > 1.0f) 00234 return -1; // closest point does not fall within the line segment 00235 Position2D intersection( 00236 lineStart.x() + u *(lineEnd.x() - lineStart.x()), 00237 lineStart.y() + u *(lineEnd.y() - lineStart.y())); 00238 return point.distanceTo(intersection); 00239 }
| Position2D GeomHelper::extrapolate_first | ( | const Position2D & | p1, | |
| const Position2D & | p2, | |||
| SUMOReal | length | |||
| ) | [static] |
Definition at line 194 of file GeomHelper.cpp.
References Position2D::distanceTo(), SUMOReal, Position2D::x(), and Position2D::y().
Referenced by Position2DVector::extrapolate(), Line2D::extrapolateFirstBy(), and Position2DVector::pruneFromBeginAt().
00195 { 00196 SUMOReal oldlen = p1.distanceTo(p2); 00197 SUMOReal x = p1.x() - (p2.x() - p1.x()) * (length) / oldlen; 00198 SUMOReal y = p1.y() - (p2.y() - p1.y()) * (length) / oldlen; 00199 return Position2D(x, y); 00200 }
| Position2D GeomHelper::extrapolate_second | ( | const Position2D & | p1, | |
| const Position2D & | p2, | |||
| SUMOReal | length | |||
| ) | [static] |
Definition at line 204 of file GeomHelper.cpp.
References Position2D::distanceTo(), SUMOReal, Position2D::x(), and Position2D::y().
Referenced by Position2DVector::extrapolate(), Line2D::extrapolateSecondBy(), NIVissimAbstractEdge::getGeomPosition(), and Position2DVector::pruneFromEndAt().
00205 { 00206 SUMOReal oldlen = p1.distanceTo(p2); 00207 SUMOReal x = p2.x() - (p1.x() - p2.x()) * (length) / oldlen; 00208 SUMOReal y = p2.y() - (p1.y() - p2.y()) * (length) / oldlen; 00209 return Position2D(x, y); 00210 }
| SUMOReal GeomHelper::getCCWAngleDiff | ( | SUMOReal | angle1, | |
| SUMOReal | angle2 | |||
| ) | throw () [static] |
Returns the distance of second angle from first angle counter-clockwise.
| [in] | angle1 | The first angle |
| [in] | angle2 | The second angle |
Definition at line 362 of file GeomHelper.cpp.
Referenced by NBNode::computeLanes2Lanes(), getMaxAngleDiff(), getMinAngleDiff(), and NBNode::isLeftMover().
00362 { 00363 if (angle1<0) { 00364 angle1 = 360 + angle1; 00365 } 00366 if (angle2<0) { 00367 angle2 = 360 + angle2; 00368 } 00369 if (angle1>=angle2) { 00370 return angle1 - angle2; 00371 } 00372 return angle1 + 360 - angle2; 00373 }
| SUMOReal GeomHelper::getCWAngleDiff | ( | SUMOReal | angle1, | |
| SUMOReal | angle2 | |||
| ) | throw () [static] |
Returns the distance of second angle from first angle clockwise.
| [in] | angle1 | The first angle |
| [in] | angle2 | The second angle |
Definition at line 377 of file GeomHelper.cpp.
Referenced by NBNode::computeLanes2Lanes(), NBEdge::computeLaneShape(), getMaxAngleDiff(), getMinAngleDiff(), and NBNode::isLeftMover().
00377 { 00378 if (angle1<0) { 00379 angle1 = 360 + angle1; 00380 } 00381 if (angle2<0) { 00382 angle2 = 360 + angle2; 00383 } 00384 if (angle1<=angle2) { 00385 return angle2 - angle1; 00386 } 00387 return 360 - angle1 + angle2; 00388 }
| SUMOReal GeomHelper::getMaxAngleDiff | ( | SUMOReal | angle1, | |
| SUMOReal | angle2 | |||
| ) | throw () [static] |
Returns the maximum distance (clockwise/counter-clockwise) between both angles.
| [in] | angle1 | The first angle |
| [in] | angle2 | The second angle |
Definition at line 398 of file GeomHelper.cpp.
References getCCWAngleDiff(), getCWAngleDiff(), and MAX2().
00398 { 00399 return MAX2(getCWAngleDiff(angle1, angle2), getCCWAngleDiff(angle1, angle2)); 00400 }
| SUMOReal GeomHelper::getMinAngleDiff | ( | SUMOReal | angle1, | |
| SUMOReal | angle2 | |||
| ) | throw () [static] |
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
| [in] | angle1 | The first angle |
| [in] | angle2 | The second angle |
Definition at line 392 of file GeomHelper.cpp.
References getCCWAngleDiff(), getCWAngleDiff(), and MIN2().
Referenced by NBNodeShapeComputer::compute(), NBEdge::computeEdgeShape(), NBNode::computeInternalLaneShape(), NBOwnTLDef::getBestCombination(), NBContHelper::edge_opposite_direction_sorter::getDiff(), NBContHelper::edge_similar_direction_sorter::operator()(), and NBNode::setPriorityJunctionPriorities().
00392 { 00393 return MIN2(getCWAngleDiff(angle1, angle2), getCCWAngleDiff(angle1, angle2)); 00394 }
| std::pair< SUMOReal, SUMOReal > GeomHelper::getNormal90D_CW | ( | const Position2D & | beg, | |
| const Position2D & | end, | |||
| SUMOReal | wanted_offset | |||
| ) | [static] |
Definition at line 341 of file GeomHelper.cpp.
References getNormal90D_CW(), SUMOReal, Position2D::x(), and Position2D::y().
00343 { 00344 SUMOReal length = sqrt((beg.x()-end.x())*(beg.x()-end.x()) + (beg.y()-end.y())*(beg.y()-end.y())); 00345 return getNormal90D_CW(beg, end, length, wanted_offset); 00346 }
| std::pair< SUMOReal, SUMOReal > GeomHelper::getNormal90D_CW | ( | const Position2D & | beg, | |
| const Position2D & | end, | |||
| SUMOReal | length, | |||
| SUMOReal | wanted_offset | |||
| ) | [static] |
Definition at line 350 of file GeomHelper.cpp.
References toString(), Position2D::x(), and Position2D::y().
Referenced by getNormal90D_CW(), NBEdge::laneOffset(), Position2DVector::move2side(), and Line2D::move2side().
00352 { 00353 if (beg == end) { 00354 throw InvalidArgument("same points at " + toString(beg)); 00355 } 00356 return std::pair<SUMOReal, SUMOReal> 00357 ((beg.y()-end.y())*wanted_offset/length, (end.x()-beg.x())*wanted_offset/length); 00358 }
| Position2D GeomHelper::interpolate | ( | const Position2D & | p1, | |
| const Position2D & | p2, | |||
| SUMOReal | length | |||
| ) | [static] |
Definition at line 184 of file GeomHelper.cpp.
References Position2D::distanceTo(), SUMOReal, Position2D::x(), and Position2D::y().
00185 { 00186 SUMOReal oldlen = p1.distanceTo(p2); 00187 SUMOReal x = p1.x() + (p2.x() - p1.x()) * length / oldlen; 00188 SUMOReal y = p1.y() + (p2.y() - p1.y()) * length / oldlen; 00189 return Position2D(x, y); 00190 }
| Position2D GeomHelper::intersection_position | ( | const Position2D & | p11, | |
| const Position2D & | p12, | |||
| const Position2D & | p21, | |||
| const Position2D & | p22 | |||
| ) | [static] |
Definition at line 108 of file GeomHelper.cpp.
References SUMOReal, Position2D::x(), and Position2D::y().
Referenced by NIVissimAbstractEdge::crossesAtPoint(), Line2D::intersectsAt(), Line2D::intersectsAtLength(), Position2DVector::intersectsAtLengths(), Position2DVector::intersectsAtPoint(), and Position2DVector::intersectsAtPoints().
00111 { 00112 /*void Intersect_Lines(SUMOReal p11.x(),SUMOReal p11.y(),SUMOReal p12.x(),SUMOReal p12.y(), 00113 SUMOReal p21.x(),SUMOReal p21.y(),SUMOReal p22.x(),SUMOReal p22.y(), 00114 SUMOReal *xi,SUMOReal *yi) 00115 {*/ 00116 // this function computes the intersection of the sent lines 00117 // and returns the intersection point, note that the function assumes 00118 // the lines intersect. the function can handle vertical as well 00119 // as horizontal lines. note the function isn't very clever, it simply 00120 //applies the math, but we don't need speed since this is a 00121 //pre-processing step 00122 00123 double a1,b1,c1, // constants of linear equations 00124 a2,b2,c2, 00125 det_inv, m1, m2; // the inverse of the determinant of the coefficient 00126 00127 // compute slopes, note the cludge for infinity, however, this will 00128 // be close enough 00129 00130 if ((p12.x()-p11.x())!=0) 00131 m1 = (p12.y()-p11.y())/(p12.x()-p11.x()); 00132 else 00133 m1 = (SUMOReal)1e+10; // close enough to infinity 00134 00135 if ((p22.x()-p21.x())!=0) 00136 m2 = (p22.y()-p21.y())/(p22.x()-p21.x()); 00137 else 00138 m2 = (SUMOReal)1e+10; // close enough to infinity 00139 00140 // compute constants 00141 00142 a1 = m1; 00143 a2 = m2; 00144 00145 b1 = -1; 00146 b2 = -1; 00147 00148 c1 = (p11.y()-m1*p11.x()); 00149 c2 = (p21.y()-m2*p21.x()); 00150 00151 // compute the inverse of the determinate 00152 det_inv = 1/(a1*b2 - a2*b1); 00153 00154 // use Kramers rule to compute xi and yi 00155 return Position2D( 00156 ((b1*c2 - b2*c1)*det_inv), 00157 ((a2*c1 - a1*c2)*det_inv)); 00158 }
| bool GeomHelper::intersects | ( | const Position2D & | p11, | |
| const Position2D & | p12, | |||
| const Position2D & | p21, | |||
| const Position2D & | p22 | |||
| ) | [static] |
Definition at line 100 of file GeomHelper.cpp.
References intersects(), Position2D::x(), and Position2D::y().
00101 { 00102 return intersects(p11.x(), p11.y(), p12.x(), p12.y(), 00103 p21.x(), p21.y(), p22.x(), p22.y()); 00104 }
| bool GeomHelper::intersects | ( | SUMOReal | x1b, | |
| SUMOReal | y1b, | |||
| SUMOReal | x1e, | |||
| SUMOReal | y1e, | |||
| SUMOReal | x2b, | |||
| SUMOReal | y2b, | |||
| SUMOReal | x2e, | |||
| SUMOReal | y2e | |||
| ) | [static] |
Definition at line 46 of file GeomHelper.cpp.
References SUMOReal.
Referenced by NGRandomNetBuilder::canConnect(), Boundary::crosses(), Position2DVector::intersects(), Line2D::intersects(), intersects(), Position2DVector::intersectsAtLengths(), Position2DVector::intersectsAtPoint(), and Position2DVector::intersectsAtPoints().
00047 { 00048 /* Compute a1, b1, c1, where line joining points 1 and 2 00049 * is "a1 x + b1 y + c1 = 0". 00050 */ 00051 SUMOReal a1 = y2 - y1; 00052 SUMOReal b1 = x1 - x2; 00053 SUMOReal c1 = x2 * y1 - x1 * y2; 00054 00055 /* Compute r3 and r4. 00056 */ 00057 SUMOReal r3 = SUMOReal(a1 * x3 + b1 * y3 + c1); 00058 SUMOReal r4 = SUMOReal(a1 * x4 + b1 * y4 + c1); 00059 00060 /* Check signs of r3 and r4. If both point 3 and point 4 lie on 00061 * same side of line 1, the line segments do not intersect. 00062 */ 00063 if (r3 != 0 && 00064 r4 != 0 && 00065 ((r3<0&&r4<0)||(r3>0&&r4>0))) 00066 return (false); 00067 00068 /* Compute a2, b2, c2 */ 00069 SUMOReal a2 = y4 - y3; 00070 SUMOReal b2 = x3 - x4; 00071 SUMOReal c2 = x4 * y3 - x3 * y4; 00072 00073 /* Compute r1 and r2 */ 00074 SUMOReal r1 = a2 * x1 + b2 * y1 + c2; 00075 SUMOReal r2 = a2 * x2 + b2 * y2 + c2; 00076 00077 /* Check signs of r1 and r2. If both point 1 and point 2 lie 00078 * on same side of second line segment, the line segments do 00079 * not intersect. 00080 */ 00081 if (r1 != 0 && 00082 r2 != 0 && 00083 ((r1<0&&r2<0)||(r1>0&&r2>0))) 00084 return (false); 00085 00086 /* Line segments intersect: compute intersection point. 00087 */ 00088 SUMOReal denom = a1 * b2 - a2 * b1; 00089 if (denom == 0) 00090 return (false); 00091 // SUMOReal offset = denom < 0 ? - denom / 2 : denom / 2; 00092 00093 return true; 00094 }
| SUMOReal GeomHelper::nearest_position_on_line_to_point | ( | const Position2D & | l1, | |
| const Position2D & | l2, | |||
| const Position2D & | p | |||
| ) | [static] |
Definition at line 214 of file GeomHelper.cpp.
References Position2D::distanceSquaredTo(), Position2D::distanceTo(), SUMOReal, Position2D::x(), and Position2D::y().
Referenced by NIVissimAbstractEdge::crossesAtPoint(), Position2DVector::distance(), NIVissimConnectionCluster::getPositionForEdge(), Line2D::intersectsAtLength(), NIVissimConnectionCluster::liesOnSameEdgesEnd(), Position2DVector::nearest_position_on_line_to_point(), Position2DVector::pruneFromBeginAt(), Position2DVector::pruneFromEndAt(), and NBEdgeCont::splitAt().
00216 { 00217 SUMOReal u = (((Point.x() - LineStart.x()) * (LineEnd.x() - LineStart.x())) + 00218 ((Point.y() - LineStart.y()) * (LineEnd.y() - LineStart.y())) 00219 ) / LineStart.distanceSquaredTo(LineEnd); 00220 if (u < 0.0f || u > 1.0f) 00221 return -1; // closest point does not fall within the line segment 00222 return u * LineStart.distanceTo(LineEnd); 00223 }
| Position2D GeomHelper::transfer_to_side | ( | Position2D & | p, | |
| const Position2D & | lineBeg, | |||
| const Position2D & | lineEnd, | |||
| SUMOReal | amount | |||
| ) | [static] |
Definition at line 275 of file GeomHelper.cpp.
References Position2D::add(), SUMOReal, Position2D::x(), and Position2D::y().
Referenced by NBEdge::getMaxLaneOffsetPositionAt(), and NBEdge::getMinLaneOffsetPositionAt().
00278 { 00279 SUMOReal dx = lineBeg.x() - lineEnd.x(); 00280 SUMOReal dy = lineBeg.y() - lineEnd.y(); 00281 SUMOReal length = sqrt( 00282 (lineBeg.x() - lineEnd.x())*(lineBeg.x() - lineEnd.x()) 00283 + 00284 (lineBeg.y() - lineEnd.y())*(lineBeg.y() - lineEnd.y())); 00285 if (dx<0) { // fromX<toX -> to right 00286 if (dy>0) { // to up right -> lanes to down right (+, +) 00287 p.add(dy*amount/length, -dx*amount/length); 00288 } else if (dy<0) { // to down right -> lanes to down left (-, +) 00289 p.add(dy*amount/length, -dx*amount/length); 00290 } else { // to right -> lanes to down (0, +) 00291 p.add(0, -dx*amount/length); 00292 } 00293 } else if (dx>0) { // fromX>toX -> to left 00294 if (dy>0) { // to up left -> lanes to up right (+, -) 00295 p.add(dy*amount/length, -dx*amount/length); 00296 } else if (dy<0) { // to down left -> lanes to up left (-, -) 00297 p.add(dy*amount/length, -dx*amount/length); 00298 } else { // to left -> lanes to up (0, -) 00299 p.add(0, -dx*amount/length); 00300 } 00301 } else { // fromX==toX 00302 if (dy>0) { // to up -> lanes to right (+, 0) 00303 p.add(dy*amount/length, 0); 00304 } else if (dy<0) { // to down -> lanes to left (-, 0) 00305 p.add(dy*amount/length, 0); 00306 } else { // zero ! 00307 throw 1; 00308 } 00309 } 00310 return p; 00311 }
1.5.6