Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_point2.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2000-19 Pierre SMARS (smars@yuntech.edu.tw)
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 2 of the License, or
6 (at your option) any later version.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 #include "a_point2.h"
17 #include "a_point.h"
18 #include <math.h>
19 #include <sstream>
20 
21 //---------------------------------------------------------------------------
22 const std::string a_point2::help()
23 {
24  std::ostringstream o;
25  return o.str();
26 }
27 //---------------------------------------------------------------------------
29 {
30  x_ = -x_;
31  y_ = -y_;
32  return *this;
33 }
34 //---------------------------------------------------------------------------
36 {
37  x_ += p.x();
38  y_ += p.y();
39  return *this;
40 }
41 //---------------------------------------------------------------------------
43 {
44  x_ -= p.x();
45  y_ -= p.y();
46  return *this;
47 }
48 //---------------------------------------------------------------------------
50 {
51  return x_*p.x()+y_*p.y();
52 }
53 //---------------------------------------------------------------------------
55 {
56  return ((x_ == p.x())&&(y_ == p.y()));
57 }
58 //---------------------------------------------------------------------------
60 {
61  x_ = p.x();
62  y_ = p.y();
63  return *this;
64 }
65 //-operator*=----------------------------------------------------------------
67 {
68  x_ *= v;
69  y_ *= v;
70  return *this;
71 }
72 //-operator/=----------------------------------------------------------------
74 {
75  x_ /= v;
76  y_ /= v;
77  return *this;
78 }
79 //-sumsq---------------------------------------------------------------------
80 double a_point2::sumsq() const
81 {
82  return x_*x_+y_*y_;
83 }
84 //-norm----------------------------------------------------------------------
85 double a_point2::norm() const
86 {
87  return sqrt(sumsq());
88 }
89 //-normalise-----------------------------------------------------------------
91 {
92  double n = norm();
93  if (n != 0) operator/=(n);
94  return *this;
95 }
96 //-rotate--------------------------------------------------------------------
98 {
99  double xn = x_*cos(angle)+y_*sin(angle);
100  double yn = -x_*sin(angle)+y_*cos(angle);
101  x_ = xn; y_ = yn;
102  return *this;
103 }
104 //***************************************************************************
105 //-operator+-----------------------------------------------------------------
106 a_point2 operator+(const a_point2& a, const a_point2& b)
107 {
108  a_point2 r = a;
109  return r += b;
110 }
111 //-operator------------------------------------------------------------------
112 a_point2 operator-(const a_point2& a, const a_point2& b)
113 {
114  a_point2 r = a;
115  return r -= b;
116 }
117 //-operator*-----------------------------------------------------------------
118 double operator*(const a_point2& a, const a_point2& b)
119 {
120  a_point2 r = a;
121  return r *= b;
122 }
123 //-operator*-----------------------------------------------------------------
124 a_point2 operator*(const double v, const a_point2& a)
125 {
126  a_point2 r = a;
127  return r *= v;
128 }
129 //-operator*-----------------------------------------------------------------
130 a_point2 operator*(const a_point2& a, double v)
131 {
132  a_point2 r = a;
133  return r *= v;
134 }
135 //-operator/-----------------------------------------------------------------
136 a_point2 operator/(const a_point2& a, double v)
137 {
138  a_point2 r = a;
139  return r /= v;
140 }
141 //---------------------------------------------------------------------------
142 a_point2 circle_centre(const a_point2& p1, const a_point2& p2, const a_point2& p3)
143 {
144 exit(-1);
145 }
146 //***************************************************************************
147 //---------------------------------------------------------------------------
148 void a_point2::read(std::istream &in)
149 {
150  in >> x_;
151  in >> y_;
152 }
153 //---------------------------------------------------------------------------
154 void a_point2::write(std::ostream &o) const
155 {
156  o << this->x() << " ";
157  o << this->y() << " ";
158 }
159 //---------------------------------------------------------------------------
160 double angle(const a_point2& a, const a_point2& b)
161 {
162  a_point a3(a.x(),a.y(),0.);
163  a_point b3(b.x(),b.y(),0.);
164  return angle(a3,b3);
165 }
166 //---------------------------------------------------------------------------
167 a_point2 average_rot(const a_point2& a, const a_point2& b, double f)
168 {
169  a_point a3(a.x(),a.y(),0.);
170  a_point b3(b.x(),b.y(),0.);
171  a_point r = average_rot(a3,b3);
172  return a_point2(r.x(),r.y());
173 }
a_point2 average_rot(const a_point2 &a, const a_point2 &b, double f)
Definition: a_point2.cxx:167
double angle(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:160
a_point2 operator+(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:106
double operator*(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:118
a_point2 operator/(const a_point2 &a, double v)
Definition: a_point2.cxx:136
a_point2 circle_centre(const a_point2 &p1, const a_point2 &p2, const a_point2 &p3)
Definition: a_point2.cxx:142
a_point2 operator-(const a_point2 &a, const a_point2 &b)
Definition: a_point2.cxx:112
a_quaternion sqrt(const a_quaternion &x)
double y() const
Definition: a_point2.h:53
a_point2 & operator-=(const a_point2 &)
Definition: a_point2.cxx:42
static const std::string help()
Definition: a_point2.cxx:22
double norm() const
Definition: a_point2.cxx:85
a_point2 & normalise()
Definition: a_point2.cxx:90
a_point2 & operator+=(const a_point2 &)
Definition: a_point2.cxx:35
double operator*=(const a_point2 &)
Definition: a_point2.cxx:49
a_point2 & operator=(const a_point2 &p)
Definition: a_point2.cxx:59
virtual void write(std::ostream &o) const
Definition: a_point2.cxx:154
double sumsq() const
Definition: a_point2.cxx:80
virtual void read(std::istream &i)
Definition: a_point2.cxx:148
a_point2 & operator-()
Definition: a_point2.cxx:28
a_point2 & rotate(const double angle)
Definition: a_point2.cxx:97
double x_
Definition: a_point2.h:86
bool operator==(const a_point2 &p)
Definition: a_point2.cxx:54
double x() const
Definition: a_point2.h:52
double y_
Definition: a_point2.h:87
a_point2 & operator/=(double v)
Definition: a_point2.cxx:73
double y() const
Definition: a_point.h:55
double x() const
Definition: a_point.h:54