b2_math.cpp
Go to the documentation of this file.
1 // MIT License
2 
3 // Copyright (c) 2019 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #include "box2d/b2_math.h"
24 
25 const b2Vec2 b2Vec2_zero(0.0f, 0.0f);
26 
30 {
31  float det = b2Dot(ex, b2Cross(ey, ez));
32  if (det != 0.0f)
33  {
34  det = 1.0f / det;
35  }
36  b2Vec3 x;
37  x.x = det * b2Dot(b, b2Cross(ey, ez));
38  x.y = det * b2Dot(ex, b2Cross(b, ez));
39  x.z = det * b2Dot(ex, b2Cross(ey, b));
40  return x;
41 }
42 
46 {
47  float a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
48  float det = a11 * a22 - a12 * a21;
49  if (det != 0.0f)
50  {
51  det = 1.0f / det;
52  }
53  b2Vec2 x;
54  x.x = det * (a22 * b.x - a12 * b.y);
55  x.y = det * (a11 * b.y - a21 * b.x);
56  return x;
57 }
58 
61 {
62  float a = ex.x, b = ey.x, c = ex.y, d = ey.y;
63  float det = a * d - b * c;
64  if (det != 0.0f)
65  {
66  det = 1.0f / det;
67  }
68 
69  M->ex.x = det * d; M->ey.x = -det * b; M->ex.z = 0.0f;
70  M->ex.y = -det * c; M->ey.y = det * a; M->ey.z = 0.0f;
71  M->ez.x = 0.0f; M->ez.y = 0.0f; M->ez.z = 0.0f;
72 }
73 
76 {
77  float det = b2Dot(ex, b2Cross(ey, ez));
78  if (det != 0.0f)
79  {
80  det = 1.0f / det;
81  }
82 
83  float a11 = ex.x, a12 = ey.x, a13 = ez.x;
84  float a22 = ey.y, a23 = ez.y;
85  float a33 = ez.z;
86 
87  M->ex.x = det * (a22 * a33 - a23 * a23);
88  M->ex.y = det * (a13 * a23 - a12 * a33);
89  M->ex.z = det * (a12 * a23 - a13 * a22);
90 
91  M->ey.x = M->ex.y;
92  M->ey.y = det * (a11 * a33 - a13 * a13);
93  M->ey.z = det * (a13 * a12 - a11 * a23);
94 
95  M->ez.x = M->ex.z;
96  M->ez.y = M->ey.z;
97  M->ez.z = det * (a11 * a22 - a12 * a12);
98 }
d
float z
Definition: b2_math.h:167
b2Vec3 ex
Definition: b2_math.h:283
float b2Dot(const b2Vec2 &a, const b2Vec2 &b)
Perform the dot product on two vectors.
Definition: b2_math.h:395
f
float x
Definition: b2_math.h:128
float y
Definition: b2_math.h:128
b2Vec3 ez
Definition: b2_math.h:283
A 2D column vector.
Definition: b2_math.h:41
void GetSymInverse33(b2Mat33 *M) const
Returns the zero matrix if singular.
Definition: b2_math.cpp:75
A 2D column vector with 3 elements.
Definition: b2_math.h:132
b2Vec3 ey
Definition: b2_math.h:283
const b2Vec2 b2Vec2_zero(0.0f, 0.0f)
Useful constant.
float b2Cross(const b2Vec2 &a, const b2Vec2 &b)
Perform the cross product on two vectors. In 2D this produces a scalar.
Definition: b2_math.h:401
b2Vec3 Solve33(const b2Vec3 &b) const
Definition: b2_math.cpp:29
float y
Definition: b2_math.h:167
A 3-by-3 matrix. Stored in column-major order.
Definition: b2_math.h:245
float x
Definition: b2_math.h:167
b2Vec2 Solve22(const b2Vec2 &b) const
Definition: b2_math.cpp:45
void GetInverse22(b2Mat33 *M) const
Definition: b2_math.cpp:60


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:19