一个点在不同坐标系下的表示练习

引用地址:https://github.com/cckaixin/Practical_Homework_for_slambook14

推荐自己下载写一下。

问题描述:

有两个右手系1和2,其中2系的x轴与1系的y轴方向相同,2系的y轴与1系z轴方向相反,2系的z轴与1系的x轴相反,两个坐标系原点重合,求R12,求1系中(1,1,1)在2系中的坐标。请自己编写一个c++程序实现它,并用Cmake编译,得到能输出答案的可执行文件。

我的代码:

#include <iostream>
#include <Eigen/Core>
#include <Eigen/Geometry>
#define PI 3.14159265358979323846

int main(int argc, char const *argv[])
{
    //hint 1: Find the Euler Angle from Frame1 to Frame2
    double roll = -PI / 2;
    double pitch = -PI / 2;
    double yaw = 0;
    //hint 2: Convert the Euler Angle into the rotation matrix
    Eigen::AngleAxisd rollRotation(roll, Eigen::Vector3d::UnitX());
    Eigen::AngleAxisd pitchRotation(pitch, Eigen::Vector3d::UnitY());
    Eigen::AngleAxisd yawRotation(yaw, Eigen::Vector3d::UnitZ());
    Eigen::Matrix3d rotation_matrix = rollRotation.toRotationMatrix()*pitchRotation.toRotationMatrix()*yawRotation.toRotationMatrix();
    // hint 3: Try to convert a known point under the Frame1, like (1,1,1), to Frame2 using the rotation matrix,
    //         and then you can check if your answer is correct intuitively. (The answer is (1, -1, -1))
    Eigen::Vector3d point1(1, 1, 1);
    Eigen::Vector3d point2;
    point2 = rotation_matrix.inverse() * point1;
    std::cout << point2 << std::endl;
    return 0;
}

作者代码请自己在下载的文件中浏览。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值