Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_circle.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2000-12 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_circle.h"
17 #include <vector>
18 #include <algorithm>
19 #include <math.h>
20 #include <sstream>
21 
22 //---------------------------------------------------------------------------
23 const std::string a_circle::help()
24 {
25  std::ostringstream o;
26  o << "*********" << std::endl;
27  o << "a_circle:" << std::endl;
28  o << "*********" << std::endl;
29  o << "This is a 'circle' class" << std::endl;
30  o << std::endl;
31  o << "Create a circle:" << std::endl;
32  o << " a_point a" << std::endl;
33  o << std::endl;
34  o << "Commands:" << std::endl;
35  o << "centre: get or set centre." << std::endl;
36  o << "normal: get or set normal." << std::endl;
37  o << "radius: get or set radius." << std::endl;
38  o << "p3 _p1 _p2 _p3: set circle passing by 3 points." << std::endl;
39  o << "p2 _p1 _p2: move a circle to make it pass by 2 points; keeps radius and normal of original circle." << std::endl;
40  o << "length: returns length." << std::endl;
41  o << "area: returns area." << std::endl;
42  o << "print: prints parameters." << std::endl;
43  o << a_geom_base::help();
44  return o.str();
45 }
46 //---------------------------------------------------------------------------
48 {
49  return ((c_ == s.centre())&&(n_ == s.normal())&&(r_ == s.radius()));
50 }
51 //---------------------------------------------------------------------------
53 {
54  c_ = s.centre();
55  n_ = s.normal();
56  r_ = s.radius();
57  return *this;
58 }
59 //---------------------------------------------------------------------------
60 void a_circle::p3(const a_point p1, const a_point p2, const a_point p3)
61 {
62  a_point d1 = p2-p1;
63  a_point d2 = p3-p1;
64  a_point dir = cross(d1,d2);
65  if (dir.norm()==0) return;
66  this->normal(dir);
67  a_point ce = circle_centre(p1,p2,p3);
68  this->centre(ce);
69  this->radius(((p1-ce).norm()+(p2-ce).norm()+(p3-ce).norm())/3.);
70 }
71 //---------------------------------------------------------------------------
72 void a_circle::p2(const a_point p1, const a_point p2)
73 {
74  a_point d = p2-p1;
75  double b = d.norm()/2.;
76  if (b>r_)
77  return;
78  double n = sqrt(r_*r_-b*b);
79  a_point m = (p1+p2)/2.;
80  a_point t = cross(d,n_).normalise();
81  this->centre(m+n*t);
82 }
83 //***************************************************************************
84 //---------------------------------------------------------------------------
85 void a_circle::read(std::istream &in)
86 {
87  in >> c_;
88  in >> n_;
89  in >> r_;
90 }
91 //---------------------------------------------------------------------------
92 void a_circle::write(std::ostream &o) const
93 {
94  o << this->centre() << " ";
95  o << this->normal() << " ";
96  o << this->radius() << " ";
97 }
a_point cross(const a_point &a, const a_point &b)
Definition: a_point.cxx:284
a_point circle_centre(const a_point &p1, const a_point &p2, const a_point &p3)
Definition: a_point.cxx:293
a_quaternion sqrt(const a_quaternion &x)
a_circle & operator=(const a_circle &v)
Definition: a_circle.cxx:52
a_point normal() const
Definition: a_circle.h:43
static const std::string help()
Definition: a_circle.cxx:23
double radius() const
Definition: a_circle.h:46
a_point centre() const
Definition: a_circle.h:40
void p3(const a_point p1, const a_point p2, const a_point p3)
Definition: a_circle.cxx:60
a_point c_
Definition: a_circle.h:65
bool operator==(const a_circle &p)
Definition: a_circle.cxx:47
void p2(const a_point p1, const a_point p2)
Definition: a_circle.cxx:72
void normal(const a_point n)
Definition: a_circle.h:42
a_point n_
Definition: a_circle.h:66
double r_
Definition: a_circle.h:67
void centre(const a_point c)
Definition: a_circle.h:39
void radius(double r)
Definition: a_circle.h:45
virtual void read(std::istream &i)
Definition: a_circle.cxx:85
virtual void write(std::ostream &o) const
Definition: a_circle.cxx:92
static const std::string help()
Definition: a_geom_base.cxx:21
a_point & normalise()
Definition: a_point.cxx:190
double norm() const
Definition: a_point.cxx:168