|
|
@ -5,43 +5,49 @@ |
|
|
|
|
|
|
|
int main() { |
|
|
|
|
|
|
|
GVector3 v1(SQRT(2)/2, SQRT(2) / 2, 0); |
|
|
|
GVector3 v2(-1, 1, -1); |
|
|
|
GVector3 v3(0, -2, -2); |
|
|
|
|
|
|
|
//斯密特正交化
|
|
|
|
GVector3 w1 = v1; |
|
|
|
GVector3 w2 = v2 - proj(v2, w1); //cout << w2 << endl;
|
|
|
|
GVector3 w3 = v3 - proj(v3, w1) - proj(v3, w2); //cout << w3 << endl;
|
|
|
|
/*
|
|
|
|
matrix P = (p1, p2, p3, ......, pn) |
|
|
|
matrix A; |
|
|
|
A * P = (A*p1, A*p2, A*p3, ......, A*pn) |
|
|
|
*/ |
|
|
|
float a[] = { |
|
|
|
3, -1, 0, |
|
|
|
4, -1, 0, |
|
|
|
-1, 0, 0 |
|
|
|
}; |
|
|
|
GMatrix A(3, 3, a); |
|
|
|
|
|
|
|
//normalize
|
|
|
|
w1 = w1 / norm(w1); |
|
|
|
w2 = w2 / norm(w2); |
|
|
|
w3 = w3 / norm(w3); |
|
|
|
float p[] = { |
|
|
|
1, 2, 3, |
|
|
|
1, 2, 3, |
|
|
|
1, 2, 3 |
|
|
|
}; |
|
|
|
GMatrix P(3, 3, p); |
|
|
|
|
|
|
|
GMatrix M1(3, 3); |
|
|
|
M1.SetRowVec(0, w1); |
|
|
|
M1.SetRowVec(1, w2); |
|
|
|
M1.SetRowVec(2, w3); |
|
|
|
cout << M1 << endl; |
|
|
|
//模拟P矩阵的第二列
|
|
|
|
float x[] = { |
|
|
|
2, |
|
|
|
2, |
|
|
|
2 |
|
|
|
}; |
|
|
|
GMatrix X(3, 1, x); |
|
|
|
|
|
|
|
GMatrix M2 = Transpose(M1); |
|
|
|
cout << M2 << endl; |
|
|
|
cout << A * P << endl; |
|
|
|
cout << A * X << endl; |
|
|
|
|
|
|
|
cout << Det(M1) * Det(M2) << endl; |
|
|
|
/*
|
|
|
|
matrix P = (p1, p2, p3, ......, pn) |
|
|
|
vector v = (v1, v2, v3, ......, vn) |
|
|
|
|
|
|
|
float a[] = { |
|
|
|
1, 2, 3, |
|
|
|
3, 1, 2, |
|
|
|
2, 3, 1 |
|
|
|
}; |
|
|
|
GMatrix M3(3, 3, a); |
|
|
|
P * V = (p1 * v1) + (p2 * v2) + (p3 * v3) + ...... + (pn * vn) |
|
|
|
*/ |
|
|
|
GVector c1 = A.GetColVec(0); |
|
|
|
GVector c2 = A.GetColVec(1); |
|
|
|
GVector c3 = A.GetColVec(2); |
|
|
|
|
|
|
|
GMatrix M4 = Inverse(M3); |
|
|
|
GVector ret = c1 * X[0][0] + c2 * X[1][0] + c3 * X[2][0]; |
|
|
|
cout << ret << endl; |
|
|
|
|
|
|
|
cout << M3 << endl; |
|
|
|
cout << M4 << endl; |
|
|
|
|
|
|
|
cout << Det(M3) * Det(M4) << endl; |
|
|
|
return 0; |
|
|
|
} |