Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_triangle.h
Go to the documentation of this file.
1 /*
2  Copyright 2010-2019 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_TRIANGLE_H_
17 #define _A_TRIANGLE_H_
18 
19 #include <iostream>
20 #include <stdlib.h>
21 #include "a_point.h"
22 #include "a_segment.h"
23 #include "a_mat_sq.h"
24 
30 class a_triangle: public a_geom_base
31 {
32  public:
33  a_triangle() : p1_(), p2_(), p3_() {}
34  a_triangle(const a_point& p1, const a_point& p2, const a_point& p3) : p1_(p1), p2_(p2), p3_(p3) {}
35  a_triangle(const a_triangle& p) {p1_ = p.p1_; p2_ = p.p2_; p3_ = p.p3_;}
36 
37  virtual const std::string classname() { return "a_triangle";}
38  static const std::string help();
39  //: get points
40  inline a_point p1() const { return p1_; }
41  inline a_point p2() const { return p2_; }
42  inline a_point p3() const { return p3_; }
43  inline a_point operator[](const int i) const {if (i==0) return p1_; if (i==1) return p2_; if (i==2) return p3_; exit(1);}
44  inline a_point p(const int i) const {if (i==0) return p1_; if (i==1) return p2_; if (i==2) return p3_; exit(1);}
45 
46  //: set points
47  inline void p1(const a_point& v) { p1_ = v; }
48  inline void p2(const a_point& v) { p2_ = v; }
49  inline void p3(const a_point& v) { p3_ = v; }
50  inline void set(const a_point& p1, const a_point& p2, const a_point& p3) {p1_ = p1; p2_ = p2; p3_ = p3;}
51 
53  inline a_segment s1() const {return a_segment(p1_,p2_);}
55  inline a_segment s2() const {return a_segment(p2_,p3_);}
57  inline a_segment s3() const {return a_segment(p3_,p1_);}
59  a_segment s(const int ref) const;
61  inline a_point c() const { return (p1_+p2_+p3_)/3.; }
62  a_triangle& translate(double x, double y, double z);
63  a_triangle& rotate(const a_point& x_axis, const a_point& y_axis, const a_point& z_axis);
64  a_triangle& invert();
65  a_point normal() const;
66  double S() const;
68  a_triangle shape() const;
70  a_mat_sq coord() const;
72  a_mat_sq inertia() const;
74  bool contains(const a_point& p) const;
76  a_point closest(const a_point& p) const;
78  a_point closestp(const a_point& p) const;
80  double dist(const a_point& p) const;
82  double distp(const a_point& p) const;
84  a_segment intersect(const a_segment& s) const;
86  double min_edge() const;
88  double max_edge() const;
90  double quality() const;
91  bool operator==(const a_triangle& p);
93 
94  //: input/output
95  virtual void read(std::istream &i);
96  virtual void write(std::ostream &o) const;
97 
98  protected:
102 };
103 
104 #endif
a square matrix unit
Definition: a_mat_sq.h:29
a segment
Definition: a_segment.h:29
a triangle
Definition: a_triangle.h:31
a_triangle & invert()
Definition: a_triangle.cxx:94
a_triangle(const a_point &p1, const a_point &p2, const a_point &p3)
Definition: a_triangle.h:34
a_triangle(const a_triangle &p)
Definition: a_triangle.h:35
a_point p3_
Definition: a_triangle.h:101
void p2(const a_point &v)
Definition: a_triangle.h:48
a_point p1_
Definition: a_triangle.h:99
a_triangle & rotate(const a_point &x_axis, const a_point &y_axis, const a_point &z_axis)
Definition: a_triangle.cxx:86
double max_edge() const
length of longest segment
Definition: a_triangle.cxx:291
static const std::string help()
Definition: a_triangle.cxx:24
void p3(const a_point &v)
Definition: a_triangle.h:49
a_point p(const int i) const
Definition: a_triangle.h:44
virtual void read(std::istream &i)
Definition: a_triangle.cxx:324
bool operator==(const a_triangle &p)
Definition: a_triangle.cxx:58
virtual void write(std::ostream &o) const
Definition: a_triangle.cxx:331
a_point operator[](const int i) const
Definition: a_triangle.h:43
a_point p1() const
Definition: a_triangle.h:40
a_triangle & operator=(const a_triangle &p)
Definition: a_triangle.cxx:63
bool contains(const a_point &p) const
check whether point lies inside triangle
Definition: a_triangle.cxx:168
a_segment s(const int ref) const
get segment i (0-2) of triangle
Definition: a_triangle.cxx:71
a_triangle shape() const
triangle with same shape but with centre of gravity at origin
Definition: a_triangle.cxx:112
a_point closest(const a_point &p) const
triangle point closest to p
Definition: a_triangle.cxx:201
virtual const std::string classname()
Definition: a_triangle.h:37
a_segment s2() const
get second segment of triangle
Definition: a_triangle.h:55
double S() const
Definition: a_triangle.cxx:107
void set(const a_point &p1, const a_point &p2, const a_point &p3)
Definition: a_triangle.h:50
a_segment s1() const
get first segment of triangle
Definition: a_triangle.h:53
a_point p3() const
Definition: a_triangle.h:42
a_mat_sq inertia() const
inertia of the triangle 3x3 matrix
Definition: a_triangle.cxx:130
double quality() const
quality: ratio between smaller and bigger segment
Definition: a_triangle.cxx:303
void p1(const a_point &v)
Definition: a_triangle.h:47
a_point c() const
get centre of gravity
Definition: a_triangle.h:61
a_point normal() const
Definition: a_triangle.cxx:102
double min_edge() const
length of smallest segment
Definition: a_triangle.cxx:279
a_segment s3() const
get third segment of triangle
Definition: a_triangle.h:57
a_segment intersect(const a_segment &s) const
intersection of triangle with a segment
Definition: a_triangle.cxx:232
a_triangle & translate(double x, double y, double z)
Definition: a_triangle.cxx:78
double distp(const a_point &p) const
distance between p and plane defined by triangle
Definition: a_triangle.cxx:227
a_point p2() const
Definition: a_triangle.h:41
a_point p2_
Definition: a_triangle.h:100
a_mat_sq coord() const
cordinates of the triangle as a 3x3 matrix
Definition: a_triangle.cxx:118
double dist(const a_point &p) const
distance between p and triangle
Definition: a_triangle.cxx:222
a_point closestp(const a_point &p) const
point of plane defined by triangle closest to p
Definition: a_triangle.cxx:195