Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_mat_r.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2010-2012 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_mat_r.h"
17 #include <math.h>
18 
19 // .PORTABILITY : ansi C++
20 
21 //***************************************************************************
22 //member functions
23 //-operator=-----------------------------------------------------------------
25 {
26  if (m.maxj() != maxj_) throw compatibility_error();
27  if (m.maxi() != 1) throw compatibility_error();
28  (*x_) = m.x();
29  return (*this);
30 }
31 //-sumsq---------------------------------------------------------------------
32 double a_mat_r::sumsq() const
33 {
34  double v = 0;
35  for (UI i = 0; i<maxi_; i++)
36  v += (*x_)[i]*(*x_)[i];
37  return v;
38 }
39 //-norm----------------------------------------------------------------------
40 double a_mat_r::norm() const
41 {
42  return sqrt(sumsq());
43 }
44 //-normalise-----------------------------------------------------------------
46 {
47  double n = norm();
48  if (n != 0) (*x_) /= n;
49 }
50 //***************************************************************************
51 //-cross---------------------------------------------------------------------
53 {
54  if ((a.maxj() != 3)||(b.maxj() != 3)) throw a_mat::compatibility_error();
55  a_mat_r r(3);
56  r(0) = a(1)*b(2)-a(2)*b(1);
57  r(1) = a(2)*b(0)-a(0)*b(2);
58  r(2) = a(0)*b(1)-a(1)*b(0);
59  return r;
60 }
unsigned int UI
Definition: a_mat.h:23
a_mat_r cross(a_mat_r &a, a_mat_r &b)
Definition: a_mat_r.cxx:52
a_quaternion sqrt(const a_quaternion &x)
a row matrix unit
Definition: a_mat_r.h:29
double norm() const
Definition: a_mat_r.cxx:40
double sumsq() const
Definition: a_mat_r.cxx:32
a_mat_r & operator=(const a_mat &m)
Definition: a_mat_r.cxx:24
void normalise()
Definition: a_mat_r.cxx:45
Definition: a_mat.h:42
std::valarray< double > * x_
Definition: a_mat.h:91
UI maxj_
Definition: a_mat.h:89
std::valarray< double > & x() const
Definition: a_mat.h:53
UI maxi_
Definition: a_mat.h:88
UI maxi() const
Definition: a_mat.h:49
UI maxj() const
Definition: a_mat.h:50