IVT
Math2d.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: Math2d.h
37 // Author: Pedram Azad
38 // Date: 2005
39 // ****************************************************************************
40 
41 
42 #ifndef _MATH_2D_H_
43 #define _MATH_2D_H_
44 
45 
46 // ****************************************************************************
47 // Necessary includes
48 // ****************************************************************************
49 
51 
52 // system
53 #include <vector>
54 
55 
56 // ****************************************************************************
57 // Forward declarations
58 // ****************************************************************************
59 
60 struct Mat3d;
61 struct Rectangle2d;
62 
63 
64 // ****************************************************************************
65 // Structs and typedefs
66 // ****************************************************************************
67 
82 struct Vec2d
83 {
84  float x, y;
85 };
86 
101 struct Mat2d
102 {
103  float r1, r2, r3, r4;
104 };
105 
106 typedef std::vector<Vec2d> Vec2dList;
108 
109 
110 
111 // ****************************************************************************
112 // Math2d
113 // ****************************************************************************
114 
119 namespace Math2d
120 {
121  void SetVec(Vec2d &vec, float x, float y);
122  void SetVec(Vec2d &vec, const Vec2d &sourceVector);
123 
124  void SetRotationMat(Mat2d &matrix, float angle);
125 
126  void MulMatMat(const Mat2d &matrix1, const Mat2d &matrix2, Mat2d &result);
127  void MulMatVec(const Mat2d &matrix, const Vec2d &vec, Vec2d &result);
128  void MulMatVec(const Mat2d &matrix, const Vec2d &vector1, const Vec2d &vector2, Vec2d &result);
129  void MulMatScalar(const Mat2d &matrix, float scalar, Mat2d &result);
130 
131  void MulVecScalar(const Vec2d &vec, float scalar, Vec2d &result);
132 
133  void RotateVec(const Vec2d &vec, float angle, Vec2d &result);
134  void RotateVec(const Vec2d &point, const Vec2d &center, float angle, Vec2d &result);
135 
136  void AddVecVec(const Vec2d &vector1, const Vec2d &vector2, Vec2d &result);
137  void SubtractVecVec(const Vec2d &vector1, const Vec2d &vector2, Vec2d &result);
138  void AddToVec(Vec2d &vec, const Vec2d &vectorToAdd);
139  void SubtractFromVec(Vec2d &vec, const Vec2d &vectorToSubtract);
140 
141  float ScalarProduct(const Vec2d &vector1, const Vec2d &vector2);
142  float SquaredLength(const Vec2d &vec);
143  float Length(const Vec2d &vec);
144  float Distance(const Vec2d &vector1, const Vec2d &vector2);
145  float SquaredDistance(const Vec2d &vector1, const Vec2d &vector2);
146  float Angle(const Vec2d &vector1, const Vec2d &vector2);
147 
148  void Transpose(const Mat2d &matrix, Mat2d &result);
149  void Invert(const Mat2d &matrix, Mat2d &result);
150 
151  void NormalizeVec(Vec2d &vec);
152 
153  void ApplyHomography(const Mat3d &A, const Vec2d &p, Vec2d &result);
154 
155  void Average(const Vec2d &vector1, const Vec2d &vector2, Vec2d &result);
156 
157  void Mean(const CVec2dArray &vectorList, Vec2d &result);
158  void Mean(const Vec2d *pVectors, int nVectors, Vec2d &result);
159 
160  void ComputeRectangleCornerPoints(const Rectangle2d &rectangle, Vec2d resultCornerPoints[4]);
161 
162  extern const Vec2d zero_vec;
163 }
164 
165 
166 
167 #endif /* _MATH_2D_H_ */
float r4
Definition: Math2d.h:103
void Average(const Vec2d &vector1, const Vec2d &vector2, Vec2d &result)
Definition: Math2d.cpp:267
void ApplyHomography(const Mat3d &A, const Vec2d &p, Vec2d &result)
Definition: Math2d.cpp:253
Data structure for the representation of a 2D vector.
Definition: Math2d.h:82
float r1
Definition: Math2d.h:103
float Angle(const Vec2d &vector1, const Vec2d &vector2)
Definition: Math2d.cpp:197
void SubtractVecVec(const Vec2d &vector1, const Vec2d &vector2, Vec2d &result)
Definition: Math2d.cpp:148
void MulMatScalar(const Mat2d &matrix, float scalar, Mat2d &result)
Definition: Math2d.cpp:109
float SquaredLength(const Vec2d &vec)
Definition: Math2d.cpp:176
void NormalizeVec(Vec2d &vec)
Definition: Math2d.cpp:160
float x
Definition: Math2d.h:84
float r3
Definition: Math2d.h:103
float SquaredDistance(const Vec2d &vector1, const Vec2d &vector2)
Definition: Math2d.cpp:189
CDynamicArrayTemplate< Vec2d > CVec2dArray
Definition: Math2d.h:107
float r2
Definition: Math2d.h:103
Data structure for the representation of a 2x2 matrix.
Definition: Math2d.h:101
void Invert(const Mat2d &matrix, Mat2d &result)
Definition: Math2d.cpp:238
float y
Definition: Math2d.h:84
float ScalarProduct(const Vec2d &vector1, const Vec2d &vector2)
Definition: Math2d.cpp:155
void SubtractFromVec(Vec2d &vec, const Vec2d &vectorToSubtract)
Definition: Math2d.cpp:87
float Length(const Vec2d &vec)
Definition: Math2d.cpp:171
void SetRotationMat(Mat2d &matrix, float angle)
Definition: Math2d.cpp:99
void Mean(const CVec2dArray &vectorList, Vec2d &result)
Definition: Math2d.cpp:273
void MulVecScalar(const Vec2d &vec, float scalar, Vec2d &result)
Definition: Math2d.cpp:142
Data structure for the representation of a 2D rectangle.
Definition: Structs.h:89
void MulMatMat(const Mat2d &matrix1, const Mat2d &matrix2, Mat2d &result)
Definition: Math2d.cpp:117
void RotateVec(const Vec2d &vec, float angle, Vec2d &result)
Definition: Math2d.cpp:206
const Vec2d zero_vec
Definition: Math2d.cpp:61
std::vector< Vec2d > Vec2dList
Definition: Math2d.h:106
void MulMatVec(const Mat2d &matrix, const Vec2d &vec, Vec2d &result)
Definition: Math2d.cpp:128
void Transpose(const Mat2d &matrix, Mat2d &result)
Definition: Math2d.cpp:228
float Distance(const Vec2d &vector1, const Vec2d &vector2)
Definition: Math2d.cpp:181
void AddVecVec(const Vec2d &vector1, const Vec2d &vector2, Vec2d &result)
Definition: Math2d.cpp:93
Data structure for the representation of a 3x3 matrix.
Definition: Math3d.h:93
void SetVec(Vec2d &vec, float x, float y)
Definition: Math2d.cpp:68
void ComputeRectangleCornerPoints(const Rectangle2d &rectangle, Vec2d resultCornerPoints[4])
Definition: Math2d.cpp:298
void AddToVec(Vec2d &vec, const Vec2d &vectorToAdd)
Definition: Math2d.cpp:81