考虑以下足球场地的图片:
从图片中可以看到各种球的运动,其中一些是弯曲的(即图像中的 (1), (2), (3)),而有些则不是(如线条(4))。
因此,我需要找出球路径与球门线和侧线的交点。有时输入可能不是曲线(比如图像中的(4))。
我已经编写了一个程序,但我不知道哪里出了问题——这是解决这种问题的正确方法吗?
如果是,那么如何将贝塞尔曲线转换为方程以便更好地解决问题?
考虑给定条件:
beizer curve eqaution -> a(x*x) + b*x + c
and line segment equation -> y = y1 + m(x-x1)
//maxCurvedPoint是曲线的最高点
var getIntersectionPoint = function (room, ballFromPosition, ballToPosition, maxCurvePoint)
{
var linepoints = [[m1,n1], [m2, n2], [m3, n3], [m4, n4]];
//converting three points(ballFromPosition, maxCurvePoint, ballToPosition) into the quadratic equation (Bezier curve) --(1)
//getting the equation of the line segment using the linepoints --(2)
//equating (1) and (2) and getting a quadratic equation and solving and finding intersection points
return intersectionPoint;
}
// solves //(-b(+-)sqrt(b*b - 4ac)/2ac)
function solve(a, b, c)
{
//check curve intersects line or not
if((Math.pow(b, 2) - (4 * a * c)) >= 0)
{
result1 = (-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a);
result2 = (-1 * b - Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a);
return [result1, result2];
}
return [];
}
有人能帮我解决这个问题吗?同时,曲线上最高点是否可以称为曲线的顶点?
const square = n => Math.pow(n, 2);
而不是内联所有的数学计算),第二个是由于 JavaScript 语言的一个特殊性,强烈推荐使用 K&R 风格的大括号而不是 GNU 风格的大括号。我敢打赌,如果你至少做到第一个建议,很可能会发现你的问题所在。 - Jared Smith