Structural deformable models
Public Member Functions | Public Attributes | Friends | List of all members
Point2D Class Reference

#include <Point.h>

Inheritance diagram for Point2D:
Inheritance graph
[legend]

Public Member Functions

 Point2D ()
 
 Point2D (const Point2D &rhs)
 
 Point2D (float _x, float _y)
 
 Point2D (const float *val)
 
virtual ~Point2D ()
 
Point2Doperator= (const Point2D &rhs)
 
Point2Doperator= (float rhs)
 
Point2Doperator= (const float *rhs)
 
Point2Doperator+= (const Point2D &rhs)
 
Point2Doperator-= (const Point2D &rhs)
 
Point2Doperator*= (const Point2D &rhs)
 
Point2Doperator*= (const float f)
 
Point2Doperator/= (const Point2D &rhs)
 
Point2Doperator/= (const float f)
 
float operator* (const Point2D &rhs) const
 
const Point2Dconst_times (const Point2D &rhs) const
 
Point2Dtimes (const Point2D &rhs)
 
float dot (const Point2D &rhs) const
 
float crossZ (const Point2D &rhs) const
 
float sinAngle (const Point2D &rhs) const
 
float angle (const Point2D &rhs=Point2D(1, 0)) const
 
float sinAngleX () const
 
float angleX () const
 
Point2D operator* (float rhs) const
 
Point2D operator+ (const Point2D &rhs) const
 
Point2D operator- (const Point2D &rhs) const
 
Point2D operator/ (const Point2D &rhs) const
 
Point2D operator/ (float rhs) const
 
float sum () const
 returns 1-norm More...
 
float norm2 () const
 returns squared 2-norm More...
 
float norm () const
 returns 2-norm aka length or absolute More...
 
float normalize ()
 normalizes the vector; returns old norm More...
 
bool clamp (float x0, float y0, float x1, float y1)
 
void glVertex () const
 Issue a glVertex2f call. More...
 
const Point2D flipOrtho () const
 
const Point2D copyNormalized () const
 
const Point2D rotate (float angle) const
 

Public Attributes

float x
 
float y
 

Friends

std::ostream & operator<< (std::ostream &os, const Point2D &p)
 
std::istream & operator>> (std::istream &is, Point2D &p)
 
bool operator== (const Point2D &lhs, const Point2D &rhs)
 
bool operator!= (const Point2D &lhs, const Point2D &rhs)
 

Detailed Description

Definition at line 16 of file Point.h.

Constructor & Destructor Documentation

Point2D::Point2D ( )
inline

Definition at line 18 of file Point.h.

Referenced by angleX(), flipOrtho(), and rotate().

18 : x(0), y(0) {};
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D::Point2D ( const Point2D rhs)
inline

Definition at line 19 of file Point.h.

References operator=().

19  {
20  operator=(rhs); }
Point2D & operator=(const Point2D &rhs)
Definition: Point.h:27
Point2D::Point2D ( float  _x,
float  _y 
)
inline

Definition at line 21 of file Point.h.

21 : x(_x), y(_y) {}
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D::Point2D ( const float *  val)
inline

Definition at line 22 of file Point.h.

References operator=().

22  {
23  operator=(val); }
Point2D & operator=(const Point2D &rhs)
Definition: Point.h:27
virtual Point2D::~Point2D ( )
inlinevirtual

Definition at line 25 of file Point.h.

25 {};

Member Function Documentation

float Point2D::angle ( const Point2D rhs = Point2D(1,0)) const
inline

Definition at line 93 of file Point.h.

References crossZ(), dot(), M_1_PI, and M_PI.

Referenced by StructTable::adjustByAvgDir(), angleX(), Model::getNodeAngle(), and setPropSDir().

93  {
94  float dv = crossZ(rhs);
95  float dh = dot(rhs);
96  return atan2(dv,dh);
97 #ifdef _THERE_IS_NO_ATAN2_
98  float dvp,dvn;
99  if(dv > 0.0) {
100  dvp = 1.0;
101  dvn = 0.0;
102  } else {
103  dvp = 0.0;
104  dvn = 1.0;
105  }
106  float dhn = (dh < 0) ? 1.0 : 0.0;
107  float psi;
108  if (dh == 0.0)
109  psi = M_PI_2 * (dvp + 3.0 * dvn);
110  else if (dv == 0.0)
111  psi = M_PI * dhn;
112  else
113  psi = atan(dv/dh) + M_PI * dhn * dvp
114  + (M_PI + M_PI * (dh > 0.0)) * dvn;
115  return psi * (180.0*M_1_PI);
116 #endif
117  }
#define M_1_PI
Definition: mathutil.h:12
#define M_PI
Definition: mathutil.h:9
float crossZ(const Point2D &rhs) const
Definition: Point.h:85
float dot(const Point2D &rhs) const
Definition: Point.h:82
float Point2D::angleX ( ) const
inline

