Math3d.h
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: Math3d.h
37 // Author: Pedram Azad
38 // Date: 2004
39 // ****************************************************************************
40 
41 
42 #ifndef _MATH_3D_H_
43 #define _MATH_3D_H_
44 
45 
46 // ****************************************************************************
47 // Necessary includes
48 // ****************************************************************************
49 
50 #include <vector>
52 
53 
54 // ****************************************************************************
55 // Structs and typedefs
56 // ****************************************************************************
57 
73 struct Vec3d
74 {
75  float x, y, z;
76 };
77 
93 struct Mat3d
94 {
95  float r1, r2, r3, r4, r5, r6, r7, r8, r9;
96 };
97 
106 {
109 };
110 
119 {
123  float w;
124 };
125 
126 typedef std::vector<Vec3d> Vec3dList;
128 
129 
130 
131 // ****************************************************************************
132 // Math3d
133 // ****************************************************************************
134 
139 namespace Math3d
140 {
141  bool LoadFromFile(Vec3d &vector, const char *pFilePath);
142  bool LoadFromFile(Mat3d &matrix, const char *pFilePath);
143  bool LoadFromFile(Transformation3d &transformation, const char *pFilePath);
144  bool SaveToFile(const Vec3d &vector, const char *pFilePath);
145  bool SaveToFile(const Mat3d &matrix, const char *pFilePath);
146  bool SaveToFile(const Transformation3d &transformation, const char *pFilePath);
147 
148  void SetVec(Vec3d &vec, float x, float y, float z);
149  void SetVec(Vec3d &vec, const Vec3d &sourceVector);
150  void SetMat(Mat3d &matrix, float r1, float r2, float r3, float r4, float r5, float r6, float r7, float r8, float r9);
151  void SetMat(Mat3d &matrix, const Mat3d &sourceMatrix);
152  void SetRotationMat(Mat3d &matrix, const Vec3d &axis, float theta);
153  void SetRotationMat(Mat3d &matrix, float alpha, float beta, float gamma);
154  void SetRotationMat(Mat3d &matrix, const Vec3d &rotation);
155  void SetRotationMatYZX(Mat3d &matrix, const Vec3d &rotation);
156  void SetRotationMatX(Mat3d &matrix, float theta);
157  void SetRotationMatY(Mat3d &matrix, float theta);
158  void SetRotationMatZ(Mat3d &matrix, float theta);
159  void SetRotationMatAxis(Mat3d &matrix, const Vec3d &axis, float theta);
160 
161  void MulMatVec(const Mat3d &matrix, const Vec3d &vec, Vec3d &result);
162  void MulMatVec(const Mat3d &matrix, const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
163  void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result);
164 
165  void MulVecTransposedVec(const Vec3d &vector1, const Vec3d &vector2, Mat3d &result);
166 
167  void RotateVec(const Vec3d &vec, const Vec3d &rotation, Vec3d &result);
168  void RotateVecYZX(const Vec3d &vec, const Vec3d &rotation, Vec3d &result);
169  void TransformVec(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result);
170  void TransformVecYZX(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result);
171 
172  void MulVecScalar(const Vec3d &vec, float scalar, Vec3d &result);
173  void MulMatScalar(const Mat3d &matrix, float scalar, Mat3d &result);
174 
175  void AddMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &matrix);
176  void AddToMat(Mat3d &matrix, const Mat3d &matrixToAdd);
177  void SubtractMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result);
178 
179  void AddVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
180  void SubtractVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
181  void AddToVec(Vec3d &vec, const Vec3d &vectorToAdd);
182  void SubtractFromVec(Vec3d &vec, const Vec3d &vectorToSubtract);
183 
184  void CrossProduct(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
185  float ScalarProduct(const Vec3d &vector1, const Vec3d &vector2);
186  float SquaredLength(const Vec3d &vec);
187  float Length(const Vec3d &vec);
188  float Distance(const Vec3d &vector1, const Vec3d &vector2);
189  float SquaredDistance(const Vec3d &vector1, const Vec3d &vector2);
190  float Angle(const Vec3d &vector1, const Vec3d &vector2);
191  float Angle(const Vec3d &vector1, const Vec3d &vector2, const Vec3d &axis);
192  float EvaluateForm(const Vec3d &matrix1, const Mat3d &matrix2); // matrix1^T * matrix2 * matrix1
193 
194  void NormalizeVec(Vec3d &vec);
195 
196  void Transpose(const Mat3d &matrix, Mat3d &result);
197  void Invert(const Mat3d &matrix, Mat3d &result);
198  float Det(const Mat3d &matrix);
199 
200  void SetTransformation(Transformation3d &transformation, const Vec3d &rotation, const Vec3d &translation);
201  void SetTransformation(Transformation3d &transformation, const Transformation3d &sourceTransformation);
202  void Invert(const Transformation3d &input, Transformation3d &result);
203  void MulTransTrans(const Transformation3d &transformation1, const Transformation3d &transformation2, Transformation3d &result);
204  void MulTransVec(const Transformation3d &transformation, const Vec3d &vec, Vec3d &result);
205 
206  void MulQuatQuat(const Quaternion &quat1, const Quaternion &quat2, Quaternion &result);
207  void RotateVecQuaternion(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result);
208  void RotateVecAngleAxis(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result);
209  void GetAxisAndAngle(const Mat3d &R, Vec3d &axis, float &angle);
210 
211  void Average(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
212 
213  void Mean(const CVec3dArray &vectorList, Vec3d &result);
214  void Mean(const Vec3d *pVectors, int nVectors, Vec3d &result);
215 
216  extern const Vec3d zero_vec;
217  extern const Mat3d unit_mat;
218  extern const Mat3d zero_mat;
219 }
220 
221 
222 
223 #endif /* _MATH_3D_H_ */
void MulVecTransposedVec(const Vec3d &vector1, const Vec3d &vector2, Mat3d &result)
Definition: Math3d.cpp:467
void RotateVec(const Vec3d &vec, const Vec3d &rotation, Vec3d &result)
Definition: Math3d.cpp:530
float SquaredLength(const Vec3d &vec)
Definition: Math3d.cpp:590
GLdouble GLdouble z
Definition: glext.h:3343
void SetVec(Vec3d &vec, const Vec3d &sourceVector)
Definition: Math3d.cpp:250
void CrossProduct(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
Definition: Math3d.cpp:564
GLuint GLenum matrix
Definition: glext.h:5683
void RotateVecQuaternion(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result)
Definition: Math3d.cpp:777
void Invert(const Transformation3d &input, Transformation3d &result)
Definition: Math3d.cpp:744
void GetAxisAndAngle(const Mat3d &R, Vec3d &axis, float &angle)
Definition: Math3d.cpp:872
void AddToMat(Mat3d &matrix, const Mat3d &matrixToAdd)
Definition: Math3d.cpp:695
void RotateVecYZX(const Vec3d &vec, const Vec3d &rotation, Vec3d &result)
Definition: Math3d.cpp:544
void Transpose(const Mat3d &matrix, Mat3d &result)
Definition: Math3d.cpp:635
float ScalarProduct(const Vec3d &vector1, const Vec3d &vector2)
Definition: Math3d.cpp:559
Vec3d translation
Definition: Math3d.h:108
void Average(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
Definition: Math3d.cpp:886
CDynamicArrayTemplate< Vec3d > CVec3dArray
Definition: Math3d.h:127
Data structure for the representation of a 3D vector.
Definition: Math3d.h:73
float x
Definition: Math3d.h:75
void SetRotationMatAxis(Mat3d &matrix, const Vec3d &axis, float theta)
Definition: Math3d.cpp:399
float Length(const Vec3d &vec)
Definition: Math3d.cpp:585
float z
Definition: Math3d.h:75
Mat3d rotation
Definition: Math3d.h:107
float Angle(const Vec3d &vector1, const Vec3d &vector2, const Vec3d &axis)
Definition: Math3d.cpp:842
Vec3d v
Definition: Math3d.h:121
std::vector< Vec3d > Vec3dList
Definition: Math3d.h:126
Data structure for the representation of a quaternion.
Definition: Math3d.h:118
GLenum GLint x
Definition: glext.h:3125
const Vec3d zero_vec
Definition: Math3d.cpp:59
void SetRotationMatZ(Mat3d &matrix, float theta)
Definition: Math3d.cpp:358
float y
Definition: Math3d.h:75
void SetRotationMatYZX(Mat3d &matrix, const Vec3d &rotation)
Definition: Math3d.cpp:327
void MulTransVec(const Transformation3d &transformation, const Vec3d &vec, Vec3d &result)
Definition: Math3d.cpp:757
void MulVecScalar(const Vec3d &vec, float scalar, Vec3d &result)
Definition: Math3d.cpp:502
float SquaredDistance(const Vec3d &vector1, const Vec3d &vector2)
Definition: Math3d.cpp:604
void SubtractMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
Definition: Math3d.cpp:708
void AddVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
Definition: Math3d.cpp:495
void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
Definition: Math3d.cpp:444
void AddToVec(Vec3d &vec, const Vec3d &vectorToAdd)
Definition: Math3d.cpp:481
void MulMatScalar(const Mat3d &matrix, float scalar, Mat3d &result)
Definition: Math3d.cpp:509
GLclampf GLclampf GLclampf alpha
Definition: glext.h:3119
float r9
Definition: Math3d.h:95
void TransformVec(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result)
Definition: Math3d.cpp:537
Efficient mathematic functions operating on the data types Vec3d, Mat3d, Transformation3d, and Quaternion.
Definition: Math3d.h:139
bool SaveToFile(const Transformation3d &transformation, const char *pFilePath)
Definition: Math3d.cpp:220
void MulQuatQuat(const Quaternion &quat1, const Quaternion &quat2, Quaternion &result)
Definition: Math3d.cpp:763
void Mean(const Vec3d *pVectors, int nVectors, Vec3d &result)
Definition: Math3d.cpp:898
void TransformVecYZX(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result)
Definition: Math3d.cpp:551
void AddMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &matrix)
Definition: Math3d.cpp:682
GLenum GLenum GLenum input
Definition: glext.h:5307
void RotateVecAngleAxis(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result)
Definition: Math3d.cpp:835
void SetRotationMatY(Mat3d &matrix, float theta)
Definition: Math3d.cpp:349
void SubtractFromVec(Vec3d &vec, const Vec3d &vectorToSubtract)
Definition: Math3d.cpp:488
void NormalizeVec(Vec3d &vec)
Definition: Math3d.cpp:573
void MulMatVec(const Mat3d &matrix, const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
Definition: Math3d.cpp:433
const Mat3d unit_mat
Definition: Math3d.cpp:60
bool LoadFromFile(Transformation3d &transformation, const char *pFilePath)
Definition: Math3d.cpp:143
GLenum GLint GLint y
Definition: glext.h:3125
float w
Definition: Math3d.h:123
float EvaluateForm(const Vec3d &matrix1, const Mat3d &matrix2)
Definition: Math3d.cpp:626
void SetTransformation(Transformation3d &transformation, const Transformation3d &sourceTransformation)
Definition: Math3d.cpp:738
void SubtractVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
Definition: Math3d.cpp:522
void SetRotationMat(Mat3d &matrix, const Vec3d &rotation)
Definition: Math3d.cpp:283
const Mat3d zero_mat
Definition: Math3d.cpp:61
float Det(const Mat3d &matrix)
Definition: Math3d.cpp:721
void SetRotationMatX(Mat3d &matrix, float theta)
Definition: Math3d.cpp:340
float Distance(const Vec3d &vector1, const Vec3d &vector2)
Definition: Math3d.cpp:595
Data structure for the representation of a 3x3 matrix.
Definition: Math3d.h:93
void MulTransTrans(const Transformation3d &transformation1, const Transformation3d &transformation2, Transformation3d &result)
Definition: Math3d.cpp:751
Data structure for the representation of a 3D rigid body transformation.
Definition: Math3d.h:105
void SetMat(Mat3d &matrix, const Mat3d &sourceMatrix)
Definition: Math3d.cpp:270


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28