Skip to content

Commit 0ab5f85

Browse files
committed
d
1 parent ece53ee commit 0ab5f85

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

glomap/math/gravity.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@ namespace glomap {
99

1010
// The second col of R_align is gravity direction
1111
Eigen::Matrix3d GetAlignRot(const Eigen::Vector3d& gravity) {
12-
return Eigen::Quaterniond::FromTwoVectors(Eigen::Vector3d(0, 1, 0), gravity)
13-
.toRotationMatrix();
12+
Eigen::Matrix3d R;
13+
Eigen::Vector3d v = gravity.normalized();
14+
R.col(1) = v;
15+
16+
Eigen::Matrix3d Q = v.householderQr().householderQ();
17+
Eigen::Matrix<double, 3, 2> N = Q.rightCols(2);
18+
R.col(0) = N.col(0);
19+
R.col(2) = N.col(1);
20+
if (R.determinant() < 0) {
21+
R.col(2) = -R.col(2);
22+
}
23+
return R;
1424
}
1525

1626
double RotUpToAngle(const Eigen::Matrix3d& R_up) {

0 commit comments

Comments
 (0)