Definition at line 123 of file Point.h.

References angle(), and Point2D().

Referenced by Edge::getAngle().

123  {
124  //return asin(sinAngleX());
125  return angle(Point2D(1,0));
126  }
float angle(const Point2D &rhs=Point2D(1, 0)) const
Definition: Point.h:93
Point2D()
Definition: Point.h:18
bool Point2D::clamp ( float  x0,
float  y0,
float  x1,
float  y1 
)
inline

Definition at line 181 of file Point.h.

References clamp(), x, and y.

182  {
183  return ::clamp(x,y,x0,y0,x1,y1);
184  }
bool clamp(T &x, T &y, const T x0, const T y0, const T x1, const T y1)
Definition: mathutil.h:24
float y
Definition: Point.h:224
float x
Definition: Point.h:224
const Point2D& Point2D::const_times ( const Point2D rhs) const
inline

Definition at line 73 of file Point.h.

References times().

73  {
74  Point2D p(*this);
75  return p.times(rhs);
76  }
Definition: Point.h:16
const Point2D Point2D::copyNormalized ( ) const
inline

Definition at line 206 of file Point.h.

References normalize().

206  {
207  Point2D p(*this);
208  p.normalize();
209  return p;
210  }
Definition: Point.h:16
float Point2D::crossZ ( const Point2D rhs) const
inline

Definition at line 85 of file Point.h.

References x, and y.

Referenced by angle().

