File indexing completed on 2025-06-01 03:50:40
0001 /* 0002 * Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com 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 const b2Mat22 b2Mat22_identity(1.0f, 0.0f, 0.0f, 1.0f); 0023 const b2Transform b2Transform_identity(b2Vec2_zero, b2Mat22_identity); 0024 0025 /// Solve A * x = b, where b is a column vector. This is more efficient 0026 /// than computing the inverse in one-shot cases. 0027 b2Vec3 b2Mat33::Solve33(const b2Vec3& b) const 0028 { 0029 qreal det = b2Dot(col1, b2Cross(col2, col3)); 0030 if (det != 0.0f) 0031 { 0032 det = 1.0f / det; 0033 } 0034 b2Vec3 x; 0035 x.x = det * b2Dot(b, b2Cross(col2, col3)); 0036 x.y = det * b2Dot(col1, b2Cross(b, col3)); 0037 x.z = det * b2Dot(col1, b2Cross(col2, b)); 0038 return x; 0039 } 0040 0041 /// Solve A * x = b, where b is a column vector. This is more efficient 0042 /// than computing the inverse in one-shot cases. 0043 b2Vec2 b2Mat33::Solve22(const b2Vec2& b) const 0044 { 0045 qreal a11 = col1.x, a12 = col2.x, a21 = col1.y, a22 = col2.y; 0046 qreal det = a11 * a22 - a12 * a21; 0047 if (det != 0.0f) 0048 { 0049 det = 1.0f / det; 0050 } 0051 b2Vec2 x; 0052 x.x = det * (a22 * b.x - a12 * b.y); 0053 x.y = det * (a11 * b.y - a21 * b.x); 0054 return x; 0055 }