SUMO - Simulation of Urban MObility
AGPosition.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // References a street of the city and defines a position in this street
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 // activitygen module
15 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include "AGPosition.h"
37 #include "AGStreet.h"
38 #include "router/ROEdge.h"
40 #include <iostream>
41 #include <limits>
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  street(&str), position(pos), pos2d(compute2dPosition()) {
49 }
50 
51 
54 }
55 
56 
57 void
59  std::cout << "- AGPosition: *Street=" << street << " position=" << position << "/" << street->getLength() << std::endl;
60 }
61 
62 
63 bool
65  return pos2d.almostSame(pos.pos2d);
66 }
67 
68 
70 AGPosition::distanceTo(const AGPosition& otherPos) const {
71  return pos2d.distanceTo(otherPos.pos2d);
72 }
73 
74 
76 AGPosition::minDistanceTo(const std::list<AGPosition>& positions) const {
77  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
78  SUMOReal tempDist;
79  std::list<AGPosition>::const_iterator itt;
80 
81  for (itt = positions.begin(); itt != positions.end(); ++itt) {
82  tempDist = this->distanceTo(*itt);
83  if (tempDist < minDist) {
84  minDist = tempDist;
85  }
86  }
87  return minDist;
88 }
89 
90 
92 AGPosition::minDistanceTo(const std::map<int, AGPosition>& positions) const {
93  SUMOReal minDist = std::numeric_limits<SUMOReal>::infinity();
94  SUMOReal tempDist;
95  std::map<int, AGPosition>::const_iterator itt;
96 
97  for (itt = positions.begin(); itt != positions.end(); ++itt) {
98  tempDist = this->distanceTo(itt->second);
99  if (tempDist < minDist) {
100  minDist = tempDist;
101  }
102  }
103  return minDist;
104 }
105 
106 
107 const AGStreet&
109  return *street;
110 }
111 
112 
113 SUMOReal
115  return position;
116 }
117 
118 
119 SUMOReal
121  return RandHelper::rand(0.0, s.getLength());
122 }
123 
124 
125 Position
127  // P = From + pos*(To - From) = pos*To + (1-pos)*From
130  Position position2d(To);
131 
132  position2d.sub(From);
133  position2d.mul(position / street->getLength());
134  position2d.add(From);
135 
136  return position2d;
137 }
138 
139 /****************************************************************************/
SUMOReal getLength() const
Returns the length of the edge.
Definition: ROEdge.h:198
void sub(SUMOReal dx, SUMOReal dy)
Substracts the given position from this one.
Definition: Position.h:139
const Position & getPosition() const
Returns the position of the node.
Definition: RONode.h:74
SUMOReal distanceTo(const AGPosition &otherPos) const
Computes the distance between two AGPosition objects.
Definition: AGPosition.cpp:70
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:119
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:221
Position compute2dPosition() const
Definition: AGPosition.cpp:126
const RONode * getFromJunction() const
Definition: ROEdge.h:436
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:63
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
A model of the street in the city.
Definition: AGStreet.h:60
SUMOReal getPosition() const
Provides the relative position of this AGPosition on the street.
Definition: AGPosition.cpp:114
SUMOReal position
Definition: AGPosition.h:143
const RONode * getToJunction() const
Definition: ROEdge.h:440
bool operator==(const AGPosition &pos) const
Tests whether two positions are at the same place.
Definition: AGPosition.cpp:64
const AGStreet & getStreet() const
Provides the street this AGPosition is located on.
Definition: AGPosition.cpp:108
AGPosition(const AGStreet &str, SUMOReal pos)
Constructs an AGPosition at a certain point on a street.
Definition: AGPosition.cpp:47
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
Position pos2d
Definition: AGPosition.h:144
static SUMOReal randomPositionInStreet(const AGStreet &street)
Determines a random relative position on a street.
Definition: AGPosition.cpp:120
bool almostSame(const Position &p2, SUMOReal maxDiv=POSITION_EPS) const
Definition: Position.h:215
void mul(SUMOReal val)
Multiplies both positions with the given value.
Definition: Position.h:99
SUMOReal minDistanceTo(const std::list< AGPosition > &positions) const
Computes the distance to the closest position in a list.
Definition: AGPosition.cpp:76
#define SUMOReal
Definition: config.h:213
void print() const
Prints out a summary of the properties of this class on standard output.
Definition: AGPosition.cpp:58
const AGStreet * street
Definition: AGPosition.h:142