由旋转矩阵到Rodrigues

由Rodrigues公式有:
R = I c o s θ + ( 1 − c o s θ ) u u T + u × s i n θ R=Icos\theta+(1-cos\theta)uu^T+u_{\times}sin\theta R=Icosθ+(1cosθ)uuT+u×sinθ
其中, I c o s θ + ( 1 − c o s θ ) u u T Icos\theta+(1-cos\theta)uu^T Icosθ+(1cosθ)uuT是对称矩阵, u × s i n θ u_{\times}sin\theta u×sinθ是反对称矩阵。
所以,
R − R T = 2 u × s i n θ R-R^T = 2u_{\times}sin\theta RRT=2u×sinθ
因为 R ( n ^ , θ ) = P R ( z ^ , θ ) P − 1 R(\hat{n},\theta)=PR(\hat{z},\theta)P^{-1} R(n^,θ)=PR(z^,θ)P1,
所以 t r ( R ) = 2 c o s θ − 1 tr(R)=2cos\theta-1 tr(R)=2cosθ1
结合 ∥ R − R T ∥ = 2 s i n θ \|R-R^T\|=2sin\theta RRT=2sinθ可以求解 u 、 θ u、\theta uθ
参考代码:https://github.com/zjulion/handeyecat

Geo3d rodrigues2(const RotMat& matrix)
{
	Eigen::JacobiSVD<Eigen::Matrix3f> svd(matrix, Eigen::ComputeFullV | Eigen::ComputeFullU);
	RotMat R = svd.matrixU() * svd.matrixV().transpose();

	double rx = R(2, 1) - R(1, 2);
	double ry = R(0, 2) - R(2, 0);
	double rz = R(1, 0) - R(0, 1);

	double s = sqrt((rx*rx + ry*ry + rz*rz)*0.25);
	double c = (R.trace() - 1) * 0.5; //c=cos(theta)
	c = c > 1. ? 1. : c < -1. ? -1. : c;

	double theta = acos(c);

	if (s < XEPS)//sin s =0
	{
		double t;

		if (c > 0) //cos s=1
			rx = ry = rz = 0;
		else
		{
			t = (R( 0, 0) + 1)*0.5;
			rx = sqrt(std::max(t, 0.0));
			t = (R(1, 1) + 1)*0.5;
			ry = sqrt(std::max(t, 0.0)) * (R(0, 1) < 0 ? -1.0 : 1.0);
			t = (R(2, 2) + 1)*0.5;
			rz = sqrt(std::max(t, 0.0)) * (R(0, 2) < 0 ? -1.0 : 1.0);

			if (fabs(rx) < fabs(ry) && fabs(rx) < fabs(rz) && (R(1, 2) > 0) != (ry*rz > 0))//这里不懂
				rz = -rz;
			theta /= sqrt(rx*rx + ry*ry + rz*rz);
			rx *= theta;
			ry *= theta;
			rz *= theta;
		}
	}
	else
	{
		double vth = 1 / (2 * s);
		vth *= theta;
		rx *= vth; ry *= vth; rz *= vth;
	}
	return Eigen::Vector3d(rx, ry, rz).cast<float>();
}

参考源:
https://www2.cs.duke.edu/courses/fall13/compsci527/notes/rodrigues.pdf
http://web.cs.iastate.edu/~cs577/handouts/rotation.pdf

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值