我正在尝试找到二维平面中一条抛物线上距离任意点最近的点,用于DirectX像素着色器。
经过大量搜索,我发现这是一个常见的预备数学作业问题。不幸的是,数百个相关答案都说“一旦你有了这个方程,使用你的图形计算器的最小值函数,它会告诉你答案是6。”
我承认我对预备数学的记忆完全没有了。我知道我要找的方程可能就在维基百科上,但我无法将这些希腊符号转换为HLSL函数。C、C++、C#或其他语言的解决方案也将不胜感激。
编辑:按照要求查看输入曲线的格式:
//Equation of parabola being y = ax^2 + bx + c
//p is the arbitrary point we're trying to find the closest point on the parabola for.
float2 GetClosestPointOnParabola(float a, float b, float c, float2 p)
{
//Something involving the distance formula...
//Something involving "minimization"...
return float2(x, y);
}