34 #include <Eigen/Dense>
35 using namespace Eigen;
37 typedef Matrix<int32_t, Eigen::Dynamic, 1>
int_array;
38 typedef Matrix<nec_float, Eigen::Dynamic, 1>
real_array;
42 #include "safe_array.h"
53 inline void vector_fill(
complex_array& x, int32_t start, int32_t N,
const nec_complex& y) {
58 inline nec_complex cplx_00() {
59 static nec_complex _cplx00(0.0,0.0);
return _cplx00;
62 inline nec_complex cplx_01() {
63 static nec_complex _cplx01(0.0,1.0);
return _cplx01;
66 inline nec_complex cplx_10() {
67 static nec_complex _cplx10(1.0,0.0);
return _cplx10;
70 inline nec_complex cplx_11() {
71 static nec_complex _cplx11(1.0,1.0);
return _cplx11;
75 inline nec_complex cplx_exp(
const nec_float& x) {
76 return nec_complex(cos(x),sin(x));
80 inline nec_float pi() {
81 static nec_float _pi = 3.1415926536;
return _pi;
84 inline nec_float two_pi() {
85 static nec_float _tmp = 2.0 * pi();
return _tmp;
88 inline nec_float four_pi() {
89 static nec_float _tmp = 4.0 * pi();
return _tmp;
92 inline nec_float pi_two() {
93 static nec_float _tmp = pi() / 2.0;
return _tmp;
96 inline nec_float sqrt_pi() {
97 static nec_float _tmp = sqrt(pi());
return _tmp;
101 inline nec_complex two_pi_j() {
102 static nec_complex _tmp(0.0,two_pi());
return _tmp;
107 inline nec_float rad_to_degrees(nec_float in_radians) {
108 static nec_float _rad_to_deg = 360.0 / (2 * pi());
109 return in_radians * _rad_to_deg;
112 inline nec_float degrees_to_rad(nec_float in_degrees) {
113 static nec_float _deg_to_rad = (2 * pi()) / 360.0;
114 return in_degrees * _deg_to_rad;
119 inline nec_complex deg_polar(nec_float r, nec_float theta) {
120 return std::polar(r, degrees_to_rad(theta));
126 inline nec_float arg_degrees(nec_complex z) {
127 return rad_to_degrees(std::arg(z));
133 inline nec_float atgn2( nec_float x, nec_float y) {
134 if ((0.0 == y) && (0.0 == x))
137 return( std::atan2(y, x) );
142 inline nec_float db10( nec_float x ) {
146 return( 10.0 * log10(x) );
150 inline nec_float from_db10( nec_float x ) {
154 return( std::pow(10,x / 10.0));
159 inline nec_float db20( nec_float x ) {
163 return( 20.0 * log10(x) );
167 inline nec_float norm(
const nec_float x,
const nec_float y) {
168 return std::sqrt(x*x + y*y);
171 inline nec_float norm2(
const nec_float x,
const nec_float y,
const nec_float z) {
172 return (x*x + y*y + z*z);
175 inline nec_float norm(
const nec_float x,
const nec_float y,
const nec_float z) {
176 return std::sqrt(norm2(x,y,z));
180 inline nec_float normL1(
const nec_float x,
const nec_float y,
const nec_float z) {
181 return std::fabs(x) + std::fabs(y) + std::fabs(z);
187 #if USING_EIGEN_3VECT
188 #include <Eigen/Dense>
189 using namespace Eigen;
192 typedef Matrix<nec_complex,3,1> nec_c3vector;
200 nec_3vector(
const nec_float& in_x,
const nec_float& in_y,
const nec_float& in_z) {
207 inline nec_float
norm()
const {
208 return ::norm(_v[0], _v[1], _v[2]);
211 inline nec_float norm2()
const {
212 return ::norm2(_v[0], _v[1], _v[2]);
217 return ::normL1(_v[0], _v[1], _v[2]);
220 inline nec_3vector& operator=(
const nec_3vector& copy) {
227 inline int operator==(
const nec_3vector& copy)
const {
228 if (_v[0] != copy._v[0])
230 if (_v[1] != copy._v[1])
232 if (_v[2] != copy._v[2])
238 inline nec_3vector& operator+=(
const nec_3vector& a) {
245 inline nec_3vector operator+(nec_float a)
const {
246 return nec_3vector(_v[0] + a, _v[1] + a, _v[2] + a);
249 inline nec_3vector operator+(
const nec_3vector& a)
const {
250 return nec_3vector(_v[0] + a._v[0], _v[1] + a._v[1], _v[2] + a._v[2]);
253 inline nec_3vector& operator-=(
const nec_3vector& a) {
260 inline nec_3vector operator-(
const nec_3vector& a)
const {
261 return nec_3vector(_v[0] - a._v[0], _v[1] - a._v[1], _v[2] - a._v[2]);
265 inline nec_3vector& operator/=(
const nec_float& a) {
271 inline nec_3vector operator/(nec_float a)
const {
272 return nec_3vector(_v[0] / a, _v[1] / a, _v[2] / a);
275 inline nec_float dot(
const nec_3vector& a)
const {
276 return (_v[0] * a._v[0]) + (_v[1] * a._v[1]) + (_v[2] * a._v[2]);
279 inline nec_3vector& operator*=(
const nec_float& a) {
285 inline nec_3vector operator*(nec_float a)
const {
286 return nec_3vector(_v[0] * a, _v[1] * a, _v[2] * a);
289 inline nec_float& operator()(
int i) {
293 inline const nec_float& operator()(
int i)
const {
300 _v[1]*a._v[2] - _v[2]*a._v[1],
301 _v[2]*a._v[0] - _v[0]*a._v[2],
302 _v[0]*a._v[1] - _v[1]*a._v[0]);
305 inline nec_float x()
const {
return _v[0]; }
306 inline nec_float y()
const {
return _v[1]; }
307 inline nec_float z()
const {
return _v[2]; }
316 inline nec_float norm(
const nec_3vector& v) {
321 inline nec_float normL1(
const nec_3vector& v) {
322 return normL1(v(0), v(1), v(2));
nec_3vector operator*(const nec_3vector &a) const
Cross-product.
Definition: math_util.h:298
A Class for handling 3 dimensional vectors.
Definition: math_util.h:196
nec_float norm() const
The Euclidian norm.
Definition: math_util.h:207
nec_float normL1() const
The L1-distance (often called the Manhattan norm)
Definition: math_util.h:216