Warning, file /education/gcompris/external/qml-box2d/Box2D/Common/b2Math.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002 * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org
0003 *
0004 * This software is provided 'as-is', without any express or implied
0005 * warranty.  In no event will the authors be held liable for any damages
0006 * arising from the use of this software.
0007 * Permission is granted to anyone to use this software for any purpose,
0008 * including commercial applications, and to alter it and redistribute it
0009 * freely, subject to the following restrictions:
0010 * 1. The origin of this software must not be misrepresented; you must not
0011 * claim that you wrote the original software. If you use this software
0012 * in a product, an acknowledgment in the product documentation would be
0013 * appreciated but is not required.
0014 * 2. Altered source versions must be plainly marked as such, and must not be
0015 * misrepresented as being the original software.
0016 * 3. This notice may not be removed or altered from any source distribution.
0017 */
0018 
0019 #include <Box2D/Common/b2Math.h>
0020 
0021 const b2Vec2 b2Vec2_zero(0.0f, 0.0f);
0022 
0023 /// Solve A * x = b, where b is a column vector. This is more efficient
0024 /// than computing the inverse in one-shot cases.
0025 b2Vec3 b2Mat33::Solve33(const b2Vec3& b) const
0026 {
0027     float32 det = b2Dot(ex, b2Cross(ey, ez));
0028     if (det != 0.0f)
0029     {
0030         det = 1.0f / det;
0031     }
0032     b2Vec3 x;
0033     x.x = det * b2Dot(b, b2Cross(ey, ez));
0034     x.y = det * b2Dot(ex, b2Cross(b, ez));
0035     x.z = det * b2Dot(ex, b2Cross(ey, b));
0036     return x;
0037 }
0038 
0039 /// Solve A * x = b, where b is a column vector. This is more efficient
0040 /// than computing the inverse in one-shot cases.
0041 b2Vec2 b2Mat33::Solve22(const b2Vec2& b) const
0042 {
0043     float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
0044     float32 det = a11 * a22 - a12 * a21;
0045     if (det != 0.0f)
0046     {
0047         det = 1.0f / det;
0048     }
0049     b2Vec2 x;
0050     x.x = det * (a22 * b.x - a12 * b.y);
0051     x.y = det * (a11 * b.y - a21 * b.x);
0052     return x;
0053 }
0054 
0055 ///
0056 void b2Mat33::GetInverse22(b2Mat33* M) const
0057 {
0058     float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
0059     float32 det = a * d - b * c;
0060     if (det != 0.0f)
0061     {
0062         det = 1.0f / det;
0063     }
0064 
0065     M->ex.x =  det * d; M->ey.x = -det * b; M->ex.z = 0.0f;
0066     M->ex.y = -det * c; M->ey.y =  det * a; M->ey.z = 0.0f;
0067     M->ez.x = 0.0f; M->ez.y = 0.0f; M->ez.z = 0.0f;
0068 }
0069 
0070 /// Returns the zero matrix if singular.
0071 void b2Mat33::GetSymInverse33(b2Mat33* M) const
0072 {
0073     float32 det = b2Dot(ex, b2Cross(ey, ez));
0074     if (det != 0.0f)
0075     {
0076         det = 1.0f / det;
0077     }
0078 
0079     float32 a11 = ex.x, a12 = ey.x, a13 = ez.x;
0080     float32 a22 = ey.y, a23 = ez.y;
0081     float32 a33 = ez.z;
0082 
0083     M->ex.x = det * (a22 * a33 - a23 * a23);
0084     M->ex.y = det * (a13 * a23 - a12 * a33);
0085     M->ex.z = det * (a12 * a23 - a13 * a22);
0086 
0087     M->ey.x = M->ex.y;
0088     M->ey.y = det * (a11 * a33 - a13 * a13);
0089     M->ey.z = det * (a13 * a12 - a11 * a23);
0090 
0091     M->ez.x = M->ex.z;
0092     M->ez.y = M->ey.z;
0093     M->ez.z = det * (a11 * a22 - a12 * a12);
0094 }