Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_mat_c.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2010-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_mat_c.h"
17 #include <math.h>
18 
19 // .PORTABILITY : ansi C++
20 
21 //***************************************************************************
22 //member functions
23 //-operator=-----------------------------------------------------------------
25 {
26  if (m.maxj() != 1) throw compatibility_error();
27  if (m.maxi() != maxi_) throw compatibility_error();
28  (*x_) = m.x();
29  return (*this);
30 }
31 //-sumsq---------------------------------------------------------------------
32 double a_mat_c::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_c::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.maxi() != 3)||(b.maxi() != 3)) throw a_mat::compatibility_error();
55  a_mat_c 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_c cross(a_mat_c &a, a_mat_c &b)
Definition: a_mat_c.cxx:52
a_quaternion sqrt(const a_quaternion &x)
a column matrix unit
Definition: a_mat_c.h:29
double sumsq() const
Definition: a_mat_c.cxx:32
double norm() const
Definition: a_mat_c.cxx:40
a_mat_c & operator=(const a_mat &m)
Definition: a_mat_c.cxx:24
void normalise()
Definition: a_mat_c.cxx:45
Definition: a_mat.h:42
std::valarray< double > * x_
Definition: a_mat.h:91
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