Eclipse SUMO - Simulation of Urban MObility
AGPosition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 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
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 // SPDX-License-Identifier: EPL-2.0
11 /****************************************************************************/
19 // References a street of the city and defines a position in this street
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include "AGPosition.h"
29 #include "AGStreet.h"
30 #include "router/ROEdge.h"
32 #include <iostream>
33 #include <limits>
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 AGPosition::AGPosition(const AGStreet& str, double pos) :
40  street(&str), position(pos), pos2d(compute2dPosition()) {
41 }
42 
43 
45  street(&str), position(randomPositionInStreet(str)), pos2d(compute2dPosition()) {
46 }
47 
48 
49 void
51  std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl;
52 }
53 
54 
55 bool
57  return pos2d.almostSame(pos.pos2d);
58 }
59 
60 
61 double
62 AGPosition::distanceTo(const AGPosition& otherPos) const {
63  return pos2d.distanceTo(otherPos.pos2d);
64 }
65 
66 
67 double
68 AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const {
69  double minDist = std::numeric_limits<double>::infinity();
70  double tempDist;
71  std::list<AGPosition>::const_iterator itt;
72 
73  for (itt = positions.begin(); itt != positions.end(); ++itt) {
74  tempDist = this->distanceTo(*itt);
75  if (tempDist < minDist) {
76  minDist = tempDist;
77  }
78  }
79  return minDist;
80 }
81 
82 
83 double
84 AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const {
85  double minDist = std::numeric_limits<double>::infinity();
86  double tempDist;
87  std::map<int, AGPosition>::const_iterator itt;
88 
89  for (itt = positions.begin(); itt != positions.end(); ++itt) {
90  tempDist = this->distanceTo(itt->second);
91  if (tempDist < minDist) {
92  minDist = tempDist;
93  }
94  }
95  return minDist;
96 }
97 
98 
99 const AGStreet&
101  return *street;
102 }
103 
104 
105 double
107  return position;
108 }
109 
110 
111 double
113  return RandHelper::rand(0.0, s.getLength());
114 }
115 
116 
117 Position
119  // P = From + pos*(To - From) = pos*To + (1-pos)*From
122  Position position2d(To);
123 
124  position2d.sub(From);
125  position2d.mul(position / street->getLength());
126  position2d.add(From);
127 
128  return position2d;
129 }
130 
131 /****************************************************************************/
AGPosition::randomPositionInStreet
static double randomPositionInStreet(const AGStreet &street)
Determines a random relative position on a street.
Definition: AGPosition.cpp:112
AGStreet.h
AGPosition::minDistanceTo
double minDistanceTo(const std::list< AGPosition > &positions) const
Computes the distance to the closest position in a list.
Definition: AGPosition.cpp:68
AGPosition::distanceTo
double distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
Definition: AGPosition.cpp:62
AGPosition::operator==
bool operator==(const AGPosition &pos) const
Tests whether two positions are at the same place.
Definition: AGPosition.cpp:56
AGPosition::getPosition
double getPosition() const
Provides the relative position of this AGPosition on the street.
Definition: AGPosition.cpp:106
Position::almostSame
bool almostSame(const Position &p2, double maxDiv=POSITION_EPS) const
check if two position is almost the sme as other
Definition: Position.h:228
RandHelper::rand
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:53
AGPosition::position
double position
Definition: AGPosition.h:135
Position::distanceTo
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:233
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
AGPosition::pos2d
Position pos2d
Definition: AGPosition.h:136
AGStreet
A model of the street in the city.
Definition: AGStreet.h:52
Position::sub
void sub(double dx, double dy)
Substracts the given position from this one.
Definition: Position.h:146
Position::mul
void mul(double val)
Multiplies both positions with the given value.
Definition: Position.h:106
ROEdge::getFromJunction
const RONode * getFromJunction() const
Definition: ROEdge.h:478
AGPosition.h
AGPosition::AGPosition
AGPosition(const AGStreet &str, double pos)
Constructs an AGPosition at a certain point on a street.
Definition: AGPosition.cpp:39
AGPosition::print
void print() const
Prints out a summary of the properties of this class on standard output.
Definition: AGPosition.cpp:50
AGPosition
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:55
ROEdge::getLength
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:204
config.h
AGPosition::getStreet
const AGStreet & getStreet() const
Provides the street this AGPosition is located on.
Definition: AGPosition.cpp:100
Position::add
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
RandHelper.h
AGPosition::compute2dPosition
Position compute2dPosition() const
Definition: AGPosition.cpp:118
AGPosition::street
const AGStreet * street
Definition: AGPosition.h:134
RONode::getPosition
const Position & getPosition() const
Returns the position of the node.
Definition: RONode.h:66
ROEdge.h
ROEdge::getToJunction
const RONode * getToJunction() const
Definition: ROEdge.h:482