简体   繁体   English

欧拉角 Y 值受 X 和 Z 值的影响 - 如何将它们归零以获得“真实”的 y 值?

[英]Euler Angles Y value is affected by X and Z values - how do I zero them out to get a "truthful" y value?

The effect I'm trying to achieve is to have an arrow pointed out from the camera's pointOfView position, aligned with the scene (and gravity) on the x and z axis, but pointing in the same direction as the camera.我试图实现的效果是从相机的pointOfView位置指向一个箭头,在 x 和 z 轴上与场景(和重力)对齐,但指向与相机相同的方向。 It might look something like this:它可能看起来像这样:

在此处输入图片说明

Right now, I have its euler angles x and z set to 0 , and it's y set to match that of the ARSCNView.pointOfView.eulerAngles.y .现在,我将其欧拉角xz设置为0 ,并将y设置为与ARSCNView.pointOfView.eulerAngles.y欧拉角相匹配。 The problem is that as I rotate the device, the eulerAngles.y can end up having the same value for different points.问题是,当我旋转设备时, eulerAngles.y最终可能eulerAngles.y不同的点具有相同的值。 For example, facing the device in one direction, my eulerAngles are:例如,面向一个方向的设备,我的eulerAngles是:

x: 2.52045, y: -0.300239, z: 3.12887

Facing it in another direction, the eulerAngles are:面向另一个方向, eulerAngles是:

euler angles x: -0.383826, y: -0.305686, z: -0.0239297

Even though these directions are quite far apart, the eulerAngles is still pretty much the same.尽管这些方向相距很远,但eulerAngles仍然几乎相同。 The different x and z values mean the y value doesn't represent which direction the device is facing.不同的xz值意味着y值不代表设备面向的方向。 As a result, my arrow follows the camera's heading to some point, and then starts rotating back in the opposite direction.结果,我的箭头跟随相机的方向到达某个点,然后开始向相反的方向旋转。 How can I zero-out the x and z values in a way that I'll get a truthful y value, that I can then use to orient my arrow?如何将xz值归零,以便获得真实的y值,然后我可以用它来确定箭头的方向?

Do not use euler angles to detect 'real' or 'truthful' values.不要使用欧拉角来检测“真实”或“真实”值。

Those values are always correct.这些值总是正确的。 To work with rotation you have to use either matricies or quaternions.要使用旋转,您必须使用矩阵或四元数。

Remember.记住。 It is possible to define lots of 'euler angles' using matrix.可以使用矩阵定义许多“欧拉角”。

Each euler angle is relative to the previous one.每个欧拉角都相对于前一个。

SceneKit applies these rotations in the reverse order of the components: SceneKit 以与组件相反的顺序应用这些旋转:

 1. first roll 2. then yaw 3. then pitch

So, to calculate the value you angle I would suggest to calculate the vector and its projection to Oxy plane.因此,要计算角度值,我建议计算向量及其到 Oxy 平面的投影。 This angle is not 'euler' angle.这个角度不是“欧拉”角。

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

相关问题 如何使用UIPanGestureRecognizer从y值获取介于0和1之间的浮点值 - How do I get float values between 0 and 1 from the y value using a UIPanGestureRecognizer Swift 3-SceneKit获取3D模型XYZ旋转值 - Swift 3 - SceneKit get 3d model X Y Z rotation Value 获取UISlider上X,Y值的位置 - Get X, Y position of value on UISlider 在Swift中获取UILabel在坐标(x,y)处的值 - Get value of UILabel at coordinate (x,y) in Swift 在MTKView中,如何获取3D(x,y,z)中给定点的像素信息(RGB和Alpha值)? - In a MTKView How to get pixel information ( RGB and Alpha values ) of a given point in 3D (x,y,z)? 如何使用4x4矩阵变换或欧拉角度旋转3d矢量? - How do I rotate a 3d vector with a 4x4 matrix transform or euler angles? 如何从iPhone的X,Y,Z加速度计读数计算行进方向上的加速度/减速度 - How do I calculate acceleration/deceleration in the direction of travel from X,Y,Z accelerometer readings from iphone 如何根据UIButton的y位置获取未知的浮点值 - How do I get a unknown float value based on y position of UIButton 核心图:如何设置x轴穿过零,底部和y轴分别为零和左? - Core Plot: How do I set the x-axis go through zero and at the bottom and y-axis to zero and left? 如何在iOS Charts 3.0中获取最大y值的x值? - How to get the x-value of the max y-value in iOS Charts 3.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM