51 PX_ASSERT(mSize <= MAX_VECTORN_SIZE);
59 for(PxU32 i = 0; i < src.mSize; i++)
61 mValues[i] = src.mValues[i];
68 for(PxU32 i = 0; i < src.mSize; i++)
70 mValues[i] = src.mValues[i];
92 PxF32 mValues[MAX_VECTORN_SIZE];
107 PX_ASSERT(mSize <= MAX_VECTORN_SIZE);
111 for(PxU32 i = 0; i < src.mSize; i++)
113 for(PxU32 j = 0; j < src.mSize; j++)
115 mValues[i][j] = src.mValues[i][j];
126 for(PxU32 i = 0;i < src.mSize; i++)
128 for(PxU32 j = 0;j < src.mSize; j++)
130 mValues[i][j] = src.mValues[i][j];
139 PX_ASSERT(i < mSize);
140 PX_ASSERT(j < mSize);
141 return mValues[i][j];
143 PX_FORCE_INLINE void set(
const PxU32 i,
const PxU32 j,
const PxF32 val)
145 PX_ASSERT(i < mSize);
146 PX_ASSERT(j < mSize);
154 PX_ASSERT(size <= MAX_VECTORN_SIZE);
160 PxF32 mValues[MAX_VECTORN_SIZE][MAX_VECTORN_SIZE];
181 PxU32 mP[MAX_VECTORN_SIZE-1];
182 PxU32 mQ[MAX_VECTORN_SIZE-1];
190 PxF32 getDet()
const {
return mdetM;}
194 const PxU32 D = A.mSize;
200 for (PxU32 k = 0; k < D-1; ++k)
204 float abs_pivot_elem = 0.0f;
205 for (PxU32 c = k; c < D; ++c)
207 for (PxU32 r = k; r < D; ++r)
209 const PxF32 abs_elem =
PxAbs(mLU.get(r,c));
210 if (abs_elem > abs_pivot_elem)
212 abs_pivot_elem = abs_elem;
223 for (PxU32 c = 0; c < D; ++c)
226 const PxF32 pivotrowc = mLU.get(pivot_row, c);
227 mLU.set(pivot_row, c, mLU.get(k, c));
228 mLU.set(k, c, pivotrowc);
236 for (PxU32 r = 0; r < D; ++r)
239 const PxF32 rpivotcol = mLU.get(r, pivot_col);
240 mLU.set(r,pivot_col, mLU.get(r,k));
241 mLU.set(r, k, rpivotcol);
245 mdetM *= mLU.get(k,k);
247 if (mLU.get(k,k) != 0.0f)
249 for (PxU32 r = k+1; r < D; ++r)
251 mLU.set(r, k, mLU.get(r,k) / mLU.get(k,k));
252 for (PxU32 c = k+1; c < D; ++c)
255 const PxF32 rc = mLU.get(r, c);
256 const PxF32 rk = mLU.get(r, k);
257 const PxF32 kc = mLU.get(k, c);
258 mLU.set(r, c, rc - rk*kc);
264 mdetM *= mLU.get(D-1,D-1);
274 const PxU32 D = x.getSize();
276 if((b.getSize() != x.getSize()) || (b.getSize() != mLU.getSize()) || (0.0f == mdetM))
278 for(PxU32 i = 0; i < D; i++)
288 for(PxU32 i = 0; i < D-1; ++i)
291 const PxF32 xp = x[mP[i]];
297 for (PxU32 r = 1; r < D; ++r)
299 for (PxU32 i = 0; i < r; ++i)
301 x[r] -= mLU.get(r,i)*x[i];
306 for (PxU32 r = D; r-- > 0;)
308 for (PxU32 i = r+1; i < D; ++i)
310 x[r] -= mLU.get(r,i)*x[i];
312 x[r] /= mLU.get(r,r);
316 for (PxU32 i = D-1; i-- > 0;)
319 const PxF32 xq = x[mQ[i]];
334 void solve(
const PxU32 maxIterations,
const PxF32 tolerance,
const MatrixNN& A,
const VectorN& b,
VectorN& result)
const
336 const PxU32 N = A.getSize();
339 PxF32 bLength2 = 0.0f;
340 for(PxU32 i = 0; i < N; i++)
342 DInv[i] = 1.0f/A.get(i,i);
343 bLength2 += (b[i] * b[i]);
347 PxF32 error = PX_MAX_F32;
348 while(iteration < maxIterations && tolerance < error)
350 for(PxU32 i = 0; i < N; i++)
353 for(PxU32 j = 0; j < i; j++)
355 l += A.get(i,j) * result[j];
359 for(PxU32 j = i + 1; j < N; j++)
361 u += A.get(i,j) * result[j];
364 result[i] = DInv[i] * (b[i] - l - u);
369 for(PxU32 i = 0; i < N; i++)
372 for(PxU32 j = 0; j < N; j++)
374 e += A.get(i,j) * result[j];
378 error = (rLength2 / (bLength2 + 1e-10f));
391 const PxF32 a = A_.get(0,0);
392 const PxF32 b = A_.get(0,1);
393 const PxF32 c = A_.get(0,2);
395 const PxF32 d = A_.get(1,0);
396 const PxF32 e = A_.get(1,1);
397 const PxF32 f = A_.get(1,2);
399 const PxF32 g = A_.get(2,0);
400 const PxF32 h = A_.get(2,1);
401 const PxF32 k = A_.get(2,2);
403 const PxF32 detA = a*(e*k - f*h) - b*(k*d - f*g) + c*(d*h - e*g);
408 const PxF32 detAInv = 1.0f/detA;
410 const PxF32 A = (e*k - f*h);
411 const PxF32 D = -(b*k - c*h);
412 const PxF32 G = (b*f - c*e);
413 const PxF32 B = -(d*k - f*g);
414 const PxF32 E = (a*k - c*g);
415 const PxF32 H = -(a*f - c*d);
416 const PxF32 C = (d*h - e*g);
417 const PxF32 F = -(a*h - b*g);
418 const PxF32 K = (a*e - b*d);
420 result[0] = detAInv*(A*b_[0] + D*b_[1] + G*b_[2]);
421 result[1] = detAInv*(B*b_[0] + E*b_[1] + H*b_[2]);
422 result[2] = detAInv*(C*b_[0] + F*b_[1] + K*b_[2]);
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39