34 vec2d(
double x0,
double x1):_x0(x0),_x1(x1)
40 { _x0 += a._x0;_x1 += a._x1;
return *
this; }
42 {
vec2d r(*
this);
return r += a; }
44 { _x0 -= a._x0;_x1 -= a._x1;
return *
this; }
46 {
vec2d r(*
this);
return r -= a; }
47 vec2d& operator *= (
double q)
48 { _x0 *= q;_x1 *= q;
return *
this; }
49 vec2d operator * (
double q)
const
50 {
vec2d r(*
this);
return r *= q; }
51 friend vec2d operator * (
double q,
const vec2d& a)
52 {
vec2d r(a);
return r *= q; }
53 vec2d& operator /= (
double q)
54 { _x0 /= q;_x1 /= q;
return *
this; }
55 vec2d operator / (
double q)
const
56 {
vec2d r(*
this);
return r /= q; }
58 {
return vec2d(-_x0,-_x1); }
62 const double& operator [] (
int i)
const
63 {
return *(&_x0 + i); }
64 double& operator [] (
int i)
65 {
return *(&_x0 + i); }
71 {
return a[0] * a[0] + a[1] * a[1]; }
74 {
return a[0] * b[0] + a[1] * b[1]; }
77 { return ::sqrt(
dotsq(a)); }
80 {
return v /
norm2(v); }
84 friend std::ostream& operator << (std::ostream& cout,
const vec2d& a)
85 {
return cout << a[0] <<
" " << a[1]; }
86 friend std::istream& operator >> (std::istream& cin,
vec2d& a)
87 {
return cin >> a[0] >> a[1]; }
98 mat2d():_x0(1,0),_x1(0,1)
108 mat2d(
double a00,
double a01,
double a10,
double a11):_x0(a00,a01),_x1(a10,a11)
117 { _x0 += a._x0;_x1 += a._x1;
return *
this; }
119 {
mat2d r(*
this);
return r += a; }
121 { _x0 -= a._x0;_x1 -= a._x1;
return *
this; }
123 {
mat2d r(*
this);
return r -= a; }
124 mat2d& operator *= (
double q)
125 { _x0 *= q;_x1 *= q;
return *
this; }
126 mat2d operator * (
double q)
const
127 {
mat2d r(*
this);
return r *= q; }
128 friend mat2d operator * (
double q,
const mat2d& a)
129 {
mat2d r(a);
return r *= q; }
133 const mat2d& t(*
this);
134 return mat2d( t[0][0] * a[0][0] + t[0][1] * a[1][0],
135 t[0][0] * a[0][1] + t[0][1] * a[1][1],
136 t[1][0] * a[0][0] + t[1][1] * a[1][0],
137 t[1][0] * a[0][1] + t[1][1] * a[1][1]);
139 mat2d& operator /= (
double q)
140 { _x0 /= q;_x1 /= q;
return *
this; }
141 mat2d operator / (
double q)
const
142 {
mat2d r(*
this);
return r /= q; }
144 {
return mat2d(-_x0,-_x1); }
147 {
return vec2d(dot(_x0,a),dot(_x1,a)); }
151 const vec2d& operator [] (
int i)
const
152 {
return *(&_x0 + i); }
153 vec2d& operator [] (
int i)
154 {
return *(&_x0 + i); }
160 {
return a[0][0] * a[1][1] - a[0][1] * a[1][0]; }
163 {
return a[0][0] + a[1][1]; }
166 {
return mat2d(a[0][0],a[1][0],a[0][1],a[1][1]); }
169 {
return mat2d(a[1][1],-a[0][1],-a[1][0],a[0][0]) /
det(a); }
173 friend std::ostream& operator << (std::ostream& cout,
const mat2d& a)
174 {
return cout << a[0] <<
" " << a[1]; }
175 friend std::istream& operator >> (std::istream& cin,
mat2d& a)
176 {
return cin >> a[0] >> a[1]; }
182 inline mat2d
ten(
const vec2d& a,
const vec2d& b)
184 {
return mat2d(a[0] * b[0],a[0] * b[1],a[1] * b[0],a[1] * b[1]); }
187 {
return mat2d(a[0] * a[0],a[0] * a[1],a[1] * a[0],a[1] * a[1]); }
189 template <
class VEC2>
195 typedef VEC2 vec2_type;
200 box():_a(HUGE_VAL,HUGE_VAL),_b(-HUGE_VAL,-HUGE_VAL)
204 _a = vec2_type(HUGE_VAL,HUGE_VAL);
205 _b = vec2_type(-HUGE_VAL,-HUGE_VAL);
207 const vec2_type& a()
const
209 const vec2_type& b()
const
211 bool is_empty()
const
212 {
return (_b[0] < _a[0]) || (_b[1] < _a[1]); }
213 void extend_x(
double x)
215 if(x < _a[0]) _a[0] = x;
216 if(x > _b[0]) _b[0] = x;
218 void extend_y(
double y)
220 if(y < _a[1]) _a[1] = y;
221 if(y > _b[1]) _b[1] = y;
223 void extend(
int i,
double q)
225 if(i == 0) extend_x(q);
226 if(i == 1) extend_y(q);
228 void extend(
const vec2_type& p)
mat2d tensq(const vec2d &a)
Tensor (dyadic) product square.
Definition: ldpk_vec2d.h:186
Exception classes for ldpk.
friend double norm2(const vec2d &a)
Euclidian norm.
Definition: ldpk_vec2d.h:76
mat2d(const mat2d &a)
Copy constructor.
Definition: ldpk_vec2d.h:102
friend vec2d unit(const vec2d &v)
Unit vector.
Definition: ldpk_vec2d.h:79
mat2d(double s)
Scalar matrix.
Definition: ldpk_vec2d.h:105
vec2d()
Default: null vector.
Definition: ldpk_vec2d.h:28
friend double det(const mat2d &a)
Determinant.
Definition: ldpk_vec2d.h:159
mat2d(const vec2d &x0, const vec2d &x1)
Constructing by components (row vectors)
Definition: ldpk_vec2d.h:111
vec2d(const vec2d &a)
Copy constructor.
Definition: ldpk_vec2d.h:31
mat2d(double a00, double a01, double a10, double a11)
Constructing by components (numbers)
Definition: ldpk_vec2d.h:108
A simple box class for double precision points in 2d. We will extend this as needed.
Definition: ldpk_vec2d.h:192
A class for double-valued 2x2-matrices. The matrix class for ldpk::vec2d.
Definition: ldpk_vec2d.h:91
mat2d()
Default: null matrix.
Definition: ldpk_vec2d.h:99
friend mat2d invert(const mat2d &a)
Inverse.
Definition: ldpk_vec2d.h:168
mat2d ten(const vec2d &a, const vec2d &b)
Tensor (dyadic) product of vectors.
Definition: ldpk_vec2d.h:183
vec2d(double x0, double x1)
Constructing by components.
Definition: ldpk_vec2d.h:34
A class for two-dimensional double-valued vectors We have added this class and ldpk::mat2d in order t...
Definition: ldpk_vec2d.h:20
friend double tr(const mat2d &a)
Trace.
Definition: ldpk_vec2d.h:162
friend double dot(const vec2d &a, const vec2d &b)
Inner product.
Definition: ldpk_vec2d.h:73
friend double dotsq(const vec2d &a)
Inner product square.
Definition: ldpk_vec2d.h:70
friend mat2d trans(const mat2d &a)
Transposed.
Definition: ldpk_vec2d.h:165