Classes | Functions

Glue_cross

//! More...

Classes

class  glue_cross

Functions

template<typename T1 , typename T2 >
static void glue_cross::apply (Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_cross > &X)

Detailed Description

//!


Function Documentation

template<typename T1 , typename T2 >
void glue_cross::apply ( Mat< typename T1::elem_type > &  out,
const Glue< T1, T2, glue_cross > &  X 
) [inline, static, inherited]

Definition at line 26 of file glue_cross_meat.hpp.

References Glue< T1, T2, glue_type >::A, Glue< T1, T2, glue_type >::B, unwrap< T1 >::M, Mat< eT >::memptr(), Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const unwrap<T1> A_tmp(X.A);
  const unwrap<T2> B_tmp(X.B);
  
  const Mat<eT>& A = A_tmp.M;
  const Mat<eT>& B = B_tmp.M;
  
  arma_debug_check( ((A.n_elem != 3) || (B.n_elem != 3)), "cross(): input vectors must have 3 elements" );
  
  out.set_size(A.n_rows, A.n_cols);
  
        eT* out_ptr = out.memptr();
  const eT* A_ptr   = A.memptr();
  const eT* B_ptr   = B.memptr();
  
  // out_ptr[0] = A_ptr[1]*B_ptr[2] - A_ptr[2]*B_ptr[1];
  // out_ptr[1] = A_ptr[2]*B_ptr[0] - A_ptr[0]*B_ptr[2];
  // out_ptr[2] = A_ptr[0]*B_ptr[1] - A_ptr[1]*B_ptr[0];
  
  const eT ax = A_ptr[0];
  const eT ay = A_ptr[1];
  const eT az = A_ptr[2];
  
  const eT bx = B_ptr[0];
  const eT by = B_ptr[1];
  const eT bz = B_ptr[2];
  
  out_ptr[0] = ay*bz - az*by;
  out_ptr[1] = az*bx - ax*bz;
  out_ptr[2] = ax*by - ay*bx;
  }