source: ThirdParty/mpqc_open/src/lib/util/render/algebra3.h@ 7516f6

Action_Thermostats Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 7516f6 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 13.3 KB
Line 
1/****************************************************************
2* *
3* C++ Vector and Matrix Algebra routines *
4* Author: Jean-Francois DOUE *
5* Version 3.1 --- October 1993 *
6* *
7****************************************************************/
8
9#ifndef _util_misc_algebra_h
10#define _util_misc_algebra_h
11
12#include <iostream>
13#include <stdlib.h>
14
15namespace sc {
16
17// this line defines a new type: pointer to a function which returns a
18// double and takes as argument a double
19typedef double (*V_FCT_PTR)(double);
20
21class vec2;
22class vec3;
23class vec4;
24class mat3;
25class mat4;
26
27enum {VX, VY, VZ, VW}; // axes
28enum {PA, PB, PC, PD}; // planes
29enum {RED, GREEN, BLUE}; // colors
30
31/****************************************************************
32* *
33* 2D Vector *
34* *
35****************************************************************/
36
37class vec2
38{
39protected:
40
41 double n[2];
42
43public:
44
45// Constructors
46
47vec2();
48vec2(const double x, const double y);
49vec2(const double d);
50vec2(const vec2& v); // copy constructor
51vec2(const vec3& v); // cast v3 to v2
52vec2(const vec3& v, int dropAxis); // cast v3 to v2
53
54// Assignment operators
55
56vec2& operator = ( const vec2& v ); // assignment of a vec2
57vec2& operator += ( const vec2& v ); // incrementation by a vec2
58vec2& operator -= ( const vec2& v ); // decrementation by a vec2
59vec2& operator *= ( const double d ); // multiplication by a constant
60vec2& operator /= ( const double d ); // division by a constant
61double& operator [] ( int i); // indexing
62const double& operator[](int i) const; // indexing
63
64// special functions
65
66double length(); // length of a vec2
67double length2(); // squared length of a vec2
68vec2& normalize(); // normalize a vec2
69vec2& apply(V_FCT_PTR fct); // apply a func. to each component
70
71// friends
72
73friend vec2 operator - (const vec2& v); // -v1
74friend vec2 operator + (const vec2& a, const vec2& b); // v1 + v2
75friend vec2 operator - (const vec2& a, const vec2& b); // v1 - v2
76friend vec2 operator * (const vec2& a, const double d); // v1 * 3.0
77friend vec2 operator * (const double d, const vec2& a); // 3.0 * v1
78friend vec2 operator * (const mat3& a, const vec2& v); // M . v
79friend vec2 operator * (const vec2& v, mat3& a); // v . M
80friend double operator * (const vec2& a, const vec2& b); // dot product
81friend vec2 operator / (const vec2& a, const double d); // v1 / 3.0
82friend vec3 operator ^ (const vec2& a, const vec2& b); // cross product
83friend int operator == (const vec2& a, const vec2& b); // v1 == v2 ?
84friend int operator != (const vec2& a, const vec2& b); // v1 != v2 ?
85friend std::ostream& operator << (std::ostream& s, vec2& v);// output to stream
86friend std::istream& operator >> (std::istream& s, vec2& v);// input from strm.
87friend void swap(vec2& a, vec2& b); // swap v1 & v2
88friend vec2 min(const vec2& a, const vec2& b); // min(v1, v2)
89friend vec2 max(const vec2& a, const vec2& b); // max(v1, v2)
90friend vec2 prod(const vec2& a, const vec2& b); // term by term *
91
92// necessary friend declarations
93
94friend class vec3;
95};
96
97/****************************************************************
98* *
99* 3D Vector *
100* *
101****************************************************************/
102
103class vec3
104{
105protected:
106
107 double n[3];
108
109public:
110
111// Constructors
112
113vec3();
114vec3(const double x, const double y, const double z);
115vec3(const double d);
116vec3(const vec3& v); // copy constructor
117vec3(const vec2& v); // cast v2 to v3
118vec3(const vec2& v, double d); // cast v2 to v3
119vec3(const vec4& v); // cast v4 to v3
120vec3(const vec4& v, int dropAxis); // cast v4 to v3
121
122// Assignment operators
123
124vec3& operator = ( const vec3& v ); // assignment of a vec3
125vec3& operator += ( const vec3& v ); // incrementation by a vec3
126vec3& operator -= ( const vec3& v ); // decrementation by a vec3
127vec3& operator *= ( const double d ); // multiplication by a constant
128vec3& operator /= ( const double d ); // division by a constant
129double& operator [] ( int i); // indexing
130const double& operator[](int i) const; // indexing
131
132// special functions
133
134double length(); // length of a vec3
135double length2(); // squared length of a vec3
136vec3& normalize(); // normalize a vec3
137vec3& apply(V_FCT_PTR fct); // apply a func. to each component
138
139// friends
140
141friend vec3 operator - (const vec3& v); // -v1
142friend vec3 operator + (const vec3& a, const vec3& b); // v1 + v2
143friend vec3 operator - (const vec3& a, const vec3& b); // v1 - v2
144friend vec3 operator * (const vec3& a, const double d); // v1 * 3.0
145friend vec3 operator * (const double d, const vec3& a); // 3.0 * v1
146friend vec3 operator * (const mat4& a, const vec3& v); // M . v
147friend vec3 operator * (const vec3& v, const mat4& a); // v . M
148friend double operator * (const vec3& a, const vec3& b); // dot product
149friend vec3 operator / (const vec3& a, const double d); // v1 / 3.0
150friend vec3 operator ^ (const vec3& a, const vec3& b); // cross product
151friend int operator == (const vec3& a, const vec3& b); // v1 == v2 ?
152friend int operator != (const vec3& a, const vec3& b); // v1 != v2 ?
153friend std::ostream& operator << (std::ostream& s, vec3& v);// output to stream
154friend std::istream& operator >> (std::istream& s, vec3& v);// input from strm.
155friend void swap(vec3& a, vec3& b); // swap v1 & v2
156friend vec3 min(const vec3& a, const vec3& b); // min(v1, v2)
157friend vec3 max(const vec3& a, const vec3& b); // max(v1, v2)
158friend vec3 prod(const vec3& a, const vec3& b); // term by term *
159
160// necessary friend declarations
161
162friend class vec2;
163friend class vec4;
164friend class mat3;
165friend vec2 operator * (const mat3& a, const vec2& v); // linear transform
166friend mat3 operator * (const mat3& a, const mat3& b); // matrix 3 product
167};
168
169/****************************************************************
170* *
171* 4D Vector *
172* *
173****************************************************************/
174
175class vec4
176{
177protected:
178
179 double n[4];
180
181public:
182
183// Constructors
184
185vec4();
186vec4(const double x, const double y, const double z, const double w);
187vec4(const double d);
188vec4(const vec4& v); // copy constructor
189vec4(const vec3& v); // cast vec3 to vec4
190vec4(const vec3& v, const double d); // cast vec3 to vec4
191
192// Assignment operators
193
194vec4& operator = ( const vec4& v ); // assignment of a vec4
195vec4& operator += ( const vec4& v ); // incrementation by a vec4
196vec4& operator -= ( const vec4& v ); // decrementation by a vec4
197vec4& operator *= ( const double d ); // multiplication by a constant
198vec4& operator /= ( const double d ); // division by a constant
199double& operator [] ( int i); // indexing
200const double& operator [] ( int i) const; // indexing
201
202// special functions
203
204double length(); // length of a vec4
205double length2(); // squared length of a vec4
206vec4& normalize(); // normalize a vec4
207vec4& apply(V_FCT_PTR fct); // apply a func. to each component
208
209// friends
210
211friend vec4 operator - (const vec4& v); // -v1
212friend vec4 operator + (const vec4& a, const vec4& b); // v1 + v2
213friend vec4 operator - (const vec4& a, const vec4& b); // v1 - v2
214friend vec4 operator * (const vec4& a, const double d); // v1 * 3.0
215friend vec4 operator * (const double d, const vec4& a); // 3.0 * v1
216friend vec4 operator * (const mat4& a, const vec4& v); // M . v
217friend vec4 operator * (const vec4& v, const mat4& a); // v . M
218friend double operator * (const vec4& a, const vec4& b); // dot product
219friend vec4 operator / (const vec4& a, const double d); // v1 / 3.0
220friend int operator == (const vec4& a, const vec4& b); // v1 == v2 ?
221friend int operator != (const vec4& a, const vec4& b); // v1 != v2 ?
222friend std::ostream& operator << (std::ostream& s, vec4& v);// output to stream
223friend std::istream& operator >> (std::istream& s, vec4& v);// input from strm.
224friend void swap(vec4& a, vec4& b); // swap v1 & v2
225friend vec4 min(const vec4& a, const vec4& b); // min(v1, v2)
226friend vec4 max(const vec4& a, const vec4& b); // max(v1, v2)
227friend vec4 prod(const vec4& a, const vec4& b); // term by term *
228
229// necessary friend declarations
230
231friend class vec3;
232friend class mat4;
233friend vec3 operator * (const mat4& a, const vec3& v); // linear transform
234friend mat4 operator * (const mat4& a, const mat4& b); // matrix 4 product
235};
236
237/****************************************************************
238* *
239* 3x3 Matrix *
240* *
241****************************************************************/
242
243class mat3
244{
245protected:
246
247 vec3 v[3];
248
249public:
250
251// Constructors
252
253mat3();
254mat3(const vec3& v0, const vec3& v1, const vec3& v2);
255mat3(const double d);
256mat3(const mat3& m);
257
258// Assignment operators
259
260mat3& operator = ( const mat3& m ); // assignment of a mat3
261mat3& operator += ( const mat3& m ); // incrementation by a mat3
262mat3& operator -= ( const mat3& m ); // decrementation by a mat3
263mat3& operator *= ( const double d ); // multiplication by a constant
264mat3& operator /= ( const double d ); // division by a constant
265vec3& operator [] ( int i); // indexing
266const vec3& operator [] ( int i) const; // indexing
267
268// special functions
269
270mat3 transpose() const; // transpose
271mat3 inverse(); // inverse
272mat3& apply(V_FCT_PTR fct); // apply a func. to each element
273
274// friends
275
276friend mat3 operator - (const mat3& a); // -m1
277friend mat3 operator + (const mat3& a, const mat3& b); // m1 + m2
278friend mat3 operator - (const mat3& a, const mat3& b); // m1 - m2
279friend mat3 operator * (const mat3& a, const mat3& b); // m1 * m2
280friend mat3 operator * (const mat3& a, const double d); // m1 * 3.0
281friend mat3 operator * (const double d, const mat3& a); // 3.0 * m1
282friend mat3 operator / (const mat3& a, const double d); // m1 / 3.0
283friend int operator == (const mat3& a, const mat3& b); // m1 == m2 ?
284friend int operator != (const mat3& a, const mat3& b); // m1 != m2 ?
285friend std::ostream& operator << (std::ostream& s, mat3& m);// output to stream
286friend std::istream& operator >> (std::istream& s, mat3& m);// input from strm.
287friend void swap(mat3& a, mat3& b); // swap m1 & m2
288
289// necessary friend declarations
290
291friend vec3 operator * (const mat3& a, const vec3& v); // linear transform
292friend vec2 operator * (const mat3& a, const vec2& v); // linear transform
293};
294
295/****************************************************************
296* *
297* 4x4 Matrix *
298* *
299****************************************************************/
300
301class mat4
302{
303protected:
304
305 vec4 v[4];
306
307public:
308
309// Constructors
310
311mat4();
312mat4(const vec4& v0, const vec4& v1, const vec4& v2, const vec4& v3);
313mat4(const double d);
314mat4(const mat4& m);
315
316// Assignment operators
317
318mat4& operator = ( const mat4& m ); // assignment of a mat4
319mat4& operator += ( const mat4& m ); // incrementation by a mat4
320mat4& operator -= ( const mat4& m ); // decrementation by a mat4
321mat4& operator *= ( const double d ); // multiplication by a constant
322mat4& operator /= ( const double d ); // division by a constant
323vec4& operator [] ( int i); // indexing
324const vec4& operator [] ( int i) const; // indexing
325
326// special functions
327
328mat4 transpose() const; // transpose
329mat4 inverse(); // inverse
330mat4& apply(V_FCT_PTR fct); // apply a func. to each element
331
332// friends
333
334friend mat4 operator - (const mat4& a); // -m1
335friend mat4 operator + (const mat4& a, const mat4& b); // m1 + m2
336friend mat4 operator - (const mat4& a, const mat4& b); // m1 - m2
337friend mat4 operator * (const mat4& a, const mat4& b); // m1 * m2
338friend mat4 operator * (const mat4& a, const double d); // m1 * 4.0
339friend mat4 operator * (const double d, const mat4& a); // 4.0 * m1
340friend mat4 operator / (const mat4& a, const double d); // m1 / 3.0
341friend int operator == (const mat4& a, const mat4& b); // m1 == m2 ?
342friend int operator != (const mat4& a, const mat4& b); // m1 != m2 ?
343friend std::ostream& operator << (std::ostream& s, mat4& m);// output to stream
344friend std::istream& operator >> (std::istream& s, mat4& m);// input from strm.
345friend void swap(mat4& a, mat4& b); // swap m1 & m2
346
347// necessary friend declarations
348
349friend vec4 operator * (const mat4& a, const vec4& v); // linear transform
350friend vec3 operator * (const mat4& a, const vec3& v); // linear transform
351};
352
353/****************************************************************
354* *
355* 2D functions and 3D functions *
356* *
357****************************************************************/
358
359mat3 identity2D(); // identity 2D
360mat3 translation2D(const vec2& v); // translation 2D
361mat3 rotation2D(const vec2& Center, const double angleDeg); // rotation 2D
362mat3 scaling2D(const vec2& scaleVector); // scaling 2D
363mat4 identity3D(); // identity 3D
364mat4 translation3D(const vec3& v); // translation 3D
365mat4 rotation3D(const vec3& Axis, const double angleDeg); // rotation 3D
366mat4 scaling3D(const vec3& scaleVector); // scaling 3D
367mat4 perspective3D(const double d); // perspective 3D
368
369}
370
371#endif
Note: See TracBrowser for help on using the repository browser.