【问题标题】:Quaternion slerp with shortest path not working最短路径的四元数 slerp 不起作用
【发布时间】:2018-08-16 20:44:32
【问题描述】:

我的 slerp 程序如下。根据我的阅读,对 > 0 的检查应该处理它,因此它总是采用最短路径。但它永远不会。在我穿过“极点”的情况下,四元数会翻转并产生具有 NAN 值的角度。

quat quat::slerp(quat dest, float t)
{
  const quat &from = *this;
  static const double epsilon = 0.0001;
  double theta, cosTheta, sinTheta;
  double p, q;

  cosTheta = from.x*dest.x + from.y*dest.y + from.z*dest.z + from.w*dest.w;

  if(cosTheta < 0.0)
  {
    dest = { -from.x, -from.y, -from.z, -from.w };
    cosTheta = -cosTheta;
  }

  if((1.0-fabs(cosTheta)) > epsilon)
  {
    theta = acos(cosTheta);
    sinTheta = sin(theta);
    q = sin((1-t) * theta) / sinTheta;
    p = sin(t*theta) / sinTheta;
  }
  else
  {
    q = 1-t;
    p = t;
  }

  quat qo;
  qo.w = (float)((q * from.w) + (p * dest.w));
  qo.x = (float)((q * from.x) + (p * dest.x));
  qo.y = (float)((q * from.y) + (p * dest.y));
  qo.z = (float)((q * from.z) + (p * dest.z));

  return qo;
}

【问题讨论】:

    标签: c++ opengl 3d quaternions


    【解决方案1】:

    也许还有其他错误,但这一行肯定有一个:

    dest = { -from.x, -from.y, -from.z, -from.w };
    

    它用-from 覆盖dest,这是不正确的。应该是:

    dest = { -dest.x, -dest.y, -dest.z, -dest.w };
    

    【讨论】:

    • 耶稣...是的,这很可能。让我解决这个问题。
    猜你喜欢
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2017-06-13
    相关资源
    最近更新 更多