简体   繁体   English

将世界转换为对象坐标

[英]Convert world to object coordinates

The iPhone gyroscope receives rotation data relative to some reference attitude and it doesn't change (unless multiplied.) Lets say I face the wall using my iPhone camera, and rotate 45 degrees left ( roll += PI/4 .) iPhone陀螺仪接收相对于某个参考姿态的旋转数据,并且旋转不变(除非相乘)。可以说,我使用iPhone相机面对墙壁,并向左旋转45度( roll += PI/4

Now, if I lift the phone towards the ceiling, both yaw and pitch change since the coordinate space is fixed (world coordinate space, doesn't move or rotate with the phone.) Is there a way to determine this angle (the one between the floor plane and the camera direction vector), roll, yaw and pitch given? 现在,如果我将手机抬到天花板上,则偏航和俯仰都会改变,因为坐标空间是固定的(世界坐标空间,不会随手机移动或旋转。)是否可以确定该角度(地板平面和相机方向向量),横摇,偏航和俯仰?

Edit: Instead of opening another question I'll try here. 编辑:而不是打开另一个问题,我将在这里尝试。 Luc's solution works. 吕克的解决方案有效。 But how to get the other two angles of rotation? 但是如何获得其他两个旋转角度呢? I've read the info on the posted link but it's been years since I studied linear algebra. 我已经阅读了发布的链接上的信息,但是学习线性代数已经有好几年了。 This might be more math than a programming question, actually. 实际上,这可能比编程问题还要数学。

I don't really code for iPhone so I'll trust you on the "real world coordinates" frame. 我不是真的为iPhone编写代码,所以我会在“真实世界坐标”框架上信任您。

In that case, you want the dot product between both z-axis' vectors. 在这种情况下,您需要两个z轴向量之间的点积。 That'll give you the cosine of the angle you're looking for, pretty close thus. 这将为您提供所需角度的余弦,因此非常接近。 Since an angle between planes only really makes sense as a value between and 90° , you actually have all the information you need in that cosine. 由于平面之间的角度只有在90°之间的值才有意义,因此您实际上拥有该余弦中所需的所有信息。

And there is no latex formatting here, otherwise I'd go into a bit more of detail, but read this page if you're interested, I'll just include the final result here, the rotation matrix for your three rotations : 而且这里没有乳胶格式,否则我会更详细一些,但是如果您感兴趣,请阅读此页面 ,我将在此处包括最终结果,即三个旋转的旋转矩阵: 旋转矩阵

Now the z-axis' vector of the horizontal plan is (0,0,1) (read this as a vertical vector though) and rotated with this matrix, you simply get its third column. 现在,水平平面的z轴矢量为(0,0,1) (尽管将其作为垂直矢量读取)并随此矩阵旋转,您只需获得其第三列即可。

So we want to have the dot product between that third column and our (0,0,1) vector, so you get cos(β)cos(γ) which is cos(pitch)*cos(roll) 因此,我们希望在第三列和我们的(0,0,1)向量之间具有点积,因此得到的cos(β)cos(γ)cos(pitch)*cos(roll)

In conclusion, the angle between your plans is arccos(cos(pitch)*cos(roll)) . 总之,您的计划之间的夹角是arccos(cos(pitch)*cos(roll)) This value will tell you how much your iPhone is inclined, not in which direction of course. 此值将告诉您iPhone倾斜了多少,而不是向哪个方向倾斜。 But you can work that out from the values of the vector (rightmost column of the matrix) we spoke of. 但是您可以根据我们所说的向量(矩阵的最右列)的值来进行计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM