O --- O
libPEDSIM Documentation
[HOME] [EXAMPLES] [ECOSYSTEM] [DOCUMENTATION] [DOWNLOAD]
O --- O
ped_obstacle.cpp
1 //
2 // pedsim - A microscopic pedestrian simulation system.
3 // Copyright (c) by Christian Gloor
4 //
5 
6 #include "ped_obstacle.h"
7 
8 #include <cmath>
9 #include <vector>
10 
11 using namespace std;
12 
15 Ped::Tobstacle::Tobstacle() : ax(0), ay(0), bx(1), by(1), type(0) {
16  static int staticid = 0;
17  id = staticid++;
18 }
19 
20 
27 Ped::Tobstacle::Tobstacle(double pax, double pay, double pbx, double pby) : Tobstacle() {
28  ax = pax;
29  ay = pay;
30  bx = pbx;
31  by = pby;
32 }
33 
34 
39 Ped::Tobstacle::Tobstacle(const Tvector& startIn, const Tvector& endIn) : Tobstacle() {
40  ax = startIn.x;
41  ay = startIn.y;
42  bx = endIn.x;
43  by = endIn.y;
44 }
45 
46 
49  // clean up
50 }
51 
52 
53 Ped::Tvector Ped::Tobstacle::getStartPoint() const {
54  return Tvector(ax, ay);
55 }
56 
57 
58 Ped::Tvector Ped::Tobstacle::getEndPoint() const {
59  return Tvector(bx, by);
60 }
61 
62 
69 void Ped::Tobstacle::setPosition(double pax, double pay, double pbx, double pby) {
70  ax = pax;
71  ay = pay;
72  bx = pbx;
73  by = pby;
74 }
75 
76 void Ped::Tobstacle::setPosition(const Tvector& startIn, const Tvector& endIn) {
77  setPosition(startIn.x, startIn.y, endIn.x, endIn.y);
78 }
79 
80 void Ped::Tobstacle::setStartPoint(const Tvector& startIn) {
81  ax = startIn.x;
82  ay = startIn.y;
83 }
84 
85 void Ped::Tobstacle::setEndPoint(const Tvector& endIn) {
86  bx = endIn.x;
87  by = endIn.y;
88 }
89 
90 Ped::Tvector Ped::Tobstacle::closestPoint(const Tvector& pointIn) const {
91  Tvector startPoint(ax, ay);
92  Tvector endPoint(bx, by);
93  Tvector relativeEndPoint = endPoint - startPoint;
94 
95  Tvector relativePoint = pointIn - startPoint;
96  double lambda = (Tvector::dotProduct(relativePoint, relativeEndPoint))
97  / relativeEndPoint.lengthSquared();
98 
99  if(lambda <= 0)
100  return startPoint;
101  else if(lambda >= 1)
102  return endPoint;
103  else
104  return startPoint + lambda*relativeEndPoint;
105 }
106 
115 Ped::Tvector Ped::Tobstacle::closestPoint(double p1, double p2) const {
116  return closestPoint(Tvector(p1, p2));
117 }
118 
127 void Ped::Tobstacle::rotate(double x, double y, double phi) {
128  double sinPhi = sin(phi);
129  double cosPhi = cos(phi);
130 
131  double anx = ax*cosPhi - x*cosPhi - ay*sinPhi + y*sinPhi + x;
132  double any = ax*sinPhi - x*sinPhi + ay*cosPhi - y*cosPhi + y;
133 
134  double bnx = bx*cosPhi - x*cosPhi - by*sinPhi + y*sinPhi + x;
135  double bny = bx*sinPhi - x*sinPhi + by*cosPhi - y*cosPhi + y;
136 
137  setPosition(anx, any, bnx, bny);
138 }
virtual void setPosition(double ax, double ay, double bx, double by)
virtual ~Tobstacle()
Destructor.
virtual void rotate(double x, double y, double phi)
double bx
Position of the obstacle.
Definition: ped_obstacle.h:64
double ay
Position of the obstacle.
Definition: ped_obstacle.h:63
virtual Tvector closestPoint(double p1, double p2) const
double by
Position of the obstacle.
Definition: ped_obstacle.h:65
double ax
Position of the obstacle.
Definition: ped_obstacle.h:62
static double dotProduct(const Tvector &a, const Tvector &b)
Definition: ped_vector.cpp:82
O --- O

⁠(c) Christian Gloor [ c|h|g|l|o|o|r|@|s|i|l|m|a|r|i|l|.|o|r|g| ]