【问题标题】:C# CS0165 on the result of QuaternionC# CS0165 关于四元数的结果
【发布时间】: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


【解决方案1】:

使用未分配的局部变量“名称”:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0165

您无法访问 W,因为很可能在您的四元数定义中您使用了属性或其他需要显式创建对象的代码。

【讨论】:

  • 四元数是结构体,不能为空。
猜你喜欢
  • 1970-01-01
  • 2010-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多