Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
xyzMatrix.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/xyzMatrix.hh
11 /// @brief Fast 3x3 matrix
12 /// @author Frank M. D'Ippolito (Objexx@objexx.com)
13 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
14 /// @remarks
15 /// @li Inline, loop-free functions for speed
16 /// @li Non-virtual destructor for speed: Not set up for use as a base class
17 
18 
19 #ifndef INCLUDED_numeric_xyzMatrix_hh
20 #define INCLUDED_numeric_xyzMatrix_hh
21 
22 
23 // Unit headers
24 #include <numeric/xyzMatrix.fwd.hh>
25 
26 // Package headers
27 #include <numeric/xyzVector.hh>
35 
36 // C++ headers
37 #include <utility/assert.hh>
38 
39 
40 namespace numeric {
41 
42 
43 /// @brief xyzMatrix: Fast 3x3 xyz matrix template
44 
45 template< typename T >
46 class xyzMatrix
47 {
48 
49 
50 private: // Friends
51 
52 
53  template< typename > friend class xyzMatrix;
54 
55  // Friend Functions (for speed of non-inlining debug builds)
56  friend xyzVector< T > operator *<>( xyzMatrix< T > const & m, xyzVector< T > const & v );
57  friend xyzVector< T > product<>( xyzMatrix< T > const & m, xyzVector< T > const & v );
58  friend xyzVector< T > & inplace_product<>( xyzMatrix< T > const & m, xyzVector< T > & v );
59  friend xyzVector< T > transpose_product<>( xyzMatrix< T > const & m, xyzVector< T > const & v );
60  friend xyzVector< T > & inplace_transpose_product<>( xyzMatrix< T > const & m, xyzVector< T > & v );
61  friend xyzMatrix< T > outer_product<>( xyzVector< T > const & a, xyzVector< T > const & b );
62  friend xyzMatrix< T > projection_matrix<>( xyzVector< T > const & v );
63  friend xyzMatrix< T > rotation_matrix<>( xyzVector< T > const & axis, T const & theta );
64  friend xyzVector< T > rotation_axis<>( xyzMatrix< T > const & R, T & theta );
65  friend xyzVector< T > eigenvalue_jacobi<>( xyzMatrix< T > const & a, T const & tol );
66  friend xyzVector< T > eigenvector_jacobi<>( xyzMatrix< T > const & a, T const & tol, xyzMatrix< T > & J );
67  friend xyzMatrix< T > inverse<>( xyzMatrix< T > const & a );
68 
69 
70 public: // Types
71 
72 
73  // Project style
74  typedef T Value;
75  typedef T & Reference;
76  typedef T const & ConstReference;
77  typedef T * Pointer;
78  typedef T const * ConstPointer;
80 
81  // STL/boost style
82  typedef T value_type;
83  typedef T & reference;
84  typedef T const & const_reference;
85  typedef T * pointer;
86  typedef T const * const_pointer;
87 
88 
89 public: // Creation
90 
91 
92  /// @brief Default constructor
93  /// @note Values are uninitialized for efficiency
94  inline
96  {}
97 
98 
99  /// @brief Copy constructor
100  inline
101  xyzMatrix( xyzMatrix const & m ) :
102  xx_( m.xx_ ), xy_( m.xy_ ), xz_( m.xz_ ),
103  yx_( m.yx_ ), yy_( m.yy_ ), yz_( m.yz_ ),
104  zx_( m.zx_ ), zy_( m.zy_ ), zz_( m.zz_ )
105  {}
106 
107 
108  /// @brief Copy constructor
109  template< typename U >
110  inline
111  xyzMatrix( xyzMatrix< U > const & m ) :
112  xx_( m.xx_ ), xy_( m.xy_ ), xz_( m.xz_ ),
113  yx_( m.yx_ ), yy_( m.yy_ ), yz_( m.yz_ ),
114  zx_( m.zx_ ), zy_( m.zy_ ), zz_( m.zz_ )
115  {}
116 
117 
118  /// @brief Uniform value constructor
119  inline
120  explicit
121  xyzMatrix( Value const & t ) :
122  xx_( t ), xy_( t ), xz_( t ),
123  yx_( t ), yy_( t ), yz_( t ),
124  zx_( t ), zy_( t ), zz_( t )
125  {}
126 
127 
128  /// @brief Destructor
129  inline
131  {}
132 
133 
134 public: // Creation: column values
135 
136 
137  /// @brief Column-ordered value named constructor
138  /// @note Constructor usage:
139  /// xyzMatrix m(
140  /// xyzMatrix::cols( xx_a, yx_a, zx_a, xy_a, yy_a, zy_a, xz_a, yz_a, zz_a ) )
141  /// @note Assignment usage:
142  /// m = xyzMatrix::cols( xx_a, yx_a, zx_a, xy_a, yy_a, zy_a, xz_a, yz_a, zz_a )
143  inline
144  static
145  xyzMatrix
147  Value const & xx_a, Value const & yx_a, Value const & zx_a,
148  Value const & xy_a, Value const & yy_a, Value const & zy_a,
149  Value const & xz_a, Value const & yz_a, Value const & zz_a
150  )
151  {
152  return xyzMatrix(
153  xx_a, xy_a, xz_a,
154  yx_a, yy_a, yz_a,
155  zx_a, zy_a, zz_a
156  );
157  }
158 
159 
160 public: // Creation: column pointers
161 
162 
163  /// @brief Pointer to contiguous column-ordered values constructor
164  /// @see cols
165  /// @note The cols named constructor/assignment provides a simple wrapper interface
166  /// @note Constructor usage: xyzMatrix m( xyzMatrix::cols( cols_pointer ) )
167  /// @note Assignment usage: m = xyzMatrix::cols( cols_pointer )
168  template< typename U >
169  inline
171  xx_( *(c.p_) ), xy_( *(c.p_+3) ), xz_( *(c.p_+6) ),
172  yx_( *(c.p_+1) ), yy_( *(c.p_+4) ), yz_( *(c.p_+7) ),
173  zx_( *(c.p_+2) ), zy_( *(c.p_+5) ), zz_( *(c.p_+8) )
174  {}
175 
176 
177  /// @brief Pointer to contiguous column-ordered values named constructor/assignment
178  /// @warning No way to check that argument points to nine contiguous values
179  /// @note Constructor usage: xyzMatrix m( xyzMatrix::cols( cols_pointer ) )
180  /// @note Assignment usage: m = xyzMatrix::cols( cols_pointer )
181  template< typename U >
182  inline
183  static
185  cols( U const * cp )
186  {
187  return ColsPointer< U >( cp );
188  }
189 
190 
191  /// @brief Pointers to contiguous columns constructor
192  /// @see cols
193  /// @note The cols named constructor/assignment provides a simple wrapper interface
194  /// @note Constructor usage:
195  /// xyzMatrix m( xyzMatrix::cols( x_col_pointer, y_col_pointer, z_col_pointer ) )
196  /// @note Assignment usage:
197  /// m = xyzMatrix::cols( x_col_pointer, y_col_pointer, z_col_pointer )
198  template< typename U >
199  inline
201  xx_( *c.xp_ ), xy_( *c.yp_ ), xz_( *c.zp_ ),
202  yx_( *(c.xp_+1) ), yy_( *(c.yp_+1) ), yz_( *(c.zp_+1) ),
203  zx_( *(c.xp_+2) ), zy_( *(c.yp_+2) ), zz_( *(c.zp_+2) )
204  {}
205 
206 
207  /// @brief Pointers to contiguous columns named constructor/assignment
208  /// @warning No way to check that arguments each point to three contiguous values
209  /// @note Constructor usage:
210  /// xyzMatrix m( xyzMatrix::cols( x_col_pointer, y_col_pointer, z_col_pointer ) )
211  /// @note Assignment usage:
212  /// m = xyzMatrix::cols( x_col_pointer, y_col_pointer, z_col_pointer )
213  template< typename U >
214  inline
215  static
218  U const * xp,
219  U const * yp,
220  U const * zp
221  )
222  {
223  return ColPointers< U >( xp, yp, zp );
224  }
225 
226 
227  /// @brief Pointers to contiguous columns named constructor
228  /// @warning No way to check that arguments each point to three contiguous values
229  /// @note Can be faster than cols() construction due to return value optimization
230  /// @note Constructor usage:
231  /// xyzMatrix m(
232  /// xyzMatrix::cols_constructor( x_col_pointer, y_col_pointer, z_col_pointer ) )
233  template< typename U >
234  inline
235  static
236  xyzMatrix
238  U const * xp,
239  U const * yp,
240  U const * zp
241  )
242  {
243  return xyzMatrix(
244  *xp, *yp, *zp,
245  *(xp+1), *(yp+1), *(zp+1),
246  *(xp+2), *(yp+2), *(zp+2)
247  );
248  }
249 
250 
251 public: // Creation: column xyzVectors
252 
253 
254  /// @brief Columns constructor
255  /// @see cols
256  /// @note The cols named constructor/assignment provides a simple wrapper interface
257  /// @note Constructor usage:
258  /// xyzMatrix m( xyzMatrix::cols( x_col_vector, y_col_vector, z_col_vector ) )
259  template< typename U >
260  inline
261  xyzMatrix( ColVectors< U > const & c ) :
262  xx_( c.x_.x_ ), xy_( c.y_.x_ ), xz_( c.z_.x_ ),
263  yx_( c.x_.y_ ), yy_( c.y_.y_ ), yz_( c.z_.y_ ),
264  zx_( c.x_.z_ ), zy_( c.y_.z_ ), zz_( c.z_.z_ )
265  {}
266 
267 
268  /// @brief Column vectors named constructor/assignment
269  /// @note Constructor usage:
270  /// xyzMatrix m( xyzMatrix::cols( x_col_vector, y_col_vector, z_col_vector ) )
271  /// @note Assignment usage:
272  /// m = xyzMatrix::cols( x_col_vector, y_col_vector, z_col_vector )
273  template< typename U >
274  inline
275  static
278  xyzVector< U > const & col_x,
279  xyzVector< U > const & col_y,
280  xyzVector< U > const & col_z
281  )
282  {
283  return ColVectors< U >( col_x, col_y, col_z );
284  }
285 
286 
287  /// @brief xyzVector columns named constructor
288  /// @note Can be faster than cols() construction due to return value optimization
289  /// @note Constructor usage:
290  /// xyzMatrix m(
291  /// xyzMatrix::cols_constructor( x_col_vector, y_col_vector, z_col_vector ) )
292  template< typename U >
293  inline
294  static
295  xyzMatrix
297  xyzVector< U > const & col_x,
298  xyzVector< U > const & col_y,
299  xyzVector< U > const & col_z
300  )
301  {
302  return xyzMatrix(
303  col_x.x_, col_y.x_, col_z.x_,
304  col_x.y_, col_y.y_, col_z.y_,
305  col_x.z_, col_y.z_, col_z.z_
306  );
307  }
308 
309 
310 public: // Creation: row values
311 
312 
313  /// @brief Row-ordered value named constructor
314  /// @note Constructor usage:
315  /// xyzMatrix m(
316  /// xyzMatrix::rows( xx_a, xy_a, xz_a, yx_a, yy_a, yz_a, zx_a, zy_a, zz_a ) )
317  /// @note Assignment usage:
318  /// m = xyzMatrix::rows( xx_a, xy_a, xz_a, yx_a, yy_a, yz_a, zx_a, zy_a, zz_a )
319  inline
320  static
321  xyzMatrix
323  Value const & xx_a, Value const & xy_a, Value const & xz_a,
324  Value const & yx_a, Value const & yy_a, Value const & yz_a,
325  Value const & zx_a, Value const & zy_a, Value const & zz_a
326  )
327  {
328  return xyzMatrix(
329  xx_a, xy_a, xz_a,
330  yx_a, yy_a, yz_a,
331  zx_a, zy_a, zz_a
332  );
333  }
334 
335 
336 public: // Creation: row pointers
337 
338 
339  /// @brief Pointer to contiguous row-ordered values constructor
340  /// @see rows
341  /// @note The rows named constructor/assignment provides a simple wrapper interface
342  /// @note Constructor usage: xyzMatrix m( xyzMatrix::rows( rows_pointer ) )
343  /// @note Assignment usage: m = xyzMatrix::rows( rows_pointer )
344  template< typename U >
345  inline
347  xx_( *(r.p_) ), xy_( *(r.p_+1) ), xz_( *(r.p_+2) ),
348  yx_( *(r.p_+3) ), yy_( *(r.p_+4) ), yz_( *(r.p_+5) ),
349  zx_( *(r.p_+6) ), zy_( *(r.p_+7) ), zz_( *(r.p_+8) )
350  {}
351 
352 
353  /// @brief Pointer to contiguous row-ordered values named constructor/assignment
354  /// @warning No way to check that argument points to nine contiguous values
355  /// @note Constructor usage: xyzMatrix m( xyzMatrix::rows( rows_pointer ) )
356  /// @note Assignment usage: m = xyzMatrix::rows( rows_pointer )
357  template< typename U >
358  inline
359  static
361  rows( U const * rp )
362  {
363  return RowsPointer< U >( rp );
364  }
365 
366 
367  /// @brief Pointers to contiguous rows constructor
368  /// @see rows
369  /// @note The rows named constructor/assignment provides a simple wrapper interface
370  /// @note Constructor usage:
371  /// xyzMatrix m( xyzMatrix::rows( x_row_pointer, y_row_pointer, z_row_pointer ) )
372  /// @note Assignment usage:
373  /// m = xyzMatrix::rows( x_row_pointer, y_row_pointer, z_row_pointer )
374  template< typename U >
375  inline
377  xx_( *r.xp_ ), xy_( *(r.xp_+1) ), xz_( *(r.xp_+2) ),
378  yx_( *r.yp_ ), yy_( *(r.yp_+1) ), yz_( *(r.yp_+2) ),
379  zx_( *r.zp_ ), zy_( *(r.zp_+1) ), zz_( *(r.zp_+2) )
380  {}
381 
382 
383  /// @brief Pointers to contiguous rows named constructor/assignment
384  /// @warning No way to check that arguments each point to three contiguous values
385  /// @note Constructor usage:
386  /// xyzMatrix m( xyzMatrix::rows( x_row_pointer, y_row_pointer, z_row_pointer ) )
387  /// @note Assignment usage:
388  /// m = xyzMatrix::rows( x_row_pointer, y_row_pointer, z_row_pointer )
389  template< typename U >
390  inline
391  static
394  U const * xp,
395  U const * yp,
396  U const * zp
397  )
398  {
399  return RowPointers< U >( xp, yp, zp );
400  }
401 
402 
403  /// @brief Pointers to contiguous rows named constructor
404  /// @warning No way to check that arguments each point to three contiguous values
405  /// @note Can be faster than rows() construction due to return value optimization
406  /// @note Constructor usage:
407  /// xyzMatrix m(
408  /// xyzMatrix::rows_constructor( x_row_pointer, y_row_pointer, z_row_pointer ) )
409  template< typename U >
410  inline
411  static
412  xyzMatrix
414  U const * xp,
415  U const * yp,
416  U const * zp
417  )
418  {
419  return xyzMatrix(
420  *xp, *(xp+1), *(xp+2),
421  *yp, *(yp+1), *(yp+2),
422  *zp, *(zp+1), *(zp+2)
423  );
424  }
425 
426 
427 public: // Creation: row xyzVectors
428 
429 
430  /// @brief Rows constructor
431  /// @see rows
432  /// @note The rows named constructor/assignment provides a simple wrapper interface
433  /// @note Constructor usage:
434  /// xyzMatrix m( xyzMatrix::rows( x_row_vector, y_row_vector, z_row_vector ) )
435  template< typename U >
436  inline
437  xyzMatrix( RowVectors< U > const & r ) :
438  xx_( r.x_.x_ ), xy_( r.x_.y_ ), xz_( r.x_.z_ ),
439  yx_( r.y_.x_ ), yy_( r.y_.y_ ), yz_( r.y_.z_ ),
440  zx_( r.z_.x_ ), zy_( r.z_.y_ ), zz_( r.z_.z_ )
441  {}
442 
443 
444  /// @brief Row vectors named constructor/assignment
445  /// @note Constructor usage:
446  /// xyzMatrix m( xyzMatrix::rows( x_row_vector, y_row_vector, z_row_vector ) )
447  /// @note Assignment usage:
448  /// m = xyzMatrix::rows( x_row_vector, y_row_vector, z_row_vector )
449  template< typename U >
450  inline
451  static
454  xyzVector< U > const & row_x,
455  xyzVector< U > const & row_y,
456  xyzVector< U > const & row_z
457  )
458  {
459  return RowVectors< U >( row_x, row_y, row_z );
460  }
461 
462 
463  /// @brief xyzVector rows named constructor
464  /// @note Can be faster than rows() construction due to return value optimization
465  /// @note Constructor usage:
466  /// xyzMatrix m(
467  /// xyzMatrix::rows_constructor( x_row_vector, y_row_vector, z_row_vector ) )
468  template< typename U >
469  inline
470  static
471  xyzMatrix
473  xyzVector< U > const & row_x,
474  xyzVector< U > const & row_y,
475  xyzVector< U > const & row_z
476  )
477  {
478  return xyzMatrix(
479  row_x.x_, row_x.y_, row_x.z_,
480  row_y.x_, row_y.y_, row_y.z_,
481  row_z.x_, row_z.y_, row_z.z_
482  );
483  }
484 
485 
486 public: // Creation: special constructors
487 
488 
489  /// @brief Diagonal value named constructor
490  /// @note diag refers to a diagonal matrix
491  inline
492  static
493  xyzMatrix
495  Value const & xx_a,
496  Value const & yy_a,
497  Value const & zz_a
498  )
499  {
500  return xyzMatrix(
501  xx_a, Value( 0 ), Value( 0 ),
502  Value( 0 ), yy_a, Value( 0 ),
503  Value( 0 ), Value( 0 ), zz_a
504  );
505  }
506 
507 
508  /// @brief Diagonal xyzVector named constructor
509  /// @note diag refers to a diagonal matrix
510  template< typename U >
511  inline
512  static
513  xyzMatrix
514  diag( xyzVector< U > const & diag_a )
515  {
516  return xyzMatrix(
517  diag_a.x_, Value( 0 ), Value( 0 ),
518  Value( 0 ), diag_a.y_, Value( 0 ),
519  Value( 0 ), Value( 0 ), diag_a.z_
520  );
521  }
522 
523 
524  /// @brief Identity xyzMatrix named constructor
525  /// @note Can be faster than I() for construction due to return value optimization
526  inline
527  static
528  xyzMatrix
530  {
531  return xyzMatrix(
532  Value( 1 ), Value( 0 ), Value( 0 ),
533  Value( 0 ), Value( 1 ), Value( 0 ),
534  Value( 0 ), Value( 0 ), Value( 1 )
535  );
536  }
537 
538 
539 private: // Creation
540 
541 
542  /// @brief Row-ordered value constructor
543  /// @note Client code uses named constructors that specify the value order explicitly
544  inline
546  Value const & xx_a, Value const & xy_a, Value const & xz_a,
547  Value const & yx_a, Value const & yy_a, Value const & yz_a,
548  Value const & zx_a, Value const & zy_a, Value const & zz_a
549  ) :
550  xx_( xx_a ), xy_( xy_a ), xz_( xz_a ),
551  yx_( yx_a ), yy_( yy_a ), yz_( yz_a ),
552  zx_( zx_a ), zy_( zy_a ), zz_( zz_a )
553  {}
554 
555 
556 public: // Assignment: xyzMatrix
557 
558 
559  /// @brief Copy assignment
560  inline
561  xyzMatrix &
562  operator =( xyzMatrix const & m )
563  {
564  if ( this != &m ) {
565  xx_ = m.xx_; xy_ = m.xy_; xz_ = m.xz_;
566  yx_ = m.yx_; yy_ = m.yy_; yz_ = m.yz_;
567  zx_ = m.zx_; zy_ = m.zy_; zz_ = m.zz_;
568  }
569  return *this;
570  }
571 
572 
573  /// @brief Copy assignment
574  template< typename U >
575  inline
576  xyzMatrix &
578  {
579  xx_ = m.xx_; xy_ = m.xy_; xz_ = m.xz_;
580  yx_ = m.yx_; yy_ = m.yy_; yz_ = m.yz_;
581  zx_ = m.zx_; zy_ = m.zy_; zz_ = m.zz_;
582  return *this;
583  }
584 
585 
586  /// @brief += xyzMatrix
587  template< typename U >
588  inline
589  xyzMatrix &
591  {
592  xx_ += m.xx_; xy_ += m.xy_; xz_ += m.xz_;
593  yx_ += m.yx_; yy_ += m.yy_; yz_ += m.yz_;
594  zx_ += m.zx_; zy_ += m.zy_; zz_ += m.zz_;
595  return *this;
596  }
597 
598 
599  /// @brief -= xyzMatrix
600  template< typename U >
601  inline
602  xyzMatrix &
604  {
605  xx_ -= m.xx_; xy_ -= m.xy_; xz_ -= m.xz_;
606  yx_ -= m.yx_; yy_ -= m.yy_; yz_ -= m.yz_;
607  zx_ -= m.zx_; zy_ -= m.zy_; zz_ -= m.zz_;
608  return *this;
609  }
610 
611 
612  /// @brief *= xyzMatrix
613  /// @note Same as right_multiply_by( xyzMatrix )
614  template< typename U >
615  inline
616  xyzMatrix &
618  {
619  Value x, y, z; // Temporaries
620 
621  // First row
622  x = ( xx_ * m.xx_ ) + ( xy_ * m.yx_ ) + ( xz_ * m.zx_ );
623  y = ( xx_ * m.xy_ ) + ( xy_ * m.yy_ ) + ( xz_ * m.zy_ );
624  z = ( xx_ * m.xz_ ) + ( xy_ * m.yz_ ) + ( xz_ * m.zz_ );
625  xx_ = x; xy_ = y; xz_ = z;
626 
627  // Second row
628  x = ( yx_ * m.xx_ ) + ( yy_ * m.yx_ ) + ( yz_ * m.zx_ );
629  y = ( yx_ * m.xy_ ) + ( yy_ * m.yy_ ) + ( yz_ * m.zy_ );
630  z = ( yx_ * m.xz_ ) + ( yy_ * m.yz_ ) + ( yz_ * m.zz_ );
631  yx_ = x; yy_ = y; yz_ = z;
632 
633  // Third row
634  x = ( zx_ * m.xx_ ) + ( zy_ * m.yx_ ) + ( zz_ * m.zx_ );
635  y = ( zx_ * m.xy_ ) + ( zy_ * m.yy_ ) + ( zz_ * m.zy_ );
636  z = ( zx_ * m.xz_ ) + ( zy_ * m.yz_ ) + ( zz_ * m.zz_ );
637  zx_ = x; zy_ = y; zz_ = z;
638 
639  return *this;
640  }
641 
642 
643 public: // Assignment: pointer
644 
645 
646  /// @brief Assignment from pointer to contiguous column-ordered values
647  /// @note Use via named assignment wrapper: m = xyzMatrix::cols( pointer )
648  template< typename U >
649  inline
650  xyzMatrix &
652  {
653  xx_ = *(c.p_); xy_ = *(c.p_+3); xz_ = *(c.p_+6);
654  yx_ = *(c.p_+1); yy_ = *(c.p_+4); yz_ = *(c.p_+7);
655  zx_ = *(c.p_+2); zy_ = *(c.p_+5); zz_ = *(c.p_+8);
656  return *this;
657  }
658 
659 
660  /// @brief Assignment from pointer to contiguous row-ordered values
661  /// @note Use via named assignment wrapper: m = xyzMatrix::rows( pointer )
662  template< typename U >
663  inline
664  xyzMatrix &
666  {
667  xx_ = *(r.p_); xy_ = *(r.p_+1); xz_ = *(r.p_+2);
668  yx_ = *(r.p_+3); yy_ = *(r.p_+4); yz_ = *(r.p_+5);
669  zx_ = *(r.p_+6); zy_ = *(r.p_+7); zz_ = *(r.p_+8);
670  return *this;
671  }
672 
673 
674  /// @brief Assignment from pointers to contiguous columns
675  /// @note Use via named assignment wrapper:
676  /// m = xyzMatrix::cols( pointer, pointer, pointer )
677  template< typename U >
678  inline
679  xyzMatrix &
681  {
682  xx_ = *c.xp_; xy_ = *c.yp_; xz_ = *c.zp_;
683  yx_ = *(c.xp_+1); yy_ = *(c.yp_+1); yz_ = *(c.zp_+1);
684  zx_ = *(c.xp_+2); zy_ = *(c.yp_+2); zz_ = *(c.zp_+2);
685  return *this;
686  }
687 
688 
689  /// @brief Assignment from pointers to contiguous rows
690  /// @note Use via named assignment wrapper:
691  /// m = xyzMatrix::rows( pointer, pointer, pointer )
692  template< typename U >
693  inline
694  xyzMatrix &
696  {
697  xx_ = *r.xp_; xy_ = *(r.xp_+1); xz_ = *(r.xp_+2);
698  yx_ = *r.yp_; yy_ = *(r.yp_+1); yz_ = *(r.yp_+2);
699  zx_ = *r.zp_; zy_ = *(r.zp_+1); zz_ = *(r.zp_+2);
700  return *this;
701  }
702 
703 
704 public: // Assignment: xyzVector
705 
706 
707  /// @brief xyzVector columns assignment
708  /// @note Use via named assignment wrapper:
709  /// m = xyzMatrix::cols( xyzVector, xyzVector, xyzVector )
710  template< typename U >
711  inline
712  xyzMatrix &
714  {
715  xx_ = c.x_.x_; xy_ = c.y_.x_; xz_ = c.z_.x_;
716  yx_ = c.x_.y_; yy_ = c.y_.y_; yz_ = c.z_.y_;
717  zx_ = c.x_.z_; zy_ = c.y_.z_; zz_ = c.z_.z_;
718  return *this;
719  }
720 
721 
722  /// @brief xyzVector rows assignment
723  /// @note Use via named assignment wrapper:
724  /// m = xyzMatrix::rows( xyzVector, xyzVector, xyzVector )
725  template< typename U >
726  inline
727  xyzMatrix &
729  {
730  xx_ = r.x_.x_; xy_ = r.x_.y_; xz_ = r.x_.z_;
731  yx_ = r.y_.x_; yy_ = r.y_.y_; yz_ = r.y_.z_;
732  zx_ = r.z_.x_; zy_ = r.z_.y_; zz_ = r.z_.z_;
733  return *this;
734  }
735 
736 
737 public: // Assignment: scalar
738 
739 
740  /// @brief = Value
741  inline
742  xyzMatrix &
743  operator =( Value const & t )
744  {
745  xx_ = xy_ = xz_ = t;
746  yx_ = yy_ = yz_ = t;
747  zx_ = zy_ = zz_ = t;
748  return *this;
749  }
750 
751 
752  /// @brief += Value
753  inline
754  xyzMatrix &
755  operator +=( Value const & t )
756  {
757  xx_ += t; xy_ += t; xz_ += t;
758  yx_ += t; yy_ += t; yz_ += t;
759  zx_ += t; zy_ += t; zz_ += t;
760  return *this;
761  }
762 
763 
764  /// @brief -= Value
765  inline
766  xyzMatrix &
767  operator -=( Value const & t )
768  {
769  xx_ -= t; xy_ -= t; xz_ -= t;
770  yx_ -= t; yy_ -= t; yz_ -= t;
771  zx_ -= t; zy_ -= t; zz_ -= t;
772  return *this;
773  }
774 
775 
776  /// @brief *= Value
777  inline
778  xyzMatrix &
779  operator *=( Value const & t )
780  {
781  xx_ *= t; xy_ *= t; xz_ *= t;
782  yx_ *= t; yy_ *= t; yz_ *= t;
783  zx_ *= t; zy_ *= t; zz_ *= t;
784  return *this;
785  }
786 
787 
788  /// @brief /= Value
789  inline
790  xyzMatrix &
791  operator /=( Value const & t )
792  {
793  assert( t != Value( 0 ) );
794  Value const inv_t( Value ( 1 ) / t );
795  xx_ *= inv_t; xy_ *= inv_t; xz_ *= inv_t;
796  yx_ *= inv_t; yy_ *= inv_t; yz_ *= inv_t;
797  zx_ *= inv_t; zy_ *= inv_t; zz_ *= inv_t;
798  return *this;
799  }
800 
801 
802 public: // Methods: basic mathematical
803 
804 
805  /// @brief xyzMatrix + xyzMatrix
806  friend
807  inline
808  xyzMatrix
809  operator +( xyzMatrix const & a, xyzMatrix const & b )
810  {
811  return xyzMatrix(
812  a.xx_ + b.xx_, a.xy_ + b.xy_, a.xz_ + b.xz_,
813  a.yx_ + b.yx_, a.yy_ + b.yy_, a.yz_ + b.yz_,
814  a.zx_ + b.zx_, a.zy_ + b.zy_, a.zz_ + b.zz_
815  );
816  }
817 
818 
819  /// @brief xyzMatrix + Value
820  friend
821  inline
822  xyzMatrix
823  operator +( xyzMatrix const & m, Value const & t )
824  {
825  return xyzMatrix(
826  m.xx_ + t, m.xy_ + t, m.xz_ + t,
827  m.yx_ + t, m.yy_ + t, m.yz_ + t,
828  m.zx_ + t, m.zy_ + t, m.zz_ + t
829  );
830  }
831 
832 
833  /// @brief Value + xyzMatrix
834  friend
835  inline
836  xyzMatrix
837  operator +( Value const & t, xyzMatrix const & m )
838  {
839  return xyzMatrix(
840  t + m.xx_, t + m.xy_, t + m.xz_,
841  t + m.yx_, t + m.yy_, t + m.yz_,
842  t + m.zx_, t + m.zy_, t + m.zz_
843  );
844  }
845 
846 
847  /// @brief xyzMatrix - xyzMatrix
848  friend
849  inline
850  xyzMatrix
851  operator -( xyzMatrix const & a, xyzMatrix const & b )
852  {
853  return xyzMatrix(
854  a.xx_ - b.xx_, a.xy_ - b.xy_, a.xz_ - b.xz_,
855  a.yx_ - b.yx_, a.yy_ - b.yy_, a.yz_ - b.yz_,
856  a.zx_ - b.zx_, a.zy_ - b.zy_, a.zz_ - b.zz_
857  );
858  }
859 
860 
861  /// @brief xyzMatrix - Value
862  friend
863  inline
864  xyzMatrix
865  operator -( xyzMatrix const & m, Value const & t )
866  {
867  return xyzMatrix(
868  m.xx_ - t, m.xy_ - t, m.xz_ - t,
869  m.yx_ - t, m.yy_ - t, m.yz_ - t,
870  m.zx_ - t, m.zy_ - t, m.zz_ - t
871  );
872  }
873 
874 
875  /// @brief Value - xyzMatrix
876  friend
877  inline
878  xyzMatrix
879  operator -( Value const & t, xyzMatrix const & m )
880  {
881  return xyzMatrix(
882  t - m.xx_, t - m.xy_, t - m.xz_,
883  t - m.yx_, t - m.yy_, t - m.yz_,
884  t - m.zx_, t - m.zy_, t - m.zz_
885  );
886  }
887 
888 
889  /// @brief xyzMatrix * xyzMatrix
890  friend
891  inline
892  xyzMatrix
893  operator *( xyzMatrix const & a, xyzMatrix const & b )
894  {
895  return xyzMatrix(
896  // First row
897  ( a.xx_ * b.xx_ ) + ( a.xy_ * b.yx_ ) + ( a.xz_ * b.zx_ ),
898  ( a.xx_ * b.xy_ ) + ( a.xy_ * b.yy_ ) + ( a.xz_ * b.zy_ ),
899  ( a.xx_ * b.xz_ ) + ( a.xy_ * b.yz_ ) + ( a.xz_ * b.zz_ ),
900 
901  // Second row
902  ( a.yx_ * b.xx_ ) + ( a.yy_ * b.yx_ ) + ( a.yz_ * b.zx_ ),
903  ( a.yx_ * b.xy_ ) + ( a.yy_ * b.yy_ ) + ( a.yz_ * b.zy_ ),
904  ( a.yx_ * b.xz_ ) + ( a.yy_ * b.yz_ ) + ( a.yz_ * b.zz_ ),
905 
906  // Third row
907  ( a.zx_ * b.xx_ ) + ( a.zy_ * b.yx_ ) + ( a.zz_ * b.zx_ ),
908  ( a.zx_ * b.xy_ ) + ( a.zy_ * b.yy_ ) + ( a.zz_ * b.zy_ ),
909  ( a.zx_ * b.xz_ ) + ( a.zy_ * b.yz_ ) + ( a.zz_ * b.zz_ )
910  );
911  }
912 
913 
914  /// @brief xyzMatrix * Value
915  friend
916  inline
917  xyzMatrix
918  operator *( xyzMatrix const & m, Value const & t )
919  {
920  return xyzMatrix(
921  m.xx_ * t, m.xy_ * t, m.xz_ * t,
922  m.yx_ * t, m.yy_ * t, m.yz_ * t,
923  m.zx_ * t, m.zy_ * t, m.zz_ * t
924  );
925  }
926 
927 
928  /// @brief Value * xyzMatrix
929  friend
930  inline
931  xyzMatrix
932  operator *( Value const & t, xyzMatrix const & m )
933  {
934  return xyzMatrix(
935  t * m.xx_, t * m.xy_, t * m.xz_,
936  t * m.yx_, t * m.yy_, t * m.yz_,
937  t * m.zx_, t * m.zy_, t * m.zz_
938  );
939  }
940 
941 
942  /// @brief xyzMatrix / Value
943  friend
944  inline
945  xyzMatrix
946  operator /( xyzMatrix const & m, Value const & t )
947  {
948  assert( t != Value( 0 ) );
949  Value const inv_t( Value( 1 ) / t );
950  return xyzMatrix(
951  m.xx_ * inv_t, m.xy_ * inv_t, m.xz_ * inv_t,
952  m.yx_ * inv_t, m.yy_ * inv_t, m.yz_ * inv_t,
953  m.zx_ * inv_t, m.zy_ * inv_t, m.zz_ * inv_t
954  );
955  }
956 
957 
958 public: // Methods: complex mathematical
959 
960 
961  /// @brief Clear
962  inline
963  xyzMatrix &
965  {
966  xx_ = xy_ = xz_ =
967  yx_ = yy_ = yz_ =
968  zx_ = zy_ = zz_ = Value( 0 );
969  return *this;
970  }
971 
972 
973  /// @brief Set to the zero xyzMatrix
974  inline
975  xyzMatrix &
977  {
978  xx_ = xy_ = xz_ =
979  yx_ = yy_ = yz_ =
980  zx_ = zy_ = zz_ = Value( 0 );
981  return *this;
982  }
983 
984 
985  /// @brief Set to the identity xyzMatrix
986  inline
987  xyzMatrix &
989  {
990  xx_ = yy_ = zz_ = Value( 1 );
991  xy_ = xz_ = yx_ = yz_ = zx_ = zy_ = Value( 0 );
992  return *this;
993  }
994 
995 
996  /// @brief Set to diagonal xyzMatrix from value
997  /// @note Resets the entire matrix (diag refers to a diagonal matrix)
998  inline
999  xyzMatrix &
1001  Value const & xx_a,
1002  Value const & yy_a,
1003  Value const & zz_a
1004  )
1005  {
1006  xx_ = xx_a;
1007  yy_ = yy_a;
1008  zz_ = zz_a;
1009  xy_ = xz_ = yx_ = yz_ = zx_ = zy_ = Value( 0 );
1010  return *this;
1011  }
1012 
1013 
1014  /// @brief Set to diagonal xyzMatrix from xyzVector
1015  /// @note Resets the entire matrix (diag refers to a diagonal matrix)
1016  template< typename U >
1017  inline
1018  xyzMatrix &
1019  to_diag( xyzVector< U > const & diag_a )
1020  {
1021  xx_ = diag_a.x_;
1022  yy_ = diag_a.y_;
1023  zz_ = diag_a.z_;
1024  xy_ = xz_ = yx_ = yz_ = zx_ = zy_ = Value( 0 );
1025  return *this;
1026  }
1027 
1028 
1029  /// @brief set diagonal of xyzMatrix from value
1030  /// @note Resets the diagonal of the matrix only (diagonal refers to diagonal
1031  /// entries of a matrix)
1032  inline
1033  xyzMatrix &
1035  Value const & xx_a,
1036  Value const & yy_a,
1037  Value const & zz_a
1038  )
1039  {
1040  xx_ = xx_a;
1041  yy_ = yy_a;
1042  zz_ = zz_a;
1043  return *this;
1044  }
1045 
1046 
1047  /// @brief Set diagonal of xyzMatrix from xyzVector
1048  /// @note Resets the diagonal of the matrix only (diagonal refers to diagonal
1049  // entries of a matrix)
1050  template< typename U >
1051  inline
1052  xyzMatrix &
1053  set_diagonal( xyzVector< U > const & diag_a )
1054  {
1055  xx_ = diag_a.x_;
1056  yy_ = diag_a.y_;
1057  zz_ = diag_a.z_;
1058  return *this;
1059  }
1060 
1061 
1062  /// @brief Add values to diagonal of xyzMatrix
1063  inline
1064  xyzMatrix &
1066  Value const & xx_a,
1067  Value const & yy_a,
1068  Value const & zz_a
1069  )
1070  {
1071  xx_ += xx_a;
1072  yy_ += yy_a;
1073  zz_ += zz_a;
1074  return *this;
1075  }
1076 
1077 
1078  /// @brief Add xyzVector to diagonal of xyzMatrix
1079  template< typename U >
1080  inline
1081  xyzMatrix &
1082  add_diagonal( xyzVector< U > const & diag_a )
1083  {
1084  xx_ += diag_a.x_;
1085  yy_ += diag_a.y_;
1086  zz_ += diag_a.z_;
1087  return *this;
1088  }
1089 
1090 
1091  /// @brief Subtract values from diagonal of xyzMatrix
1092  inline
1093  xyzMatrix &
1095  Value const & xx_a,
1096  Value const & yy_a,
1097  Value const & zz_a
1098  )
1099  {
1100  xx_ -= xx_a;
1101  yy_ -= yy_a;
1102  zz_ -= zz_a;
1103  return *this;
1104  }
1105 
1106 
1107  /// @brief Subtract xyzVector from diagonal of xyzMatrix
1108  template< typename U >
1109  inline
1110  xyzMatrix &
1112  {
1113  xx_ -= diag_a.x_;
1114  yy_ -= diag_a.y_;
1115  zz_ -= diag_a.z_;
1116  return *this;
1117  }
1118 
1119 
1120  /// @brief Transpose
1121  inline
1122  xyzMatrix &
1124  {
1125  Value temp = xy_;
1126  xy_ = yx_;
1127  yx_ = temp;
1128 
1129  temp = xz_;
1130  xz_ = zx_;
1131  zx_ = temp;
1132 
1133  temp = yz_;
1134  yz_ = zy_;
1135  zy_ = temp;
1136 
1137  return *this;
1138  }
1139 
1140 
1141  /// @brief Right multiply by xyzMatrix
1142  /// @note Same as *= xyzMatrix
1143  template< typename U >
1144  inline
1145  xyzMatrix &
1147  {
1148  Value x, y, z; // Temporaries
1149 
1150  // First row
1151  x = ( xx_ * m.xx_ ) + ( xy_ * m.yx_ ) + ( xz_ * m.zx_ );
1152  y = ( xx_ * m.xy_ ) + ( xy_ * m.yy_ ) + ( xz_ * m.zy_ );
1153  z = ( xx_ * m.xz_ ) + ( xy_ * m.yz_ ) + ( xz_ * m.zz_ );
1154  xx_ = x; xy_ = y; xz_ = z;
1155 
1156  // Second row
1157  x = ( yx_ * m.xx_ ) + ( yy_ * m.yx_ ) + ( yz_ * m.zx_ );
1158  y = ( yx_ * m.xy_ ) + ( yy_ * m.yy_ ) + ( yz_ * m.zy_ );
1159  z = ( yx_ * m.xz_ ) + ( yy_ * m.yz_ ) + ( yz_ * m.zz_ );
1160  yx_ = x; yy_ = y; yz_ = z;
1161 
1162  // Third row
1163  x = ( zx_ * m.xx_ ) + ( zy_ * m.yx_ ) + ( zz_ * m.zx_ );
1164  y = ( zx_ * m.xy_ ) + ( zy_ * m.yy_ ) + ( zz_ * m.zy_ );
1165  z = ( zx_ * m.xz_ ) + ( zy_ * m.yz_ ) + ( zz_ * m.zz_ );
1166  zx_ = x; zy_ = y; zz_ = z;
1167 
1168  return *this;
1169  }
1170 
1171 
1172  /// @brief Right multiply by transpose xyzMatrix
1173  template< typename U >
1174  inline
1175  xyzMatrix &
1177  {
1178  Value x, y, z; // Temporaries
1179 
1180  // First row
1181  x = ( xx_ * m.xx_ ) + ( xy_ * m.xy_ ) + ( xz_ * m.xz_ );
1182  y = ( xx_ * m.yx_ ) + ( xy_ * m.yy_ ) + ( xz_ * m.yz_ );
1183  z = ( xx_ * m.zx_ ) + ( xy_ * m.zy_ ) + ( xz_ * m.zz_ );
1184  xx_ = x; xy_ = y; xz_ = z;
1185 
1186  // Second row
1187  x = ( yx_ * m.xx_ ) + ( yy_ * m.xy_ ) + ( yz_ * m.xz_ );
1188  y = ( yx_ * m.yx_ ) + ( yy_ * m.yy_ ) + ( yz_ * m.yz_ );
1189  z = ( yx_ * m.zx_ ) + ( yy_ * m.zy_ ) + ( yz_ * m.zz_ );
1190  yx_ = x; yy_ = y; yz_ = z;
1191 
1192  // Third row
1193  x = ( zx_ * m.xx_ ) + ( zy_ * m.xy_ ) + ( zz_ * m.xz_ );
1194  y = ( zx_ * m.yx_ ) + ( zy_ * m.yy_ ) + ( zz_ * m.yz_ );
1195  z = ( zx_ * m.zx_ ) + ( zy_ * m.zy_ ) + ( zz_ * m.zz_ );
1196  zx_ = x; zy_ = y; zz_ = z;
1197 
1198  return *this;
1199  }
1200 
1201 
1202  /// @brief Left multiply by xyzMatrix
1203  template< typename U >
1204  inline
1205  xyzMatrix &
1207  {
1208  Value x, y, z; // Temporaries
1209 
1210  // First column
1211  x = ( m.xx_ * xx_ ) + ( m.xy_ * yx_ ) + ( m.xz_ * zx_ );
1212  y = ( m.yx_ * xx_ ) + ( m.yy_ * yx_ ) + ( m.yz_ * zx_ );
1213  z = ( m.zx_ * xx_ ) + ( m.zy_ * yx_ ) + ( m.zz_ * zx_ );
1214  xx_ = x; yx_ = y; zx_ = z;
1215 
1216  // Second column
1217  x = ( m.xx_ * xy_ ) + ( m.xy_ * yy_ ) + ( m.xz_ * zy_ );
1218  y = ( m.yx_ * xy_ ) + ( m.yy_ * yy_ ) + ( m.yz_ * zy_ );
1219  z = ( m.zx_ * xy_ ) + ( m.zy_ * yy_ ) + ( m.zz_ * zy_ );
1220  xy_ = x; yy_ = y; zy_ = z;
1221 
1222  // Third column
1223  x = ( m.xx_ * xz_ ) + ( m.xy_ * yz_ ) + ( m.xz_ * zz_ );
1224  y = ( m.yx_ * xz_ ) + ( m.yy_ * yz_ ) + ( m.yz_ * zz_ );
1225  z = ( m.zx_ * xz_ ) + ( m.zy_ * yz_ ) + ( m.zz_ * zz_ );
1226  xz_ = x; yz_ = y; zz_ = z;
1227 
1228  return *this;
1229  }
1230 
1231 
1232  /// @brief Left multiply by transpose xyzMatrix
1233  template< typename U >
1234  inline
1235  xyzMatrix &
1237  {
1238  Value x, y, z; // Temporaries
1239 
1240  // First column
1241  x = ( m.xx_ * xx_ ) + ( m.yx_ * yx_ ) + ( m.zx_ * zx_ );
1242  y = ( m.xy_ * xx_ ) + ( m.yy_ * yx_ ) + ( m.zy_ * zx_ );
1243  z = ( m.xz_ * xx_ ) + ( m.yz_ * yx_ ) + ( m.zz_ * zx_ );
1244  xx_ = x; yx_ = y; zx_ = z;
1245 
1246  // Second column
1247  x = ( m.xx_ * xy_ ) + ( m.yx_ * yy_ ) + ( m.zx_ * zy_ );
1248  y = ( m.xy_ * xy_ ) + ( m.yy_ * yy_ ) + ( m.zy_ * zy_ );
1249  z = ( m.xz_ * xy_ ) + ( m.yz_ * yy_ ) + ( m.zz_ * zy_ );
1250  xy_ = x; yy_ = y; zy_ = z;
1251 
1252  // Third column
1253  x = ( m.xx_ * xz_ ) + ( m.yx_ * yz_ ) + ( m.zx_ * zz_ );
1254  y = ( m.xy_ * xz_ ) + ( m.yy_ * yz_ ) + ( m.zy_ * zz_ );
1255  z = ( m.xz_ * xz_ ) + ( m.yz_ * yz_ ) + ( m.zz_ * zz_ );
1256  xz_ = x; yz_ = y; zz_ = z;
1257 
1258  return *this;
1259  }
1260 
1261 
1262  /// @brief Identity xyzMatrix for expressions
1263  /// @note identity() named constructor can be faster for construction
1264  /// @note Returns reference to function-local static object so can be used in
1265  /// construction of global objects
1266  inline
1267  static
1268  xyzMatrix const &
1269  I()
1270  {
1271  static xyzMatrix const I_(
1272  Value( 1 ), Value( 0 ), Value( 0 ),
1273  Value( 0 ), Value( 1 ), Value( 0 ),
1274  Value( 0 ), Value( 0 ), Value( 1 )
1275  );
1276 
1277  return I_;
1278  }
1279 
1280 
1281 public: // Properties: columns
1282 
1283 
1284  /// @brief Column x
1285  inline
1286  Vector
1287  col_x() const
1288  {
1289  return Vector( xx_, yx_, zx_ );
1290  }
1291 
1292 
1293  /// @brief Column x assignment
1294  inline
1295  xyzMatrix &
1296  col_x( Vector const & v )
1297  {
1298  xx_ = v.x_; yx_ = v.y_; zx_ = v.z_;
1299  return *this;
1300  }
1301 
1302 
1303  /// @brief Column y
1304  inline
1305  Vector
1306  col_y() const
1307  {
1308  return Vector( xy_, yy_, zy_ );
1309  }
1310 
1311 
1312  /// @brief Column y assignment
1313  inline
1314  xyzMatrix &
1315  col_y( Vector const & v )
1316  {
1317  xy_ = v.x_; yy_ = v.y_; zy_ = v.z_;
1318  return *this;
1319  }
1320 
1321 
1322  /// @brief Column z
1323  inline
1324  Vector
1325  col_z() const
1326  {
1327  return Vector( xz_, yz_, zz_ );
1328  }
1329 
1330 
1331  /// @brief Column z assignment
1332  inline
1333  xyzMatrix &
1334  col_z( Vector const & v)
1335  {
1336  xz_ = v.x_; yz_ = v.y_; zz_ = v.z_;
1337  return *this;
1338  }
1339 
1340 
1341  /// @brief Column( i ): 1-based index
1342  inline
1343  Vector
1344  col( int const i ) const
1345  {
1346  assert( ( i > 0 ) && ( i <= 3 ) );
1347  switch ( i ) {
1348  case 1 :
1349  return Vector( xx_, yx_, zx_ );
1350  case 2 :
1351  return Vector( xy_, yy_, zy_ );
1352  default : // Assume i == 3
1353  return Vector( xz_, yz_, zz_ );
1354  }
1355  }
1356 
1357 
1358  /// @brief Column( i, xyzVector ) assignment: 1-base index
1359  inline
1360  xyzMatrix &
1361  col( int const i, Vector const & v )
1362  {
1363  assert( ( i > 0 ) && ( i <= 3 ) );
1364  switch ( i ) {
1365  case 1 :
1366  xx_ = v.x_; yx_ = v.y_; zx_ = v.z_;
1367  break;
1368  case 2 :
1369  xy_ = v.x_; yy_ = v.y_; zy_ = v.z_;
1370  break;
1371  default : // Assume i == 3
1372  xz_ = v.x_; yz_ = v.y_; zz_ = v.z_;
1373  }
1374  return *this;
1375  }
1376 
1377 
1378 public: // Properties: rows
1379 
1380 
1381  /// @brief Row x
1382  inline
1383  Vector
1384  row_x() const
1385  {
1386  return Vector( xx_, xy_, xz_ );
1387  }
1388 
1389 
1390  /// @brief Row x assignment
1391  inline
1392  xyzMatrix &
1393  row_x( Vector const & v )
1394  {
1395  xx_ = v.x_; xy_ = v.y_; xz_ = v.z_;
1396  return *this;
1397  }
1398 
1399 
1400  /// @brief Row y
1401  inline
1402  Vector
1403  row_y() const
1404  {
1405  return Vector( yx_, yy_, yz_ );
1406  }
1407 
1408 
1409  /// @brief Row y assignment
1410  inline
1411  xyzMatrix &
1412  row_y( Vector const & v )
1413  {
1414  yx_ = v.x_; yy_ = v.y_; yz_ = v.z_;
1415  return *this;
1416  }
1417 
1418 
1419  /// @brief Row z
1420  inline
1421  Vector
1422  row_z() const
1423  {
1424  return Vector( zx_, zy_, zz_ );
1425  }
1426 
1427 
1428  /// @brief Row z assignment
1429  inline
1430  xyzMatrix &
1431  row_z( Vector const & v )
1432  {
1433  zx_ = v.x_; zy_ = v.y_; zz_ = v.z_;
1434  return *this;
1435  }
1436 
1437 
1438  /// @brief Row ( i ): 1-based index
1439  inline
1440  Vector
1441  row( int const i ) const
1442  {
1443  assert( ( i > 0 ) && ( i <= 3 ) );
1444  switch ( i ) {
1445  case 1 :
1446  return Vector( xx_, xy_, xz_ );
1447  case 2 :
1448  return Vector( yx_, yy_, yz_ );
1449  default : // Assume i == 3
1450  return Vector( zx_, zy_, zz_ );
1451  }
1452  }
1453 
1454 
1455  /// @brief Row ( i, xyzVector ) assignment: 1-based index
1456  inline
1457  xyzMatrix &
1458  row( int const i, Vector const & v )
1459  {
1460  assert( ( i > 0 ) && ( i <= 3 ) );
1461  switch ( i ) {
1462  case 1 :
1463  xx_ = v.x_; xy_ = v.y_; xz_ = v.z_;
1464  case 2 :
1465  yx_ = v.x_; yy_ = v.y_; yz_ = v.z_;
1466  default : // Assume i == 3
1467  zx_ = v.x_; zy_ = v.y_; zz_ = v.z_;
1468  }
1469  return *this;
1470  }
1471 
1472 
1473 public: // Properties: scalars
1474 
1475 
1476  /// @brief Value xx const
1477  inline
1478  Value const &
1479  xx() const
1480  {
1481  return xx_;
1482  }
1483 
1484 
1485  /// @brief Value xx
1486  inline
1487  Value &
1488  xx()
1489  {
1490  return xx_;
1491  }
1492 
1493 
1494  /// @brief Value xy const
1495  inline
1496  Value const &
1497  xy() const
1498  {
1499  return xy_;
1500  }
1501 
1502 
1503  /// @brief Value xy
1504  inline
1505  Value &
1506  xy()
1507  {
1508  return xy_;
1509  }
1510 
1511 
1512  /// @brief Value xz const
1513  inline
1514  Value const &
1515  xz() const
1516  {
1517  return xz_;
1518  }
1519 
1520 
1521  /// @brief Value xz
1522  inline
1523  Value &
1524  xz()
1525  {
1526  return xz_;
1527  }
1528 
1529 
1530  /// @brief Value yx const
1531  inline
1532  Value const &
1533  yx() const
1534  {
1535  return yx_;
1536  }
1537 
1538 
1539  /// @brief Value yx
1540  inline
1541  Value &
1542  yx()
1543  {
1544  return yx_;
1545  }
1546 
1547 
1548  /// @brief Value yy const
1549  inline
1550  Value const &
1551  yy() const
1552  {
1553  return yy_;
1554  }
1555 
1556 
1557  /// @brief Value yy
1558  inline
1559  Value &
1560  yy()
1561  {
1562  return yy_;
1563  }
1564 
1565 
1566  /// @brief Value yz const
1567  inline
1568  Value const &
1569  yz() const
1570  {
1571  return yz_;
1572  }
1573 
1574 
1575  /// @brief Value yz
1576  inline
1577  Value &
1578  yz()
1579  {
1580  return yz_;
1581  }
1582 
1583 
1584  /// @brief Value zx const
1585  inline
1586  Value const &
1587  zx() const
1588  {
1589  return zx_;
1590  }
1591 
1592 
1593  /// @brief Value zx
1594  inline
1595  Value &
1596  zx()
1597  {
1598  return zx_;
1599  }
1600 
1601 
1602  /// @brief Value zy const
1603  inline
1604  Value const &
1605  zy() const
1606  {
1607  return zy_;
1608  }
1609 
1610 
1611  /// @brief Value zy
1612  inline
1613  Value &
1614  zy()
1615  {
1616  return zy_;
1617  }
1618 
1619 
1620  /// @brief Value zz const
1621  inline
1622  Value const &
1623  zz() const
1624  {
1625  return zz_;
1626  }
1627 
1628 
1629  /// @brief Value zz
1630  inline
1631  Value &
1632  zz()
1633  {
1634  return zz_;
1635  }
1636 
1637 
1638  /// @brief xyzMatrix( i, j ) const: 1-based index
1639  inline
1640  Value const &
1641  operator ()( int const i, int const j ) const
1642  {
1643  assert( ( i > 0 ) && ( i <= 3 ) );
1644  assert( ( j > 0 ) && ( j <= 3 ) );
1645  switch ( i ) {
1646  case 1 :
1647  return ( j == 1 ? xx_ : ( j == 2 ? xy_ : xz_ ) );
1648  case 2 :
1649  return ( j == 1 ? yx_ : ( j == 2 ? yy_ : yz_ ) );
1650  default : // Assume i == 3
1651  return ( j == 1 ? zx_ : ( j == 2 ? zy_ : zz_ ) );
1652  }
1653  }
1654 
1655 
1656  /// @brief xyzMatrix( i, j ): 1-based index
1657  inline
1658  Value &
1659  operator ()( int const i, int const j )
1660  {
1661  assert( ( i > 0 ) && ( i <= 3 ) );
1662  assert( ( j > 0 ) && ( j <= 3 ) );
1663  switch ( i ) {
1664  case 1 :
1665  return ( j == 1 ? xx_ : ( j == 2 ? xy_ : xz_ ) );
1666  case 2 :
1667  return ( j == 1 ? yx_ : ( j == 2 ? yy_ : yz_ ) );
1668  default : // Assume i == 3
1669  return ( j == 1 ? zx_ : ( j == 2 ? zy_ : zz_ ) );
1670  }
1671  }
1672 
1673 
1674 public: // Properties: value assignment
1675 
1676 
1677  /// @brief xx assignment
1678  inline
1679  void
1680  xx( Value const & xx_a )
1681  {
1682  xx_ = xx_a;
1683  }
1684 
1685 
1686  /// @brief xy assignment
1687  inline
1688  void
1689  xy( Value const & xy_a )
1690  {
1691  xy_ = xy_a;
1692  }
1693 
1694 
1695  /// @brief xz assignment
1696  inline
1697  void
1698  xz( Value const & xz_a )
1699  {
1700  xz_ = xz_a;
1701  }
1702 
1703 
1704  /// @brief yx assignment
1705  inline
1706  void
1707  yx( Value const & yx_a )
1708  {
1709  yx_ = yx_a;
1710  }
1711 
1712 
1713  /// @brief yy assignment
1714  inline
1715  void
1716  yy( Value const & yy_a )
1717  {
1718  yy_ = yy_a;
1719  }
1720 
1721 
1722  /// @brief yz assignment
1723  inline
1724  void
1725  yz( Value const & yz_a )
1726  {
1727  yz_ = yz_a;
1728  }
1729 
1730 
1731  /// @brief zx assignment
1732  inline
1733  void
1734  zx( Value const & zx_a )
1735  {
1736  zx_ = zx_a;
1737  }
1738 
1739 
1740  /// @brief zy assignment
1741  inline
1742  void
1743  zy( Value const & zy_a )
1744  {
1745  zy_ = zy_a;
1746  }
1747 
1748 
1749  /// @brief zz assignment
1750  inline
1751  void
1752  zz( Value const & zz_a )
1753  {
1754  zz_ = zz_a;
1755  }
1756 
1757 
1758 public: // Properties: predicates
1759 
1760 
1761  /// @brief Is zero?
1762  inline
1763  bool
1764  is_zero() const
1765  {
1766  static Value const ZERO( 0 );
1767  return
1768  ( xx_ == ZERO ) && ( xy_ == ZERO ) && ( xz_ == ZERO ) &&
1769  ( yx_ == ZERO ) && ( yy_ == ZERO ) && ( yz_ == ZERO ) &&
1770  ( zx_ == ZERO ) && ( zy_ == ZERO ) && ( zz_ == ZERO );
1771  }
1772 
1773 
1774  /// @brief Is identity?
1775  inline
1776  bool
1777  is_identity() const
1778  {
1779  static Value const ZERO( 0 );
1780  static Value const ONE( 1 );
1781  return
1782  ( xx_ == ONE ) && ( xy_ == ZERO ) && ( xz_ == ZERO ) &&
1783  ( yx_ == ZERO ) && ( yy_ == ONE ) && ( yz_ == ZERO ) &&
1784  ( zx_ == ZERO ) && ( zy_ == ZERO ) && ( zz_ == ONE );
1785  }
1786 
1787 
1788 public: // Properties: calculated
1789 
1790 
1791  /// @brief Determinant
1792  inline
1793  Value
1794  det() const
1795  {
1796  return
1797  xx_ * ( ( yy_ * zz_ ) - ( zy_ * yz_ ) ) -
1798  xy_ * ( ( yx_ * zz_ ) - ( zx_ * yz_ ) ) +
1799  xz_ * ( ( yx_ * zy_ ) - ( zx_ * yy_ ) );
1800  }
1801 
1802  /// @brief Trace
1803  inline
1804  Value
1805  trace() const
1806  {
1807  return xx_ + yy_ + zz_;
1808  }
1809 
1810 
1811  /// @brief Transposed copy
1812  inline
1813  xyzMatrix
1814  transposed() const
1815  {
1816  return xyzMatrix(
1817  xx_, yx_, zx_,
1818  xy_, yy_, zy_,
1819  xz_, yz_, zz_
1820  );
1821  }
1822 
1823  // Adding member version so we can use M.inverse in PyRosetta
1824  inline
1826  inverse() const {
1827  xyzMatrix const & a(*this);
1828  T D = a.det();
1829  return xyzMatrix< T >(
1830  (a.yy_*a.zz_-a.yz_*a.zy_)/D, -(a.xy_*a.zz_-a.xz_*a.zy_)/D, (a.xy_*a.yz_-a.xz_*a.yy_)/D,
1831  -(a.yx_*a.zz_-a.zx_*a.yz_)/D, (a.xx_*a.zz_-a.xz_*a.zx_)/D, -(a.xx_*a.yz_-a.xz_*a.yx_)/D,
1832  (a.yx_*a.zy_-a.zx_*a.yy_)/D, -(a.xx_*a.zy_-a.xy_*a.zx_)/D, (a.xx_*a.yy_-a.xy_*a.yx_)/D
1833  );
1834  }
1835 
1836 public: // Comparison
1837 
1838 
1839  /// @brief xyzMatrix == xyzMatrix
1840  friend
1841  inline
1842  bool
1843  operator ==( xyzMatrix const & a, xyzMatrix const & b )
1844  {
1845  return
1846  ( a.xx_ == b.xx_ ) && ( a.xy_ == b.xy_ ) && ( a.xz_ == b.xz_ ) &&
1847  ( a.yx_ == b.yx_ ) && ( a.yy_ == b.yy_ ) && ( a.yz_ == b.yz_ ) &&
1848  ( a.zx_ == b.zx_ ) && ( a.zy_ == b.zy_ ) && ( a.zz_ == b.zz_ );
1849  }
1850 
1851 
1852  /// @brief xyzMatrix != xyzMatrix
1853  friend
1854  inline
1855  bool
1856  operator !=( xyzMatrix const & a, xyzMatrix const & b )
1857  {
1858  return !( a == b );
1859  }
1860 
1861 
1862  /// @brief xyzMatrix < xyzMatrix
1863  friend
1864  inline
1865  bool
1866  operator <( xyzMatrix const & a, xyzMatrix const & b )
1867  {
1868  return
1869  ( a.xx_ < b.xx_ ) && ( a.xy_ < b.xy_ ) && ( a.xz_ < b.xz_ ) &&
1870  ( a.yx_ < b.yx_ ) && ( a.yy_ < b.yy_ ) && ( a.yz_ < b.yz_ ) &&
1871  ( a.zx_ < b.zx_ ) && ( a.zy_ < b.zy_ ) && ( a.zz_ < b.zz_ );
1872  }
1873 
1874 
1875  /// @brief xyzMatrix <= xyzMatrix
1876  friend
1877  inline
1878  bool
1879  operator <=( xyzMatrix const & a, xyzMatrix const & b )
1880  {
1881  return
1882  ( a.xx_ <= b.xx_ ) && ( a.xy_ <= b.xy_ ) && ( a.xz_ <= b.xz_ ) &&
1883  ( a.yx_ <= b.yx_ ) && ( a.yy_ <= b.yy_ ) && ( a.yz_ <= b.yz_ ) &&
1884  ( a.zx_ <= b.zx_ ) && ( a.zy_ <= b.zy_ ) && ( a.zz_ <= b.zz_ );
1885  }
1886 
1887 
1888  /// @brief xyzMatrix >= xyzMatrix
1889  friend
1890  inline
1891  bool
1892  operator >=( xyzMatrix const & a, xyzMatrix const & b )
1893  {
1894  return
1895  ( a.xx_ >= b.xx_ ) && ( a.xy_ >= b.xy_ ) && ( a.xz_ >= b.xz_ ) &&
1896  ( a.yx_ >= b.yx_ ) && ( a.yy_ >= b.yy_ ) && ( a.yz_ >= b.yz_ ) &&
1897  ( a.zx_ >= b.zx_ ) && ( a.zy_ >= b.zy_ ) && ( a.zz_ >= b.zz_ );
1898  }
1899 
1900 
1901  /// @brief xyzMatrix > xyzMatrix
1902  friend
1903  inline
1904  bool
1905  operator >( xyzMatrix const & a, xyzMatrix const & b )
1906  {
1907  return
1908  ( a.xx_ > b.xx_ ) && ( a.xy_ > b.xy_ ) && ( a.xz_ > b.xz_ ) &&
1909  ( a.yx_ > b.yx_ ) && ( a.yy_ > b.yy_ ) && ( a.yz_ > b.yz_ ) &&
1910  ( a.zx_ > b.zx_ ) && ( a.zy_ > b.zy_ ) && ( a.zz_ > b.zz_ );
1911  }
1912 
1913 
1914  /// @brief xyzMatrix == Value
1915  friend
1916  inline
1917  bool
1918  operator ==( xyzMatrix const & m, Value const & t )
1919  {
1920  return
1921  ( m.xx_ == t ) && ( m.xy_ == t ) && ( m.xz_ == t ) &&
1922  ( m.yx_ == t ) && ( m.yy_ == t ) && ( m.yz_ == t ) &&
1923  ( m.zx_ == t ) && ( m.zy_ == t ) && ( m.zz_ == t );
1924  }
1925 
1926 
1927  /// @brief xyzMatrix != Value
1928  friend
1929  inline
1930  bool
1931  operator !=( xyzMatrix const & m, Value const & t )
1932  {
1933  return !( m == t );
1934  }
1935 
1936 
1937  /// @brief xyzMatrix < Value
1938  friend
1939  inline
1940  bool
1941  operator <( xyzMatrix const & m, Value const & t )
1942  {
1943  return
1944  ( m.xx_ < t ) && ( m.xy_ < t ) && ( m.xz_ < t ) &&
1945  ( m.yx_ < t ) && ( m.yy_ < t ) && ( m.yz_ < t ) &&
1946  ( m.zx_ < t ) && ( m.zy_ < t ) && ( m.zz_ < t );
1947  }
1948 
1949 
1950  /// @brief xyzMatrix <= Value
1951  friend
1952  inline
1953  bool
1954  operator <=( xyzMatrix const & m, Value const & t )
1955  {
1956  return
1957  ( m.xx_ <= t ) && ( m.xy_ <= t ) && ( m.xz_ <= t ) &&
1958  ( m.yx_ <= t ) && ( m.yy_ <= t ) && ( m.yz_ <= t ) &&
1959  ( m.zx_ <= t ) && ( m.zy_ <= t ) && ( m.zz_ <= t );
1960  }
1961 
1962 
1963  /// @brief xyzMatrix >= Value
1964  friend
1965  inline
1966  bool
1967  operator >=( xyzMatrix const & m, Value const & t )
1968  {
1969  return
1970  ( m.xx_ >= t ) && ( m.xy_ >= t ) && ( m.xz_ >= t ) &&
1971  ( m.yx_ >= t ) && ( m.yy_ >= t ) && ( m.yz_ >= t ) &&
1972  ( m.zx_ >= t ) && ( m.zy_ >= t ) && ( m.zz_ >= t );
1973  }
1974 
1975 
1976  /// @brief xyzMatrix > Value
1977  friend
1978  inline
1979  bool
1980  operator >( xyzMatrix const & m, Value const & t )
1981  {
1982  return
1983  ( m.xx_ > t ) && ( m.xy_ > t ) && ( m.xz_ > t ) &&
1984  ( m.yx_ > t ) && ( m.yy_ > t ) && ( m.yz_ > t ) &&
1985  ( m.zx_ > t ) && ( m.zy_ > t ) && ( m.zz_ > t );
1986  }
1987 
1988 
1989  /// @brief Value == xyzMatrix
1990  friend
1991  inline
1992  bool
1993  operator ==( Value const & t, xyzMatrix const & m )
1994  {
1995  return
1996  ( t == m.xx_ ) && ( t == m.xy_ ) && ( t == m.xz_ ) &&
1997  ( t == m.yx_ ) && ( t == m.yy_ ) && ( t == m.yz_ ) &&
1998  ( t == m.zx_ ) && ( t == m.zy_ ) && ( t == m.zz_ );
1999  }
2000 
2001 
2002  /// @brief Value != xyzMatrix
2003  friend
2004  inline
2005  bool
2006  operator !=( Value const & t, xyzMatrix const & m )
2007  {
2008  return !( t == m );
2009  }
2010 
2011 
2012  /// @brief Value < xyzMatrix
2013  friend
2014  inline
2015  bool
2016  operator <( Value const & t, xyzMatrix const & m )
2017  {
2018  return
2019  ( t < m.xx_ ) && ( t < m.xy_ ) && ( t < m.xz_ ) &&
2020  ( t < m.yx_ ) && ( t < m.yy_ ) && ( t < m.yz_ ) &&
2021  ( t < m.zx_ ) && ( t < m.zy_ ) && ( t < m.zz_ );
2022  }
2023 
2024 
2025  /// @brief Value <= xyzMatrix
2026  friend
2027  inline
2028  bool
2029  operator <=( Value const & t, xyzMatrix const & m )
2030  {
2031  return
2032  ( t <= m.xx_ ) && ( t <= m.xy_ ) && ( t <= m.xz_ ) &&
2033  ( t <= m.yx_ ) && ( t <= m.yy_ ) && ( t <= m.yz_ ) &&
2034  ( t <= m.zx_ ) && ( t <= m.zy_ ) && ( t <= m.zz_ );
2035  }
2036 
2037 
2038  /// @brief Value >= xyzMatrix
2039  friend
2040  inline
2041  bool
2042  operator >=( Value const & t, xyzMatrix const & m )
2043  {
2044  return
2045  ( t >= m.xx_ ) && ( t >= m.xy_ ) && ( t >= m.xz_ ) &&
2046  ( t >= m.yx_ ) && ( t >= m.yy_ ) && ( t >= m.yz_ ) &&
2047  ( t >= m.zx_ ) && ( t >= m.zy_ ) && ( t >= m.zz_ );
2048  }
2049 
2050 
2051  /// @brief Value > xyzMatrix
2052  friend
2053  inline
2054  bool
2055  operator >( Value const & t, xyzMatrix const & m )
2056  {
2057  return
2058  ( t > m.xx_ ) && ( t > m.xy_ ) && ( t > m.xz_ ) &&
2059  ( t > m.yx_ ) && ( t > m.yy_ ) && ( t > m.yz_ ) &&
2060  ( t > m.zx_ ) && ( t > m.zy_ ) && ( t > m.zz_ );
2061  }
2062 
2063  /// @brief Show
2064  inline
2065  void
2066  show(std::ostream & output=std::cout) const
2067  {
2068  output << "(" << xx_ << ", " << xy_ << ", " << xz_ << ")" << std::endl;
2069  output << "(" << yx_ << ", " << yy_ << ", " << yz_ << ")" << std::endl;
2070  output << "(" << zx_ << ", " << zy_ << ", " << zz_ << ")" << std::endl;
2071  }
2072 
2073 
2074 private: // Fields
2075 
2076 
2077  /// @brief Elements of the 3x3 matrix
2081 
2082 
2083 }; // xyzMatrix
2084 
2085 
2086 /// @brief xyzMatrix + xyzMatrix
2087 template< typename T >
2089 operator +( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2090 
2091 
2092 /// @brief xyzMatrix + T
2093 template< typename T >
2095 operator +( xyzMatrix< T > const & m, T const & t );
2096 
2097 
2098 /// @brief T + xyzMatrix
2099 template< typename T >
2101 operator +( T const & t, xyzMatrix< T > const & m );
2102 
2103 
2104 /// @brief xyzMatrix - xyzMatrix
2105 template< typename T >
2107 operator -( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2108 
2109 
2110 /// @brief xyzMatrix - T
2111 template< typename T >
2113 operator -( xyzMatrix< T > const & m, T const & t );
2114 
2115 
2116 /// @brief T - xyzMatrix
2117 template< typename T >
2119 operator -( T const & t, xyzMatrix< T > const & m );
2120 
2121 
2122 /// @brief xyzMatrix * xyzMatrix
2123 template< typename T >
2125 operator *( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2126 
2127 
2128 /// @brief xyzMatrix * T
2129 template< typename T >
2131 operator *( xyzMatrix< T > const & m, T const & t );
2132 
2133 
2134 /// @brief T * xyzMatrix
2135 template< typename T >
2137 operator *( T const & t, xyzMatrix< T > const & m );
2138 
2139 
2140 /// @brief xyzMatrix / T
2141 template< typename T >
2143 operator /( xyzMatrix< T > const & m, T const & t );
2144 
2145 
2146 /// @brief xyzMatrix == xyzMatrix
2147 template< typename T >
2148 bool
2149 operator ==( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2150 
2151 
2152 /// @brief xyzMatrix != xyzMatrix
2153 template< typename T >
2154 bool
2155 operator !=( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2156 
2157 
2158 /// @brief xyzMatrix < xyzMatrix
2159 template< typename T >
2160 bool
2161 operator <( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2162 
2163 
2164 /// @brief xyzMatrix <= xyzMatrix
2165 template< typename T >
2166 bool
2167 operator <=( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2168 
2169 
2170 /// @brief xyzMatrix >= xyzMatrix
2171 template< typename T >
2172 bool
2173 operator >=( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2174 
2175 
2176 /// @brief xyzMatrix > xyzMatrix
2177 template< typename T >
2178 bool
2179 operator >( xyzMatrix< T > const & a, xyzMatrix< T > const & b );
2180 
2181 
2182 /// @brief xyzMatrix == T
2183 template< typename T >
2184 bool
2185 operator ==( xyzMatrix< T > const & m, T const & t );
2186 
2187 
2188 /// @brief xyzMatrix != T
2189 template< typename T >
2190 bool
2191 operator !=( xyzMatrix< T > const & m, T const & t );
2192 
2193 
2194 /// @brief xyzMatrix < T
2195 template< typename T >
2196 bool
2197 operator <( xyzMatrix< T > const & m, T const & t );
2198 
2199 
2200 /// @brief xyzMatrix <= T
2201 template< typename T >
2202 bool
2203 operator <=( xyzMatrix< T > const & m, T const & t );
2204 
2205 
2206 /// @brief xyzMatrix >= T
2207 template< typename T >
2208 bool
2209 operator >=( xyzMatrix< T > const & m, T const & t );
2210 
2211 
2212 /// @brief xyzMatrix > T
2213 template< typename T >
2214 bool
2215 operator >( xyzMatrix< T > const & m, T const & t );
2216 
2217 
2218 /// @brief T == xyzMatrix
2219 template< typename T >
2220 bool
2221 operator ==( T const & t, xyzMatrix< T > const & m );
2222 
2223 
2224 /// @brief T != xyzMatrix
2225 template< typename T >
2226 bool
2227 operator !=( T const & t, xyzMatrix< T > const & m );
2228 
2229 
2230 /// @brief T < xyzMatrix
2231 template< typename T >
2232 bool
2233 operator <( T const & t, xyzMatrix< T > const & m );
2234 
2235 
2236 /// @brief T <= xyzMatrix
2237 template< typename T >
2238 bool
2239 operator <=( T const & t, xyzMatrix< T > const & m );
2240 
2241 
2242 /// @brief T >= xyzMatrix
2243 template< typename T >
2244 bool
2245 operator >=( T const & t, xyzMatrix< T > const & m );
2246 
2247 
2248 /// @brief T > xyzMatrix
2249 template< typename T >
2250 bool
2251 operator >( T const & t, xyzMatrix< T > const & m );
2252 
2253 
2254 /// @brief xyzMatrix * xyzVector
2255 /// @note Same as product( xyzMatrix, xyzVector )
2256 template< typename T >
2257 inline
2260 {
2261  return xyzVector< T >(
2262  m.xx_ * v.x_ + m.xy_ * v.y_ + m.xz_ * v.z_,
2263  m.yx_ * v.x_ + m.yy_ * v.y_ + m.yz_ * v.z_,
2264  m.zx_ * v.x_ + m.zy_ * v.y_ + m.zz_ * v.z_
2265  );
2266 }
2267 
2268 
2269 // PyRosetta work around for templates classes
2270 //class xyzMatrix_Double : public xyzMatrix< double >
2271 //{};
2272 
2273 } // namespace numeric
2274 
2275 
2276 #endif // INCLUDED_numeric_xyzMatrix_HH
3x3 matrix row pointers wrapper class
xyzMatrix(ColVectors< U > const &c)
Columns constructor.
Definition: xyzMatrix.hh:261
void yz(Value const &yz_a)
yz assignment
Definition: xyzMatrix.hh:1725
xyzVector< T > const & x_
x column
Definition: ColVectors.hh:89
xyzMatrix & row(int const i, Vector const &v)
Row ( i, xyzVector ) assignment: 1-based index.
Definition: xyzMatrix.hh:1458
xyzMatrix(ColPointers< U > const &c)
Pointers to contiguous columns constructor.
Definition: xyzMatrix.hh:200
static xyzMatrix rows_constructor(xyzVector< U > const &row_x, xyzVector< U > const &row_y, xyzVector< U > const &row_z)
xyzVector rows named constructor
Definition: xyzMatrix.hh:472
T const * const_pointer
Definition: xyzMatrix.hh:86
xyzVector< T > Vector
Definition: xyzMatrix.hh:79
xyzMatrix & set_diagonal(xyzVector< U > const &diag_a)
Set diagonal of xyzMatrix from xyzVector.
Definition: xyzMatrix.hh:1053
bool operator==(BodyPosition< T > const &p1, BodyPosition< T > const &p2)
BodyPosition == BodyPosition.
xyzMatrix(ColsPointer< U > const &c)
Pointer to contiguous column-ordered values constructor.
Definition: xyzMatrix.hh:170
xyzMatrix(Value const &xx_a, Value const &xy_a, Value const &xz_a, Value const &yx_a, Value const &yy_a, Value const &yz_a, Value const &zx_a, Value const &zy_a, Value const &zz_a)
Row-ordered value constructor.
Definition: xyzMatrix.hh:545
T const * yp_
Pointer (non-owning) to y row.
Definition: RowPointers.hh:92
xyzMatrix & transpose()
Transpose.
Definition: xyzMatrix.hh:1123
xyzMatrix & subtract_diagonal(Value const &xx_a, Value const &yy_a, Value const &zz_a)
Subtract values from diagonal of xyzMatrix.
Definition: xyzMatrix.hh:1094
3x3 matrix column vectors wrapper class
friend xyzVector< T > operator*(xyzMatrix< T > const &m, xyzVector< T > const &v)
xyzMatrix * xyzVector
Definition: xyzMatrix.hh:2259
xyzMatrix & add_diagonal(xyzVector< U > const &diag_a)
Add xyzVector to diagonal of xyzMatrix.
Definition: xyzMatrix.hh:1082
friend bool operator==(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix == xyzMatrix
Definition: xyzMatrix.hh:1843
Value & xy()
Value xy.
Definition: xyzMatrix.hh:1506
static xyzMatrix cols_constructor(xyzVector< U > const &col_x, xyzVector< U > const &col_y, xyzVector< U > const &col_z)
xyzVector columns named constructor
Definition: xyzMatrix.hh:296
Value const & zz() const
Value zz const.
Definition: xyzMatrix.hh:1623
Value & xz()
Value xz.
Definition: xyzMatrix.hh:1524
~xyzMatrix()
Destructor.
Definition: xyzMatrix.hh:130
Value det() const
Determinant.
Definition: xyzMatrix.hh:1794
Vector row_x() const
Row x.
Definition: xyzMatrix.hh:1384
xyzVector< T > const & y_
y row
Definition: RowVectors.hh:92
xyzMatrix & to_diag(Value const &xx_a, Value const &yy_a, Value const &zz_a)
Set to diagonal xyzMatrix from value.
Definition: xyzMatrix.hh:1000
Vector col_y() const
Column y.
Definition: xyzMatrix.hh:1306
static xyzMatrix rows(Value const &xx_a, Value const &xy_a, Value const &xz_a, Value const &yx_a, Value const &yy_a, Value const &yz_a, Value const &zx_a, Value const &zy_a, Value const &zz_a)
Row-ordered value named constructor.
Definition: xyzMatrix.hh:322
T const * xp_
Pointer (non-owning) to x column.
Definition: ColPointers.hh:89
static xyzMatrix diag(xyzVector< U > const &diag_a)
Diagonal xyzVector named constructor.
Definition: xyzMatrix.hh:514
xyzMatrix & operator*=(xyzMatrix< U > const &m)
*= xyzMatrix
Definition: xyzMatrix.hh:617
Value x_
Coordinates of the 3 coordinate vector.
Definition: xyzVector.hh:2062
xyzMatrix & operator=(xyzMatrix const &m)
Copy assignment.
Definition: xyzMatrix.hh:562
xyzMatrix & clear()
Clear.
Definition: xyzMatrix.hh:964
MathMatrix< T > operator*(const MathMatrix< T > &MATRIX_LHS, const MathMatrix< T > &MATRIX_RHS)
multiply two matrixs of equal size by building the inner product yielding the scalar product ...
friend bool operator>(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix > xyzMatrix
Definition: xyzMatrix.hh:1905
def x
string output
Definition: contacts.py:31
xyzMatrix & col(int const i, Vector const &v)
Column( i, xyzVector ) assignment: 1-base index.
Definition: xyzMatrix.hh:1361
xyzMatrix & left_multiply_by_transpose(xyzMatrix< U > const &m)
Left multiply by transpose xyzMatrix.
Definition: xyzMatrix.hh:1236
bool is_zero() const
Is zero?
Definition: xyzMatrix.hh:1764
xyzMatrix transposed() const
Transposed copy.
Definition: xyzMatrix.hh:1814
Value const & operator()(int const i, int const j) const
xyzMatrix( i, j ) const: 1-based index
Definition: xyzMatrix.hh:1641
static ColPointers< U > cols(U const *xp, U const *yp, U const *zp)
Pointers to contiguous columns named constructor/assignment.
Definition: xyzMatrix.hh:217
static xyzMatrix cols_constructor(U const *xp, U const *yp, U const *zp)
Pointers to contiguous columns named constructor.
Definition: xyzMatrix.hh:237
Value const & yx() const
Value yx const.
Definition: xyzMatrix.hh:1533
friend bool operator<=(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix <= xyzMatrix
Definition: xyzMatrix.hh:1879
MathMatrix< T > operator-(const MathMatrix< T > &MATRIX_LHS, const MathMatrix< T > &MATRIX_RHS)
subtract two matrixs of equal size
Value const & xx() const
Value xx const.
Definition: xyzMatrix.hh:1479
void yx(Value const &yx_a)
yx assignment
Definition: xyzMatrix.hh:1707
Vector row_z() const
Row z.
Definition: xyzMatrix.hh:1422
friend bool operator>=(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix >= xyzMatrix
Definition: xyzMatrix.hh:1892
Value const & yz() const
Value yz const.
Definition: xyzMatrix.hh:1569
Value const & yy() const
Value yy const.
Definition: xyzMatrix.hh:1551
xyzMatrix & col_z(Vector const &v)
Column z assignment.
Definition: xyzMatrix.hh:1334
friend xyzMatrix operator-(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix - xyzMatrix
Definition: xyzMatrix.hh:851
void zy(Value const &zy_a)
zy assignment
Definition: xyzMatrix.hh:1743
xyzMatrix & to_identity()
Set to the identity xyzMatrix.
Definition: xyzMatrix.hh:988
static xyzMatrix rows_constructor(U const *xp, U const *yp, U const *zp)
Pointers to contiguous rows named constructor.
Definition: xyzMatrix.hh:413
xyzMatrix(Value const &t)
Uniform value constructor.
Definition: xyzMatrix.hh:121
xyzVector< T > const & z_
z column
Definition: ColVectors.hh:95
xyzMatrix & zero()
Set to the zero xyzMatrix.
Definition: xyzMatrix.hh:976
void yy(Value const &yy_a)
yy assignment
Definition: xyzMatrix.hh:1716
bool operator>=(xyzMatrix< T > const &a, xyzMatrix< T > const &b)
xyzMatrix >= xyzMatrix
Vector col(int const i) const
Column( i ): 1-based index.
Definition: xyzMatrix.hh:1344
friend bool operator!=(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix != xyzMatrix
Definition: xyzMatrix.hh:1856
Value trace() const
Trace.
Definition: xyzMatrix.hh:1805
T const * zp_
Pointer (non-owning) to z column.
Definition: ColPointers.hh:95
MathMatrix< T > operator/(const MathMatrix< T > &MATRIX_LHS, const T &SCALAR_RHS)
divide matrix with scalar
void xz(Value const &xz_a)
xz assignment
Definition: xyzMatrix.hh:1698
static RowPointers< U > rows(U const *xp, U const *yp, U const *zp)
Pointers to contiguous rows named constructor/assignment.
Definition: xyzMatrix.hh:393
xyzMatrix & operator+=(xyzMatrix< U > const &m)
+= xyzMatrix
Definition: xyzMatrix.hh:590
xyzMatrix & row_x(Vector const &v)
Row x assignment.
Definition: xyzMatrix.hh:1393
def z
Vector col_x() const
Column x.
Definition: xyzMatrix.hh:1287
xyzMatrix & operator-=(xyzMatrix< U > const &m)
-= xyzMatrix
Definition: xyzMatrix.hh:603
friend bool operator<(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix < xyzMatrix
Definition: xyzMatrix.hh:1866
xyzMatrix & set_diagonal(Value const &xx_a, Value const &yy_a, Value const &zz_a)
set diagonal of xyzMatrix from value
Definition: xyzMatrix.hh:1034
Value & zy()
Value zy.
Definition: xyzMatrix.hh:1614
Value & xx()
Value xx.
Definition: xyzMatrix.hh:1488
T const & const_reference
Definition: xyzMatrix.hh:84
xyzMatrix & row_z(Vector const &v)
Row z assignment.
Definition: xyzMatrix.hh:1431
void zx(Value const &zx_a)
zx assignment
Definition: xyzMatrix.hh:1734
3x3 matrix column pointers wrapper class
friend xyzMatrix operator+(xyzMatrix const &a, xyzMatrix const &b)
xyzMatrix + xyzMatrix
Definition: xyzMatrix.hh:809
xyzVector< T > const & x_
x row
Definition: RowVectors.hh:89
static RowVectors< U > rows(xyzVector< U > const &row_x, xyzVector< U > const &row_y, xyzVector< U > const &row_z)
Row vectors named constructor/assignment.
Definition: xyzMatrix.hh:453
Vector row_y() const
Row y.
Definition: xyzMatrix.hh:1403
xyzMatrix & subtract_diagonal(xyzVector< U > const &diag_a)
Subtract xyzVector from diagonal of xyzMatrix.
Definition: xyzMatrix.hh:1111
static RowsPointer< U > rows(U const *rp)
Pointer to contiguous row-ordered values named constructor/assignment.
Definition: xyzMatrix.hh:361
numeric::xyzVector and numeric::xyzMatrix functions forward declarations
void show(std::ostream &output=std::cout) const
Show.
Definition: xyzMatrix.hh:2066
void zz(Value const &zz_a)
zz assignment
Definition: xyzMatrix.hh:1752
T const * xp_
Pointer (non-owning) to x row.
Definition: RowPointers.hh:89
Value const & zx() const
Value zx const.
Definition: xyzMatrix.hh:1587
bool operator>(xyzMatrix< T > const &a, xyzMatrix< T > const &b)
xyzMatrix > xyzMatrix
xyzMatrix & to_diag(xyzVector< U > const &diag_a)
Set to diagonal xyzMatrix from xyzVector.
Definition: xyzMatrix.hh:1019
xyzMatrix & col_y(Vector const &v)
Column y assignment.
Definition: xyzMatrix.hh:1315
xyzMatrix & add_diagonal(Value const &xx_a, Value const &yy_a, Value const &zz_a)
Add values to diagonal of xyzMatrix.
Definition: xyzMatrix.hh:1065
T const * p_
Pointer (non-owning) to contiguous row-ordered 3x3 matrix.
Definition: RowsPointer.hh:65
static xyzMatrix const & I()
Identity xyzMatrix for expressions.
Definition: xyzMatrix.hh:1269
bool operator!=(BodyPosition< T > const &p1, BodyPosition< T > const &p2)
BodyPosition != BodyPosition.
Value & yx()
Value yx.
Definition: xyzMatrix.hh:1542
numeric::xyzMatrix forward declarations
Vector col_z() const
Column z.
Definition: xyzMatrix.hh:1325
xyzMatrix(xyzMatrix< U > const &m)
Copy constructor.
Definition: xyzMatrix.hh:111
3x3 matrix row vectors wrapper class
xyzVector< T > const & z_
z row
Definition: RowVectors.hh:95
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
Value const & zy() const
Value zy const.
Definition: xyzMatrix.hh:1605
float tol
Definition: loops_kic.py:75
xyzMatrix(RowVectors< U > const &r)
Rows constructor.
Definition: xyzMatrix.hh:437
Value & yy()
Value yy.
Definition: xyzMatrix.hh:1560
MathMatrix< T > operator+(const MathMatrix< T > &MATRIX_LHS, const MathMatrix< T > &MATRIX_RHS)
sum two matrixs of equal size
xyzMatrix: Fast 3x3 xyz matrix template
xyzMatrix & col_x(Vector const &v)
Column x assignment.
Definition: xyzMatrix.hh:1296
xyzVector< T > const & y_
y column
Definition: ColVectors.hh:92
Value xx_
Elements of the 3x3 matrix.
Definition: xyzMatrix.hh:2078
xyzMatrix & right_multiply_by_transpose(xyzMatrix< U > const &m)
Right multiply by transpose xyzMatrix.
Definition: xyzMatrix.hh:1176
Vector row(int const i) const
Row ( i ): 1-based index.
Definition: xyzMatrix.hh:1441
friend xyzMatrix operator/(xyzMatrix const &m, Value const &t)
xyzMatrix / Value
Definition: xyzMatrix.hh:946
xyzMatrix(RowPointers< U > const &r)
Pointers to contiguous rows constructor.
Definition: xyzMatrix.hh:376
static xyzMatrix diag(Value const &xx_a, Value const &yy_a, Value const &zz_a)
Diagonal value named constructor.
Definition: xyzMatrix.hh:494
Contiguous column-ordered 3x3 matrix pointer wrapper class.
xyzMatrix & operator/=(Value const &t)
/= Value
Definition: xyzMatrix.hh:791
bool is_identity() const
Is identity?
Definition: xyzMatrix.hh:1777
Value & zz()
Value zz.
Definition: xyzMatrix.hh:1632
T const * yp_
Pointer (non-owning) to y column.
Definition: ColPointers.hh:92
Contiguous row-ordered 3x3 matrix pointer wrapper class.
point axis
Fast (x,y,z)-coordinate numeric vector.
Value & zx()
Value zx.
Definition: xyzMatrix.hh:1596
xyzMatrix & left_multiply_by(xyzMatrix< U > const &m)
Left multiply by xyzMatrix.
Definition: xyzMatrix.hh:1206
T const & ConstReference
Definition: xyzMatrix.hh:76
xyzMatrix(xyzMatrix const &m)
Copy constructor.
Definition: xyzMatrix.hh:101
Value const & xz() const
Value xz const.
Definition: xyzMatrix.hh:1515
xyzMatrix & row_y(Vector const &v)
Row y assignment.
Definition: xyzMatrix.hh:1412
void xx(Value const &xx_a)
xx assignment
Definition: xyzMatrix.hh:1680
T const * p_
Pointer (non-owning) to contiguous column-ordered 3x3 matrix.
Definition: ColsPointer.hh:65
Value const & xy() const
Value xy const.
Definition: xyzMatrix.hh:1497
static ColVectors< U > cols(xyzVector< U > const &col_x, xyzVector< U > const &col_y, xyzVector< U > const &col_z)
Column vectors named constructor/assignment.
Definition: xyzMatrix.hh:277
Value & yz()
Value yz.
Definition: xyzMatrix.hh:1578
def y
xyzMatrix & right_multiply_by(xyzMatrix< U > const &m)
Right multiply by xyzMatrix.
Definition: xyzMatrix.hh:1146
static xyzMatrix cols(Value const &xx_a, Value const &yx_a, Value const &zx_a, Value const &xy_a, Value const &yy_a, Value const &zy_a, Value const &xz_a, Value const &yz_a, Value const &zz_a)
Column-ordered value named constructor.
Definition: xyzMatrix.hh:146
xyzMatrix(RowsPointer< U > const &r)
Pointer to contiguous row-ordered values constructor.
Definition: xyzMatrix.hh:346
void xy(Value const &xy_a)
xy assignment
Definition: xyzMatrix.hh:1689
static ColsPointer< U > cols(U const *cp)
Pointer to contiguous column-ordered values named constructor/assignment.
Definition: xyzMatrix.hh:185
T const * ConstPointer
Definition: xyzMatrix.hh:78
T const * zp_
Pointer (non-owning) to z row.
Definition: RowPointers.hh:95
xyzMatrix()
Default constructor.
Definition: xyzMatrix.hh:95
static xyzMatrix identity()
Identity xyzMatrix named constructor.
Definition: xyzMatrix.hh:529
xyzMatrix< T > inverse() const
Definition: xyzMatrix.hh:1826