Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_pos2.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_pos2.h"
17 //---------------------------------------------------------------------------
18 a_pos2::a_pos2(const a_mat& m) : a_mat(4,4)
19 {
20  for (int i = 0; i<4; i++)
21  {
22  for (int j = 0; j<4; j++)
23  (*this)(i,j)= m(i,j);
24  }
25 }
26 //---------------------------------------------------------------------------
28 {
29  // rz*ry*rx
30  double a[] = {cos(ax_), sin(ax_), cos(ay_), sin(ay_), cos(az_), sin(az_)};
31  (*this)(0,0) = a[2]*a[4];
32  (*this)(0,1) = a[1]*a[3]*a[4] + a[0]*a[5];
33  (*this)(0,2) = -a[0]*a[3]*a[4] + a[1]*a[5];
34  (*this)(1,0) = -a[2]*a[5];
35  (*this)(1,1) = -a[1]*a[3]*a[5] + a[0]*a[4];
36  (*this)(1,2) = a[0]*a[3]*a[5] + a[1]*a[4];
37  (*this)(2,0) = a[3];
38  (*this)(2,1) = -a[1]*a[2];
39  (*this)(2,2) = a[0]*a[2];
40 }
41 //---------------------------------------------------------------------------
42 bool angle_egal(double a, double b)
43 {
44  double c = cos(a)-cos(b);
45  double s = sin(a)-sin(b);
46  return c*c+s*s < 0.0001;
47 }
48 //---------------------------------------------------------------------------
50 {
51  const double pi = 3.141592653589793238;
52  double f1 = asin((*this)(2,0));
53 
54  double o1 = asin(-(*this)(2,1)/cos(f1));
55  double o2 = -o1;
56  double o3 = acos((*this)(2,2)/cos(f1));
57  double o4 = -o3;
58 
59  if (angle_egal(o2,o3)||angle_egal(o2,o4))
60  o1 = o2;
61 
62  double k1 = acos((*this)(0,0)/cos(f1));
63  double k2 = -k1;
64  double k3 = asin(-(*this)(1,0)/cos(f1));
65  double k4 = -k3;
66 
67  if (angle_egal(k2,k3)||angle_egal(k2,k4))
68  k1 = k2;
69 
70  ax_ = o1;
71  ay_ = f1;
72  az_ = k1;
73 }
74 //---------------------------------------------------------------------------
76 {
77  (*this)(0,3) = ox_;
78  (*this)(1,3) = oy_;
79  (*this)(2,3) = oz_;
80  (*this)(3,3) = 1;
81 }
82 //---------------------------------------------------------------------------
84 {
85  ox_ = (*this)(0,3);
86  oy_ = (*this)(1,3);
87  oz_ = (*this)(2,3);
88 }
89 //---------------------------------------------------------------------------
90 std::istream& operator>> (std::istream& i, a_pos2& m)
91 {
92  int i0,j0;
93  i >> i0;
94  i >> j0;
95  if ((i0 != m.maxi_)||(j0 != m.maxj_)) throw a_mat::range_error();
96  for (UI j=0; j < m.maxi_; j++)
97  {
98  for (UI k=0; k < m.maxj_; k++)
99  i >> m(j,k);
100  }
101  m.compute_or_inv();
102  m.compute_rot_inv();
103  return i;
104 }
const double pi
a circle
Definition: a_circle.h:29
unsigned int UI
Definition: a_mat.h:23
std::istream & operator>>(std::istream &i, a_pos2 &m)
Definition: a_pos2.cxx:90
bool angle_egal(double a, double b)
Definition: a_pos2.cxx:42
Definition: a_mat.h:42
UI maxj_
Definition: a_mat.h:89
UI maxi_
Definition: a_mat.h:88
a position matrix
Definition: a_pos2.h:29
void compute_rot()
Definition: a_pos2.cxx:27
double ax_
Definition: a_pos2.h:66
a_pos2()
Definition: a_pos2.h:31
double oz_
Definition: a_pos2.h:65
double ay_
Definition: a_pos2.h:66
void compute_or_inv()
Definition: a_pos2.cxx:83
double ox_
Definition: a_pos2.h:65
double az_
Definition: a_pos2.h:66
double oy_
Definition: a_pos2.h:65
void compute_rot_inv()
Definition: a_pos2.cxx:49
void compute_or()
Definition: a_pos2.cxx:75