 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
48 std::vector<double>& into) {
49 const double dx = p2.
x() - p1.
x();
50 const double dy = p2.
y() - p1.
y();
52 const double A = dx * dx + dy * dy;
53 const double B = 2 * (dx * (p1.
x() - c.
x()) + dy * (p1.
y() - c.
y()));
54 const double C = (p1.
x() - c.
x()) * (p1.
x() - c.
x()) + (p1.
y() - c.
y()) * (p1.
y() - c.
y()) - radius * radius;
56 const double det = B * B - 4 * A * C;
57 if ((A <= 0.0000001) || (det < 0)) {
63 const double t = -B / (2 * A);
64 if (t >= 0. && t <= 1.) {
69 const double t = (double)((-B + sqrt(det)) / (2 * A));
70 Position intersection(p1.
x() + t * dx, p1.
y() + t * dy);
71 if (t >= 0. && t <= 1.) {
74 const double t2 = (double)((-B - sqrt(det)) / (2 * A));
75 if (t2 >= 0. && t2 <= 1.) {
84 return angleDiff(atan2(p1.
y(), p1.
x()), atan2(p2.
y(), p2.
x()));
91 const Position& p,
bool perpendicular) {
92 const double lineLength2D = lineStart.
distanceTo2D(lineEnd);
93 if (lineLength2D == 0.0f) {
98 const double u = (((p.
x() - lineStart.
x()) * (lineEnd.
x() - lineStart.
x())) +
99 ((p.
y() - lineStart.
y()) * (lineEnd.
y() - lineStart.
y()))
100 ) / (lineLength2D * lineLength2D);
101 if (u < 0.0f || u > 1.0f) {
110 return u * lineLength2D;
118 const Position& p,
bool perpendicular) {
121 const double lineLength2D = lineStart.
distanceTo2D(lineEnd);
122 const double lineLength = lineStart.
distanceTo(lineEnd);
123 result *= (lineLength / lineLength2D);
155 double v = angle2 - angle1;
165 double v = angle1 - angle2;
181 double dtheta = angle2 - angle1;
182 while (dtheta > (
double)
M_PI) {
183 dtheta -= (double)(2.0 *
M_PI);
185 while (dtheta < (
double) -
M_PI) {
186 dtheta += (double)(2.0 *
M_PI);
195 if (std::isinf(degree)) {
199 while (degree >= 360.) {
202 while (degree < 0.) {
219 while (degree >= 360.) {
222 while (degree < 0.) {
226 while (degree >= 180.) {
229 while (degree < -180.) {
239 WRITE_ERROR(
"GeomHelper::makeCircle() requires nPoints>=3");
242 circle.push_back({radius, 0});
243 for (
unsigned int i = 1; i < nPoints; ++i) {
244 const double a = 2.0 *
M_PI * (double)i / (
double) nPoints;
245 circle.push_back({radius * cos(a), radius * sin(a)});
247 circle.push_back({radius, 0});
256 WRITE_ERROR(
"GeomHelper::makeRing() requires nPoints>=3");
258 if (radius1 >= radius2) {
259 WRITE_ERROR(
"GeomHelper::makeRing() requires radius2>radius1");
262 ring.push_back({radius1, 0});
263 ring.push_back({radius2, 0});
264 for (
unsigned int i = 1; i < nPoints; ++i) {
265 const double a = 2.0 *
M_PI * (double)i / (
double) nPoints;
266 ring.push_back({radius2 * cos(a), radius2 * sin(a)});
268 ring.push_back({radius2, 0});
269 ring.push_back({radius1, 0});
270 for (
unsigned int i = 1; i < nPoints; ++i) {
271 const double a = -2.0 *
M_PI * (double)i / (
double) nPoints;
272 ring.push_back({radius1 * cos(a), radius1 * sin(a)});
274 ring.push_back({radius1, 0});
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
double ymin() const
Returns minimum y-coordinate.
static double getMinAngleDiff(double angle1, double angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
static double nearest_offset_on_line_to_point25D(const Position &lineStart, const Position &lineEnd, const Position &p, bool perpendicular=true)
static double legacyDegree(const double angle, const bool positive=false)
static double naviDegree(const double angle)
double xmax() const
Returns maximum x-coordinate.
static double nearest_offset_on_line_to_point2D(const Position &lineStart, const Position &lineEnd, const Position &p, bool perpendicular=true)
static PositionVector makeRing(const double radius1, const double radius2, const Position ¢er, unsigned int nPoints)
void add(double xoff, double yoff, double zoff)
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.
double xmin() const
Returns minimum x-coordinate.
static const double INVALID_OFFSET
a value to signify offsets outside the range of [0, Line.length()]
static Position crossPoint(const Boundary &b, const PositionVector &v)
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
static void findLineCircleIntersections(const Position &c, double radius, const Position &p1, const Position &p2, std::vector< double > &into)
Returns the positions the given circle is crossed by the given line.
A class that stores a 2D geometrical boundary.
A point in 2D or 3D with translation and scaling methods.
double x() const
Returns the x-position.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
static double getCWAngleDiff(double angle1, double angle2)
Returns the distance of second angle from first angle clockwise.
static double angle2D(const Position &p1, const Position &p2)
Returns the angle between two vectors on a plane The angle is from vector 1 to vector 2,...
double y() const
Returns the y-position.
Position intersectionPosition2D(const Position &p1, const Position &p2, const double withinDist=0.) const
Returns the position of the intersection.
static double fromNaviDegree(const double angle)
static PositionVector makeCircle(const double radius, const Position ¢er, unsigned int nPoints)
static double getCCWAngleDiff(double angle1, double angle2)
Returns the distance of second angle from first angle counter-clockwise.
double ymax() const
Returns maximum y-coordinate.