Math3d.h
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  Math3d.h
00037 // Author:    Pedram Azad
00038 // Date:      2004
00039 // ****************************************************************************
00040 
00041 
00042 #ifndef _MATH_3D_H_
00043 #define _MATH_3D_H_
00044 
00045 
00046 // ****************************************************************************
00047 // Necessary includes
00048 // ****************************************************************************
00049 
00050 #include <vector>
00051 #include "DataStructures/DynamicArrayTemplate.h"
00052 
00053 
00054 // ****************************************************************************
00055 // Structs and typedefs
00056 // ****************************************************************************
00057 
00073 struct Vec3d
00074 {
00075         float x, y, z;
00076 };
00077 
00093 struct Mat3d
00094 {
00095         float r1, r2, r3, r4, r5, r6, r7, r8, r9;
00096 };
00097 
00105 struct Transformation3d
00106 {
00107         Mat3d rotation;
00108         Vec3d translation;
00109 };
00110 
00118 struct Quaternion
00119 {
00121         Vec3d v;
00123         float w;
00124 };
00125 
00126 typedef std::vector<Vec3d> Vec3dList;
00127 typedef CDynamicArrayTemplate<Vec3d> CVec3dArray;
00128 
00129 
00130 
00131 // ****************************************************************************
00132 // Math3d
00133 // ****************************************************************************
00134 
00139 namespace Math3d
00140 {
00141         bool LoadFromFile(Vec3d &vector, const char *pFilePath);
00142         bool LoadFromFile(Mat3d &matrix, const char *pFilePath);
00143         bool LoadFromFile(Transformation3d &transformation, const char *pFilePath);
00144         bool SaveToFile(const Vec3d &vector, const char *pFilePath);
00145         bool SaveToFile(const Mat3d &matrix, const char *pFilePath);
00146         bool SaveToFile(const Transformation3d &transformation, const char *pFilePath);
00147         
00148         void SetVec(Vec3d &vec, float x, float y, float z);
00149         void SetVec(Vec3d &vec, const Vec3d &sourceVector);
00150         void SetMat(Mat3d &matrix, float r1, float r2, float r3, float r4, float r5, float r6, float r7, float r8, float r9);
00151         void SetMat(Mat3d &matrix, const Mat3d &sourceMatrix);
00152         void SetRotationMat(Mat3d &matrix, const Vec3d &axis, float theta);
00153         void SetRotationMat(Mat3d &matrix, float alpha, float beta, float gamma);
00154         void SetRotationMat(Mat3d &matrix, const Vec3d &rotation);
00155         void SetRotationMatYZX(Mat3d &matrix, const Vec3d &rotation);
00156         void SetRotationMatX(Mat3d &matrix, float theta);
00157         void SetRotationMatY(Mat3d &matrix, float theta);
00158         void SetRotationMatZ(Mat3d &matrix, float theta);
00159         void SetRotationMatAxis(Mat3d &matrix, const Vec3d &axis, float theta);
00160 
00161         void MulMatVec(const Mat3d &matrix, const Vec3d &vec, Vec3d &result);
00162         void MulMatVec(const Mat3d &matrix, const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
00163         void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result);
00164 
00165         void MulVecTransposedVec(const Vec3d &vector1, const Vec3d &vector2, Mat3d &result);
00166         
00167         void RotateVec(const Vec3d &vec, const Vec3d &rotation, Vec3d &result);
00168         void RotateVecYZX(const Vec3d &vec, const Vec3d &rotation, Vec3d &result);
00169         void TransformVec(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result);
00170         void TransformVecYZX(const Vec3d &vec, const Vec3d &rotation, const Vec3d &translation, Vec3d &result);
00171         
00172         void MulVecScalar(const Vec3d &vec, float scalar, Vec3d &result);
00173         void MulMatScalar(const Mat3d &matrix, float scalar, Mat3d &result);
00174 
00175         void AddMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &matrix);
00176         void AddToMat(Mat3d &matrix, const Mat3d &matrixToAdd);
00177         void SubtractMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result);
00178                 
00179         void AddVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
00180         void SubtractVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
00181         void AddToVec(Vec3d &vec, const Vec3d &vectorToAdd);
00182         void SubtractFromVec(Vec3d &vec, const Vec3d &vectorToSubtract);
00183         
00184         void CrossProduct(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
00185         float ScalarProduct(const Vec3d &vector1, const Vec3d &vector2);
00186         float SquaredLength(const Vec3d &vec);
00187         float Length(const Vec3d &vec);
00188         float Distance(const Vec3d &vector1, const Vec3d &vector2);
00189         float SquaredDistance(const Vec3d &vector1, const Vec3d &vector2);
00190         float Angle(const Vec3d &vector1, const Vec3d &vector2);
00191         float Angle(const Vec3d &vector1, const Vec3d &vector2, const Vec3d &axis);
00192         float EvaluateForm(const Vec3d &matrix1, const Mat3d &matrix2); // matrix1^T * matrix2 * matrix1
00193         
00194         void NormalizeVec(Vec3d &vec);
00195         
00196         void Transpose(const Mat3d &matrix, Mat3d &result);
00197         void Invert(const Mat3d &matrix, Mat3d &result);
00198         float Det(const Mat3d &matrix);
00199 
00200         void SetTransformation(Transformation3d &transformation, const Vec3d &rotation, const Vec3d &translation);
00201         void SetTransformation(Transformation3d &transformation, const Transformation3d &sourceTransformation);
00202         void Invert(const Transformation3d &input, Transformation3d &result);
00203         void MulTransTrans(const Transformation3d &transformation1, const Transformation3d &transformation2, Transformation3d &result);
00204         void MulTransVec(const Transformation3d &transformation, const Vec3d &vec, Vec3d &result);
00205 
00206         void MulQuatQuat(const Quaternion &quat1, const Quaternion &quat2, Quaternion &result);
00207         void RotateVecQuaternion(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result);
00208         void RotateVecAngleAxis(const Vec3d &vec, const Vec3d &axis, float theta, Vec3d &result);
00209         void GetAxisAndAngle(const Mat3d &R, Vec3d &axis, float &angle);
00210 
00211         void Average(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result);
00212 
00213         void Mean(const CVec3dArray &vectorList, Vec3d &result);
00214         void Mean(const Vec3d *pVectors, int nVectors, Vec3d &result);
00215 
00216         extern const Vec3d zero_vec;
00217         extern const Mat3d unit_mat;
00218         extern const Mat3d zero_mat;
00219 }
00220 
00221 
00222 
00223 #endif /* _MATH_3D_H_ */


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:57