四元素與點的乘法-得到的是空間點做旋轉後的點的座標-AR開發常用

SCNVector3 QuaternionMultVector(SCNQuaternion rotation, SCNVector3 point)
{
    float num = rotation.x * 2;
    float num2 = rotation.y * 2;
    float num3 = rotation.z * 2;
    float num4 = rotation.x * num;
    float num5 = rotation.y * num2;
    float num6 = rotation.z * num3;
    float num7 = rotation.x * num2;
    float num8 = rotation.x * num3;
    float num9 = rotation.y * num3;
    float num10 = rotation.w * num;
    float num11 = rotation.w * num2;
    float num12 = rotation.w * num3;
    SCNVector3 result;
    result.x = (1 - (num5 + num6)) * point.x + (num7 - num12) * point.y + (num8 + num11) * point.z;
    result.y = (num7 + num12) * point.x + (1 - (num4 + num6)) * point.y + (num9 - num10) * point.z;
    result.z = (num8 - num11) * point.x + (num9 + num10) * point.y + (1 - (num4 + num5)) * point.z;
    return result;
}

点赞