对于 DirectX 像素着色器,我正在尝试在抛物线上找到与 2d 中任意点最近的点。
大量的谷歌搜索向我揭示了这是一个常见的微积分前作业问题。不幸的是,数百个相关答案都说“一旦你有了这个方程,使用你的图形计算器的最小函数,它会告诉你答案是 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);
}