Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_point.h
Go to the documentation of this file.
1 /*
2  Copyright 2010-2020 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 #ifndef _A_POINT_H_
17 #define _A_POINT_H_
18 
19 #include "a_geom_base.h"
20 #include <stdlib.h>
21 #include <cmath>
22 #include "a_mat_sq.h"
23 
31 class a_point;
32 
33 a_point operator+(const a_point& a, const a_point& b);
34 a_point operator-(const a_point& a, const a_point& b);
35 double operator*(const a_point& a, const a_point& b);
36 a_point operator*(const double v, const a_point& a);
37 a_point operator*(const a_point& a, double v);
38 a_point cross(const a_point& a, const a_point& b);
39 a_point operator/(const a_point& a, double v);
40 a_point circle_centre(const a_point&, const a_point&, const a_point&);
41 
42 class a_point: public a_geom_base
43 {
44  public:
45  a_point() = default;
46  a_point(double x, double y, double z) : x_(x), y_(y), z_(z) {}
47  a_point(const float x[3]) : x_(x[0]), y_(x[1]), z_(x[2]) {}
48  a_point(const double x[3]) : x_(x[0]), y_(x[1]), z_(x[2]) {}
49  inline a_point(const a_point& p) {x_ = p.x_; y_ = p.y_; z_ = p.z_;}
50 
51  virtual const std::string classname() { return "a_point";}
52  static const std::string help();
53  //: get coordinates
54  inline double x() const { return x_; }
55  inline double y() const { return y_; }
56  inline double z() const { return z_; }
57  inline double operator[](const int i) const {if (i==0) return x_; if (i==1) return y_; if (i==2) return z_; exit(1); return x_;}
58 
59  //: set coordinates
60  inline void x(double v) { x_ = v; }
61  inline void y(double v) { y_ = v; }
62  inline void z(double v) { z_ = v; }
63  inline void set(double x, double y, double z) {x_ = x; y_ = y; z_ = z;}
64  inline void set(double x[3]) {x_ = x[0]; y_ = x[1]; z_ = x[2];}
65  inline void set(float x[3]) {x_ = x[0]; y_ = x[1]; z_ = x[2];}
66  a_mat_sq inertia() const;
67  inline void set_cylindrical(double r, double a, double h) {x_ = r*cos(a); y_ = r*sin(a); z_ = h;}
68  inline void set_spherical(double r, double th, double ph) {x_ = r*cos(th)*cos(ph); y_ = r*cos(th)*sin(ph); z_ = r*sin(th);}
69  inline void clear() {this->set(0.,0.,0.);}
70  inline a_point& translate(double x, double y, double z) {x_ += x; y_ += y; z_ += z; return *this;}
71  a_point& rotate(const a_point& x_axis, const a_point& y_axis, const a_point& z_axis);
72  a_point& rotate(const a_point& axis, const double angle);
73  inline double& operator[](const int i) {if (i==0) return x_; if (i==1) return y_; if (i==2) return z_; exit(1); return x_;}
74 
75  bool operator==(const a_point& p) const;
76  bool operator!=(const a_point& p) const {return !this->operator==(p);}
77  a_point& operator=(const a_point& p);
78  a_point& operator-();
79  a_point operator+(const a_point&);
80  a_point operator-(const a_point&);
81  double operator*(const a_point&);
82  a_point cross(const a_point&) const;
83  // a_point operator*(double v);
84  a_point& operator+=(const a_point&);
85  a_point& operator-=(const a_point&);
86  double operator*=(const a_point&);
87  a_point& operator*=(double v);
88  a_point& operator/=(double v);
89 
91  double sumsq() const;
92  double norm() const;
93  double norm1() const;
94  double norm2() const;
95  double normI() const;
96  inline double dist(const a_point& p) const {return (p-*this).norm();}
97  a_point& normalise();
99  a_point& max();
100 
101  //: input/output
102  virtual void read(std::istream &i);
103  virtual void write(std::ostream &o) const;
104 
105  protected:
106  double x_ = 0.;
107  double y_ = 0.;
108  double z_ = 0.;
109 };
110 
111 inline double dist(const a_point& a, const a_point& b) {return (a-b).norm();}
112 double angle(a_point a, a_point b);
113 inline a_point average(const a_point& a, const a_point& b, double f = 0.5) {return (a+f*(b-a));}
114 a_point average_rot(const a_point& a, const a_point& b, double f = 0.5);
115 
116 #endif
a_point operator-(const a_point &a, const a_point &b)
Definition: a_point.cxx:254
a_point operator+(const a_point &a, const a_point &b)
Definition: a_point.cxx:248
double angle(a_point a, a_point b)
Definition: a_point.cxx:329
a_point cross(const a_point &a, const a_point &b)
Definition: a_point.cxx:284
a_point average_rot(const a_point &a, const a_point &b, double f=0.5)
Definition: a_point.cxx:352
a_point circle_centre(const a_point &, const a_point &, const a_point &)
Definition: a_point.cxx:293
double dist(const a_point &a, const a_point &b)
Definition: a_point.h:111
a_point average(const a_point &a, const a_point &b, double f=0.5)
Definition: a_point.h:113
a_point operator/(const a_point &a, double v)
Definition: a_point.cxx:278
double operator*(const a_point &a, const a_point &b)
Definition: a_point.cxx:260
a square matrix unit
Definition: a_mat_sq.h:29
a_point(const a_point &p)
Definition: a_point.h:49
a_point & operator-=(const a_point &)
Definition: a_point.cxx:121
double norm1() const
Definition: a_point.cxx:172
void x(double v)
Definition: a_point.h:60
a_point operator+(const a_point &)
Definition: a_point.cxx:79
a_point & operator+=(const a_point &)
Definition: a_point.cxx:113
double normI() const
Definition: a_point.cxx:180
a_point(const double x[3])
Definition: a_point.h:48
a_point(const float x[3])
Definition: a_point.h:47
a_point & operator=(const a_point &p)
Definition: a_point.cxx:139
double x_
Definition: a_point.h:106
double y_
Definition: a_point.h:107
bool operator==(const a_point &p) const
Definition: a_point.cxx:134
bool operator!=(const a_point &p) const
Definition: a_point.h:76
a_point & rotate(const a_point &x_axis, const a_point &y_axis, const a_point &z_axis)
Definition: a_point.cxx:225
a_point(double x, double y, double z)
Definition: a_point.h:46
a_point cross(const a_point &) const
Definition: a_point.cxx:96
double sumsq() const
Definition: a_point.cxx:163
void set(double x, double y, double z)
Definition: a_point.h:63
void clear()
Definition: a_point.h:69
void set_spherical(double r, double th, double ph)
Definition: a_point.h:68
a_point & normalise()
Definition: a_point.cxx:190
static const std::string help()
Definition: a_point.cxx:22
a_point & operator/=(double v)
Definition: a_point.cxx:155
double z() const
Definition: a_point.h:56
double y() const
Definition: a_point.h:55
a_point & translate(double x, double y, double z)
Definition: a_point.h:70
double norm2() const
Definition: a_point.cxx:176
double z_
Definition: a_point.h:108
a_point & operator/=(const a_point &)
double x() const
Definition: a_point.h:54
a_point()=default
void z(double v)
Definition: a_point.h:62
void set_cylindrical(double r, double a, double h)
Definition: a_point.h:67
double dist(const a_point &p) const
Definition: a_point.h:96
virtual const std::string classname()
Definition: a_point.h:51
virtual void write(std::ostream &o) const
Definition: a_point.cxx:322
void set(float x[3])
Definition: a_point.h:65
double operator*=(const a_point &)
Definition: a_point.cxx:129
a_mat_sq inertia() const
Definition: a_point.cxx:197
double operator*(const a_point &)
Definition: a_point.cxx:91
void y(double v)
Definition: a_point.h:61
virtual void read(std::istream &i)
Definition: a_point.cxx:315
a_point & operator-()
Definition: a_point.cxx:71
a_point & max()
set maximum abs value of component to 1.
Definition: a_point.cxx:214
double norm() const
Definition: a_point.cxx:168
double & operator[](const int i)
Definition: a_point.h:73
double operator[](const int i) const
Definition: a_point.h:57
void set(double x[3])
Definition: a_point.h:64