85  {
86  return y*rhs.x-x*rhs.y;
87  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
float Point2D::dot ( const Point2D rhs) const
inline

Definition at line 82 of file Point.h.

References x, and y.

Referenced by angle(), and Model::calculateForces().

82  {
83  return x*rhs.x+y*rhs.y;
84  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
const Point2D Point2D::flipOrtho ( ) const
inline

Definition at line 202 of file Point.h.

References Point2D(), x, and y.

Referenced by Model::addTorque().

202  {
203  return Point2D(-y,x);
204  }
float y
Definition: Point.h:224
Point2D()
Definition: Point.h:18
float x
Definition: Point.h:224
void Point2D::glVertex ( ) const
inline

Issue a glVertex2f call.

Definition at line 198 of file Point.h.

References x, and y.

198  {
199  glVertex2f(x, y);
200  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
float Point2D::norm ( ) const
inline

returns 2-norm aka length or absolute

Definition at line 170 of file Point.h.

References dmutil::sqrt(), x, and y.

Referenced by Model::calculateForces(), normalize(), setPropSDir(), and sinAngleX().

170  {
171  return (float)sqrt(x*x+y*y);
172  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Point2D::norm2 ( ) const
inline

returns squared 2-norm

Definition at line 165 of file Point.h.

References x, and y.

Referenced by Edge::length2(), and sinAngle().

165  {
166  return x*x+y*y;
167  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
float Point2D::normalize ( )
inline

normalizes the vector; returns old norm

Definition at line 175 of file Point.h.

References norm(), and operator*=().

Referenced by Model::addTorque(), CornerSensor::calcValue(), and copyNormalized().

175  {
176  float n = norm();
177  if (n>0.0f) operator*=(1/n);
178  return n;
179  }
float norm() const
returns 2-norm aka length or absolute
Definition: Point.h:170
Point2D & operator*=(const Point2D &rhs)
Definition: Point.h:50
float Point2D::operator* ( const Point2D rhs) const
inline

Definition at line 69 of file Point.h.

References x, and y.

69  {
70  return x*rhs.x + y*rhs.y;
71  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D Point2D::operator* ( float  rhs) const
inline

Definition at line 129 of file Point.h.

129  {
130  Point2D p(*this);
131  p *= rhs;
132  return p;
133  }
Definition: Point.h:16
Point2D& Point2D::operator*= ( const Point2D rhs)
inline

Definition at line 50 of file Point.h.

References x, and y.

Referenced by normalize().

50  {
51  x*=rhs.x; y*=rhs.y;
52  return *this;
53  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D& Point2D::operator*= ( const float  f)
inline

Definition at line 55 of file Point.h.

References x, and y.

55  {
56  x*=f; y*=f;
57  return *this;
58  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D Point2D::operator+ ( const Point2D rhs) const
inline

Definition at line 135 of file Point.h.

135  {
136  Point2D p(*this);
137  p += rhs;
138  return p;
139  }
Definition: Point.h:16
Point2D& Point2D::operator+= ( const Point2D rhs)
inline

Definition at line 41 of file Point.h.

References x, and y.

41  {
42  x+=rhs.x; y+=rhs.y;
43  return *this;
44  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D Point2D::operator- ( const Point2D rhs) const
inline

Definition at line 141 of file Point.h.

141  {
142  Point2D p(*this);
143  p -= rhs;
144  return p;
145  }
Definition: Point.h:16
Point2D& Point2D::operator-= ( const Point2D rhs)
inline

Definition at line 45 of file Point.h.

References x, and y.

45  {
46  x-=rhs.x; y-=rhs.y;
47  return *this;
48  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D Point2D::operator/ ( const Point2D rhs) const
inline

Definition at line 147 of file Point.h.

147  {
148  Point2D p(*this);
149  p /= rhs;
150  return p;
151  }
Definition: Point.h:16
Point2D Point2D::operator/ ( float  rhs) const
inline

Definition at line 153 of file Point.h.

153  {
154  Point2D p(*this);
155  p *= 1/rhs;
156  return p;
157  }
Definition: Point.h:16
Point2D& Point2D::operator/= ( const Point2D rhs)
inline

Definition at line 60 of file Point.h.

References x, and y.

60  {
61  x/=rhs.x; y/=rhs.y;
62  return *this;
63  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D& Point2D::operator/= ( const float  f)
inline

Definition at line 64 of file Point.h.

References x, and y.

64  {
65  x/=f; y/=f;
66  return *this;
67  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D& Point2D::operator= ( const Point2D rhs)
inline

Definition at line 27 of file Point.h.

References x, and y.

Referenced by IPoint2D::IPoint2D(), Node::operator=(), IPoint2D::operator=(), Point2D(), and Node::setPos().

27  {
28  x=rhs.x; y=rhs.y;
29  return *this;
30  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D& Point2D::operator= ( float  rhs)
inline

Definition at line 32 of file Point.h.

References x, and y.

32  {
33  x = y = rhs;
34  return *this;
35  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D& Point2D::operator= ( const float *  rhs)
inline

Definition at line 37 of file Point.h.

References x, and y.

37  {
38  this->x = rhs[0]; this->y = rhs[1];
39  return *this;
40  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
const Point2D Point2D::rotate ( float  angle) const
inline

Definition at line 211 of file Point.h.

References Point2D(), x, and y.

Referenced by StructTable::adjustByAvgDir(), getPropSDir(), and Model::rotate().

211  {
212  float ca = cos(angle);
213  float sa = sin(angle);
214  return Point2D(x*ca-y*sa,x*sa+y*ca);
215  }
float y
Definition: Point.h:224
float angle(const Point2D &rhs=Point2D(1, 0)) const
Definition: Point.h:93
Point2D()
Definition: Point.h:18
float x
Definition: Point.h:224
float Point2D::sinAngle ( const Point2D rhs) const
inline

Definition at line 88 of file Point.h.

References norm2(), dmutil::sqrt(), x, and y.

88  {
89  // z-component of the cross product
90  return (x*rhs.y-y*rhs.x)/sqrt(norm2()*rhs.norm2());
91  }
float y
Definition: Point.h:224
float norm2() const
returns squared 2-norm
Definition: Point.h:165
float x
Definition: Point.h:224
DMatrix< T > & sqrt(DMatrix< T > &mat)
Definition: DMatrixUtil.h:81
float Point2D::sinAngleX ( ) const
inline

Definition at line 119 of file Point.h.

References norm(), and y.

119  {
120  return -y/norm();
121  }
float y
Definition: Point.h:224
float norm() const
returns 2-norm aka length or absolute
Definition: Point.h:170
float Point2D::sum ( ) const
inline

returns 1-norm

Definition at line 160 of file Point.h.

References x, and y.

Referenced by Searcher::buildBins().

160  {
161  return x+y;
162  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
Point2D& Point2D::times ( const Point2D rhs)
inline

Definition at line 78 of file Point.h.

Referenced by const_times().

78  {
79  return *this *= rhs;
80  }

Friends And Related Function Documentation

bool operator!= ( const Point2D lhs,
const Point2D rhs 
)
friend

Definition at line 219 of file Point.h.

219  {
220  return !operator==(lhs, rhs);
221  }
friend bool operator==(const Point2D &lhs, const Point2D &rhs)
Definition: Point.h:216
std::ostream& operator<< ( std::ostream &  os,
const Point2D p 
)
friend

Definition at line 186 of file Point.h.

186  {
187  os << p.x << " " << p.y;
188  return os;
189  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
bool operator== ( const Point2D lhs,
const Point2D rhs 
)
friend

Definition at line 216 of file Point.h.

216  {
217  return lhs.x == rhs.x && lhs.y == rhs.y;
218  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224
std::istream& operator>> ( std::istream &  is,
Point2D p 
)
friend

Definition at line 191 of file Point.h.

191  {
192  is >> p.x;
193  is >> p.y;
194  return is;
195  }
float y
Definition: Point.h:224
float x
Definition: Point.h:224

Member Data Documentation

float Point2D::x
float Point2D::y

The documentation for this class was generated from the following file: