Points&Forces (survey)
Software tools facilitating the task of surveying architecture
a_contact.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2010-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 <math.h>
17 #include "a_contact.h"
18 #include "a_debug.h"
19 
20 const double verysmall=1.e-10;
21 //---------------------------------------------------------------------------
23 {
24  vertices_.clear();
25  for (int i=0; i<c.nv(); i++)
26  this->av(c.v(i));
27  f_ = c.f();
28 }
29 //---------------------------------------------------------------------------
30 a_segment a_contact::s(const int i) const
31 {
32  int n=this->nv();
33  return a_segment(this->v(i%n),this->v((i+1)%n));
34 }
35 //---------------------------------------------------------------------------
37 {
39  const int n = this->nv();
40  if (n<3)
41  return;
42  a_contact c2;
43  c2.av(this->v(0));
44  int i = 0;
45  while (i<n-2)
46  {
47  a_point p1 = this->v(i);
48  a_segment s1(p1,this->v(i+1));
49  a_point d1 = s1.dir();
50  int k;
51  double c;
52  k = i+2;
53  do
54  {
55  a_segment s2(p1,this->v(k));
56  a_point d2 = s2.dir();
57  c = fabs(d1*d2);
58  k++;
59  } while ((c<verysmall)&&(k<n));
60  i = k-1;
61  c2.av(this->v(i));
62  }
63  if (i!=n-1)
64  c2.av(this->v(n-1));
65  (*this) = c2;
66 }
67 //***************************************************************************
68 //---------------------------------------------------------------------------
69 void a_contact::read(std::istream &in)
70 {
71  int nv;
72  in >> nv;
73  vertices_.clear();
74  for (int i=0; i<nv; i++)
75  {
76  a_point pt;
77  in >> pt;
78  vertices_.push_back(pt);
79  }
80 }
81 //---------------------------------------------------------------------------
82 void a_contact::write(std::ostream &o) const
83 {
84  o << this->nv() << " ";
85  for (int i=0; i<this->nv(); i++)
86  o << this->v(i) << " ";
87  o << std::endl;
88 }
89 //-operator>>----------------------------------------------------------------
90 std::istream& operator>> (std::istream& in, a_contact& c)
91 {
92  c.read(in);
93  return in;
94 }
95 //-operator<<----------------------------------------------------------------
96 std::ostream& operator<< (std::ostream& o, const a_contact& c)
97 {
98  c.write(o);
99  return o;
100 }
std::istream & operator>>(std::istream &in, a_contact &c)
Definition: a_contact.cxx:90
const double verysmall
Definition: a_contact.cxx:20
std::ostream & operator<<(std::ostream &o, const a_contact &c)
Definition: a_contact.cxx:96
void f(const a_wrench &f)
set force on the face
Definition: a_contact.h:43
std::vector< a_point > vertices_
points defining face
Definition: a_contact.h:54
void clean()
clean
Definition: a_contact.cxx:36
a_wrench f_
force on the face
Definition: a_contact.h:56
a_point v(const int i) const
get a vertex
Definition: a_contact.h:37
virtual void read(std::istream &i)
Definition: a_contact.cxx:69
a_segment s(const int i) const
get a segment
Definition: a_contact.cxx:30
void av(const a_point p)
add a vertex
Definition: a_contact.h:35
virtual void write(std::ostream &o) const
Definition: a_contact.cxx:82
int nv() const
get number of vertices
Definition: a_contact.h:33
a_contact()
Definition: a_contact.h:30