Points&Forces (survey)
Software tools facilitating the task of surveying architecture
e_point.cxx
Go to the documentation of this file.
1 /*
2  Copyright 2002-2011 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 "e_point.h"
17 #include <math.h>
18 
19 //---------------------------------------------------------------------------
21 {
22  x_ += p.x();
23  y_ += p.y();
24  z_ += p.z();
25  return *this;
26 }
27 //---------------------------------------------------------------------------
29 {
30  x_ -= p.x();
31  y_ -= p.y();
32  z_ -= p.z();
33  return *this;
34 }
35 //---------------------------------------------------------------------------
36 double e_point::operator*=(const e_point& p)
37 {
38  return x_*p.x()+y_*p.y()+z_*p.z();
39 }
40 //-operator*=----------------------------------------------------------------
41 e_point & e_point::operator*=(const double v)
42 {
43  x_ *= v;
44  y_ *= v;
45  z_ *= v;
46  return (*this);
47 }
48 //-operator/=----------------------------------------------------------------
49 e_point & e_point::operator/=(const double v)
50 {
51  x_ /= v;
52  y_ /= v;
53  z_ /= v;
54  return (*this);
55 }
56 //-sumsq---------------------------------------------------------------------
57 double e_point::sumsq() const
58 {
59  return x_*x_+y_*y_+z_*z_;
60 }
61 //-norm----------------------------------------------------------------------
62 double e_point::norm() const
63 {
64  return sqrt(sumsq());
65 }
66 //-normalise-----------------------------------------------------------------
68 {
69  double n = norm();
70  if (n != 0) operator/=(n);
71  return *this;
72 }
73 //***************************************************************************
74 //-operator+-----------------------------------------------------------------
76 {
77  e_point r = a;
78  return r += b;
79 }
80 //-operator------------------------------------------------------------------
82 {
83  e_point r = a;
84  return r -= b;
85 }
86 //-operator*-----------------------------------------------------------------
87 double operator*(e_point& a, e_point& b)
88 {
89  e_point r = a;
90  return r *= b;
91 }
92 //-operator*-----------------------------------------------------------------
94 {
95  e_point r = a;
96  return r *= v;
97 }
98 //-operator*-----------------------------------------------------------------
100 {
101  e_point r = a;
102  return r *= v;
103 }
104 //-cross---------------------------------------------------------------------
106 {
107  e_point r;
108  r.x(a.y()*b.z()-a.z()*b.y());
109  r.y(a.z()*b.x()-a.x()*b.z());
110  r.z(a.x()*b.y()-a.y()*b.x());
111  return r;
112 }
113 //***************************************************************************
114 //---------------------------------------------------------------------------
115 std::istream& operator>> (std::istream& i, e_point& p)
116 {
117  i >> p.x_;
118  i >> p.y_;
119  i >> p.z_;
120  return i;
121 }
122 //---------------------------------------------------------------------------
123 std::ostream& operator<< (std::ostream& o, const e_point& p)
124 {
125  o << p.x() << " ";
126  o << p.y() << " ";
127  o << p.z() << " " << std::endl;
128  return o;
129 }
130 //---------------------------------------------------------------------------
131 std::istream& operator>> (std::istream& i, e_point* p)
132 {
133  i >> p->x_;
134  i >> p->y_;
135  i >> p->z_;
136  return i;
137 }
138 //---------------------------------------------------------------------------
139 std::ostream& operator<< (std::ostream& o, const e_point* p)
140 {
141  o << p->x() << " ";
142  o << p->y() << " ";
143  o << p->z() << " " << std::endl;
144  return o;
145 }
146 //---------------------------------------------------------------------------
147 void e_point::print(std::ostream& o)
148 {
149  o << "d " << this->norm() << std::endl;
150  o << "dx " << this->x() << std::endl;
151  o << "dy " << this->y() << std::endl;
152  o << "dz " << this->z() << std::endl;
153  e_point a(*this);
154  a.normalise();
155  o << "cx " << a.x() << " " << 180/3.141592653589*acos(a.x()) << std::endl;
156  o << "cy " << a.y() << " " << 180/3.141592653589*acos(a.y()) << std::endl;
157  o << "cz " << a.z() << " " << 180/3.141592653589*acos(a.z()) << std::endl;
158 }
point + ...
Definition: e_point.h:29
double z_
Definition: e_point.h:67
double operator*=(const e_point &)
Definition: e_point.cxx:36
double z() const
Definition: e_point.h:39
double x() const
Definition: e_point.h:37
double y_
Definition: e_point.h:66
double norm() const
Definition: e_point.cxx:62
e_point & operator+=(const e_point &)
Definition: e_point.cxx:20
double y() const
Definition: e_point.h:38
e_point & operator-=(const e_point &)
Definition: e_point.cxx:28
double sumsq() const
Definition: e_point.cxx:57
void print(std::ostream &o)
Definition: e_point.cxx:147
e_point & normalise()
Definition: e_point.cxx:67
e_point & operator/=(const double v)
Definition: e_point.cxx:49
double x_
Definition: e_point.h:65
e_point cross(e_point &a, e_point &b)
Definition: e_point.cxx:105
double operator*(e_point &a, e_point &b)
Definition: e_point.cxx:87
e_point operator-(e_point &a, e_point &b)
Definition: e_point.cxx:81
std::istream & operator>>(std::istream &i, e_point &p)
Definition: e_point.cxx:115
e_point operator+(e_point &a, e_point &b)
Definition: e_point.cxx:75
std::ostream & operator<<(std::ostream &o, const e_point &p)
Definition: e_point.cxx:123
double v(const uint32_t step, const uint32_t n)
Definition: generate.cxx:42
uint32_t n[]
Definition: generate.cxx:34