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