贝塞尔曲线 - 使用(图)X来求解Y.

时间:2017-08-15 11:35:49

标签: c# math bezier

我试图取两个点和两个切线并解决y给定的x。但是,我在网上找到的所有在线资源都比我需要的有点不同。所有资源都允许我找到x和y,给出0到1之间的百分比。这不是我需要的。我将尝试用下面的图片解释我的意思:

curve

我知道这条曲线是多条bezier线,但我只是想说明一点。在非常曲线上演示更容易一些。如果我试图在我在线找到的公式上获得y输出的百分比为0.5,我将得到(可能)大约红点。这不是我想要的。我想在图表上解决.5,而不是使用图表的百分比。我想解决蓝线问题。有谁知道我怎么能做到这一点?另外,如果我用线条做一个循环,是否可以找到两个y值?

如果有人愿意给我写一个小样本,我正在使用C#和变量: Vector2 start,tan1,end,tan2; //每个包含x和y float 浮动时间; //我们想要解决的图表上的时间(0到1之间)

        Vector2 start = new Vector2(50, 150), end = new Vector2(150, 150), tan1 = new Vector2(65, 30), tan2 = new Vector2(90, 160), delta;
    float t = .5f;
    delta = end - start;
    GLDraw.DrawBezier(start, tan1, end, tan2, Color.red, 1);
    GLDraw.DrawBox(new Rect(tan1.x - 1, tan1.y - 1, 2, 2), Color.red, 1);
    GLDraw.DrawBox(new Rect(tan2.x - 1, tan2.y - 1, 2, 2), Color.red, 1);
    float X = Mathf.Pow((1 - t), 3) * start.x + 3 * Mathf.Pow((1 - t), 2) * t * tan1.x + 3 * (1 - t) * Mathf.Pow(t, 2) * tan2.x + Mathf.Pow(t, 3) * end.x;
    float Y = Mathf.Pow((1 - t), 3) * start.y + 3 * Mathf.Pow((1 - t), 3) * t * tan1.y + 3 * (1 - t) * Mathf.Pow(t, 2) * tan2.y + Mathf.Pow(t, 3) * end.y;
    GLDraw.DrawBox(new Rect(X - 1, Y - 1, 2, 2), Color.red, 1);

[drawnCurve[2]

2 个答案:

答案 0 :(得分:1)

您有未知t和给定XValue的等式。只需打开括号并求解t得到的三次方程。请注意,等式最多可能有三种解决方案。

 (1 - t)^3 * start.x + 
 3 * (1 - t)^2 * t * tan1.x + 
 3 * (1 - t) * t^2 * tan2.x + 
 t^3 * end.x - XValue               =  0

 t^3 * (-start.x + 3 * tan1.x - 3 * tan2.x +  end.x)  + 
 t^2 * (3*start.x - 6 * tan1.x + 3 * tan2.x) + 
 t   * (-3*start.x + 3 * tan1.x) + 
       (start.x - XValue)           =  0

答案 1 :(得分:0)

这篇文章解释了我需要知道的内容。在我寻找实现这一目标的整个过程中,我正在寻找与'bezier曲线解决y从x'相关的事情,但找到交叉点更接近我需要的东西。很抱歉非常不清楚。 https://www.particleincell.com/2013/cubic-line-intersection/