C_and_CPP 板


LINE

开发平台(Platform): (Ex: Win10, Linux, ...) win10 编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出) C++ 额外使用到的函数库(Library Used): (Ex: OpenGL, ...) eigen 问题(Question): 各位前辈好 小弟我目前想要计算空间中的转换矩阵 A(Xa,Ya,Za)为某S面的中心点 B(Xb,Yb,Zb)为某W面的中心点 S面与W面有固定的位置关系 S面经过旋转及平移後的中心位置为A'(Xa',Ya',Za') 我的计算方式是 先将 旋转平移後S面的角度(单位:度) 减去 S面原先的角度 => 得到的尤拉角计算出旋转矩阵 再将原本A(Xa,Ya,Za) 乘上 旋转矩阵 得到 A旋转完後的座标 再取 A' 点减此座标 得到平移矩阵 将平移矩阵与旋转矩阵合并乘 转换矩阵 再将B乘上转换矩阵 得到W面在相同旋转平移後B'的座标 不过得到的座标B'不太正确 想请教各位前辈 是不是小弟我逻辑上有错误 程式码的部分整理好後附上 喂入的资料(Input): A(7.48116 , -16.723 , 1237.61) S面夹角(-1.4951 ,0.440311 ,-151.567) A'(71.769 , -17.6274, 12341.06) S'面夹角(-0.166662 ,1.80244 ,-151.815) B(26.05982 ,-16.57224, 1236.45) W面夹角(1.536868 ,1.711784 ,-150.7084) 预期的正确结果(Expected Output): B'(90.4556, -17.1076 , 1241.89) W'面颊角(2.25271 ,2.95927, -151.271) 计算完可能会有误差,容许范围0.02或更小 错误结果(Wrong Output): 程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档) #include <iostream> #include <eigen/Eigen> #include <math.h> typedef Eigen::Matrix<double, 3, 3> Matrix3d; typedef Eigen::Matrix<double, 4, 4> Matrix4d; typedef Eigen::Matrix<double, 4, 1> Vector4d; typedef struct _Pose { double x; double y; double z; double rx; double ry; double rz; }POSE; POSE GetFinalPose( POSE prePos_X, POSE Pos_X , POSE currentPose_Y) { double angleX, angleY, angleZ; //计算角度差 同一平面 angleX = Pos_X.rx - prePos_X.rx; angleY = Pos_X.ry - prePos_X.ry; angleZ = Pos_X.rz - prePos_X.rz; Matrix4d _Rotation; //得到旋转矩阵 _Rotation(0, 0) = cos(angleZ) * cos(angleY); _Rotation(0, 1) = cos(angleZ) * sin(angleX) * sin(angleY) - cos(angleX) * sin(angleZ); _Rotation(0, 2) = sin(angleZ) * sin(angleX) + cos(angleZ) * cos(angleX) * sin(angleY); _Rotation(0, 3) = 0; _Rotation(1, 0) = cos(angleY) * sin(angleZ); _Rotation(1, 1) = cos(angleZ) * cos(angleX) + sin(angleZ) * sin(angleX) * sin(angleY); _Rotation(1, 2) = cos(angleX) * sin(angleZ) * sin(angleY) - cos(angleZ) * sin(angleX); _Rotation(1, 3) = 0; _Rotation(2, 0) = -sin(angleY); _Rotation(2, 1) = cos(angleY) * sin(angleX); _Rotation(2, 2) = cos(angleX) * cos(angleY); _Rotation(2, 3) = 0; _Rotation(3, 0) = 0; _Rotation(3, 1) = 0; _Rotation(3, 2) = 0; _Rotation(3, 3) = 1; + //设置位置 Vector4d _Position; _Position(0, 0) = prePos_X.x; _Position(1, 0) = prePos_X.y; _Position(2, 0) = prePos_X.z; _Position(3, 0) = 1; //得到平移矩阵 R*t Vector4d _Translation; _Translation = _Rotation * _Position; //计算平移差距 _Translation(0, 0) = Pos_X.x - _Translation(0, 0) ; _Translation(1, 0) = Pos_X.y - _Translation(1, 0); _Translation(2, 0) = Pos_X.z - _Translation(2, 0); _Translation(3, 0) = 1; std::cout << _Translation << std::endl; //得到转换矩阵 _Rotation.block<4, 1>(0, 3) = _Translation; std::cout << _Rotation << std::endl; //点 _Position(0, 0) = currentPose_Y.x; _Position(1, 0) = currentPose_Y.y; _Position(2, 0) = currentPose_Y.z; _Position(3, 0) = 1; //计算 点*转换矩阵 _Translation = _Rotation * _Position; POSE calPose; calPose.x = _Translation(0, 0); calPose.y = _Translation(1, 0); calPose.z = _Translation(2, 0); return calPose; } 补充说明(Supplement): --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.173.140.59 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1583942146.A.9D3.html
1F:推 Schottky: 是。请不要用这麽浪漫的描述方式,写成算式就知道错在哪 03/12 01:42
2F:→ Schottky: 具体的说,什麽叫 "平移矩阵与旋转矩阵合并乘 转换矩阵" 03/12 01:43
3F:→ Schottky: 旋转的时候请注意旋转中心在哪,你这样转,中心是原点 03/12 01:47
4F:→ wtchen: 请补程式码喔 03/12 21:34
5F:推 j0958322080: 补个算式啊 03/12 22:04
补上程式码罗 因为角度的部分还在思考怎麽计算 所以这里只有位置的部分 ※ 编辑: asdfg1597860 (218.173.140.59 台湾), 03/12/2020 22:07:36 ※ 编辑: asdfg1597860 (218.173.140.59 台湾), 03/12/2020 22:16:41







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP