Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
AGPosition.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// activitygen module
5// Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6// This program and the accompanying materials are made available under the
7// terms of the Eclipse Public License 2.0 which is available at
8// https://www.eclipse.org/legal/epl-2.0/
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License 2.0 are satisfied: GNU General Public License, version 2
12// or later which is available at
13// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15/****************************************************************************/
23// References a street of the city and defines a position in this street
24/****************************************************************************/
25#include <config.h>
26
27#include "AGPosition.h"
28#include "AGStreet.h"
29#include "router/ROEdge.h"
31#include <iostream>
32#include <limits>
33
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38AGPosition::AGPosition(const AGStreet& str, double pos) :
39 street(&str), position(pos), pos2d(compute2dPosition()) {
40}
41
42
44 street(&str), position(randomPositionInStreet(str)), pos2d(compute2dPosition()) {
45}
46
47
48void
50 std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl;
51}
52
53
54bool
56 return pos2d.almostSame(pos.pos2d);
57}
58
59
60double
61AGPosition::distanceTo(const AGPosition& otherPos) const {
62 return pos2d.distanceTo(otherPos.pos2d);
63}
64
65
66double
67AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const {
68 double minDist = std::numeric_limits<double>::infinity();
69 double tempDist;
70 std::list<AGPosition>::const_iterator itt;
71
72 for (itt = positions.begin(); itt != positions.end(); ++itt) {
73 tempDist = this->distanceTo(*itt);
74 if (tempDist < minDist) {
75 minDist = tempDist;
76 }
77 }
78 return minDist;
79}
80
81
82double
83AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const {
84 double minDist = std::numeric_limits<double>::infinity();
85 double tempDist;
86 std::map<int, AGPosition>::const_iterator itt;
87
88 for (itt = positions.begin(); itt != positions.end(); ++itt) {
89 tempDist = this->distanceTo(itt->second);
90 if (tempDist < minDist) {
91 minDist = tempDist;
92 }
93 }
94 return minDist;
95}
96
97
98const AGStreet&
100 return *street;
101}
102
103
104double
106 return position;
107}
108
109
110double
114
115
118 // P = From + pos*(To - From) = pos*To + (1-pos)*From
121 Position position2d(To);
122
123 position2d.sub(From);
124 position2d.mul(position / street->getLength());
125 position2d.add(From);
126
127 return position2d;
128}
129
130
131/****************************************************************************/
A location in the 2D plane freely positioned on a street.
Definition AGPosition.h:53
double getPosition() const
Provides the relative position of this AGPosition on the street.
double distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
const AGStreet & getStreet() const
Provides the street this AGPosition is located on.
void print() const
Prints out a summary of the properties of this class on standard output.
Position pos2d
Definition AGPosition.h:134
bool operator==(const AGPosition &pos) const
Tests whether two positions are at the same place.
double position
Definition AGPosition.h:133
double minDistanceTo(const std::list< AGPosition > &positions) const
Computes the distance to the closest position in a list.
static double randomPositionInStreet(const AGStreet &street)
Determines a random relative position on a street.
const AGStreet * street
Definition AGPosition.h:132
AGPosition(const AGStreet &str, double pos)
Constructs an AGPosition at a certain point on a street.
Position compute2dPosition() const
A model of the street in the city.
Definition AGStreet.h:50
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
Definition Position.h:266
void sub(double dx, double dy)
Subtracts the given position from this one.
Definition Position.h:152
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:132
void mul(double val)
Multiplies position with the given value.
Definition Position.h:105
bool almostSame(const Position &p2, double maxDiv=POSITION_EPS) const
check whether the other position has a euclidean distance of less than maxDiv
Definition Position.h:261
const RONode * getToJunction() const
Definition ROEdge.h:516
const RONode * getFromJunction() const
Definition ROEdge.h:512
double getLength() const
Returns the length of the edge.
Definition ROEdge.h:219
const Position & getPosition() const
Returns the position of the node.
Definition RONode.h:64
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)