【发布时间】:2018-06-19 16:48:56
【问题描述】:
我想将我的四元数转换为欧拉角,但在此函数中,我在 result.W 上出现错误。错误是 CS0165。
public static Quaternion Euler(string[]text)
{
double yaw = Convert.ToDouble(text[1]);
double pitch = Convert.ToDouble(text[2]);
double roll = Convert.ToDouble(text[3]);
yaw = (Math.PI / 180) * yaw;
pitch = (Math.PI / 180) * pitch;
roll = (Math.PI / 180) * roll;
double yawOver2 = yaw * 0.5f;
float cosYawOver2 = (float)System.Math.Cos(yawOver2);
float sinYawOver2 = (float)System.Math.Sin(yawOver2);
double pitchOver2 = pitch * 0.5f;
float cosPitchOver2 = (float)System.Math.Cos(pitchOver2);
float sinPitchOver2 = (float)System.Math.Sin(pitchOver2);
double rollOver2 = roll * 0.5f;
float cosRollOver2 = (float)System.Math.Cos(rollOver2);
float sinRollOver2 = (float)System.Math.Sin(rollOver2);
Quaternion result;
result.W = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2;
result.X = sinYawOver2 * cosPitchOver2 * cosRollOver2 + cosYawOver2 * sinPitchOver2 * sinRollOver2;
result.Y = cosYawOver2 * sinPitchOver2 * cosRollOver2 - sinYawOver2 * cosPitchOver2 * sinRollOver2;
result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
return result;
}
可能是什么问题?
【问题讨论】:
-
使用未赋值的局部变量'name'
-
那么我建议您需要将结果初始化为新的四元数?
-
错误在哪一行?
-
result.W = cosYawOv ..... 这里是结果
-
您会找到答案here。短版:
Quaternion result = new Quaternion();
标签: c# quaternions euler-angles