# Given $y$, find the $x$ value of a point on a Bezier curve

I have linear equation of Bezier curve with one control point:

f[x_] := (1 – t)^2 x0 + 2 (1 – t) t x1 + t^2 x2;
f[y_] := (1 – t)^2 y0 + 2 (1 – t) t y1 + t^2 y2;


I have a specific Bezier curve and $y$ value and I want get the corresponding $x$ point on my curve.

I have the following second-order equations:

x[t_] := a t^2 + b t + c;
y[t_] := d t^2 + e t + f;


I solve these equations and get two values for $t$ and then replace $t1$ and $t2$ in $y$ linear equation of the curve and if answer of each one equal to my input $y$. Then I replace that $t$ in $y$ linear equation of the curve and get my $x$. My problem is that sometime answer of none of $y$ linear equation of the curve is not equal to input $y$.
for example I have these values

x0:=1
y0:=30
x1:=20
y1:=1
x2:=50
y2=30


and I want $x$ for

y:=10


I try my method for some curves and I find out when $delta$ is negetive in above second-order equation it dont work right.

I don't know what is my problem.

• Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
Jan 4, 2016 at 18:27
• People here generally like users to post code as Mathematica code, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you.
– user9660
Jan 4, 2016 at 18:28
• Do you really mean to raise to the power of 2P0 (as your code states)? And what can the code snippet [x, y] possibly mean? And instead of x(t) to you actually mean x[t_]? And do you want to raise the value at to the second power (as your code states)? I think you have many many syntactic errors here. Jan 4, 2016 at 18:34
• you should give a specific example. Jan 4, 2016 at 19:14
• @george2079 I edited my question Jan 5, 2016 at 5:04

I hope I have understood your question correctly.

The problem is that your Bezier curve (blue) does not intersect with the line $y=10$ (red) as you can see from the following plot.

fx[t_] := (1 - t)^2 x0 + (1 - t) t x1 + t^2 x2;
fy[t_] := (1 - t)^2 y0 + (1 - t) t y1 + t^2 y2;
{x0, y1} = {1, 30};
{x1, y1} = {20, 1};
{x2, y2} = {50, 30};
y = 10;
Show[{
ParametricPlot[{fx[t], fy[t]}, {t, 0, 1}, PlotRange -> All],
ParametricPlot[{t, y}, {t, 1, 50}, PlotStyle -> Red]}]


(note that the horizontal axis does not correspond to $y$=0).

However, for a different value of y you can get a solution as follows.

y = 20;
t = t /. Solve[fy[t] == y, t]


The variable t now contains two parameter values for which fy is equal to y; more precisely, fy[ t[[1]] ] is now equal to y and fy[ t[[2]] ] as well. The intersections are now easy to obtain:

intersection1 = {N[fx[ t[[1]] ] ], fy[ t[[1]] ]}


intersection2 = {N[fx[ t[[2]] ] ], fy[ t[[2]] ]}


Finally, you can now plot everything:

Show[{
ParametricPlot[{fx[t], fy[t]}, {t, 0, 1}, PlotRange -> All],
ParametricPlot[{t, y}, {t, 1, 50}, PlotStyle -> Green],
Graphics[{PointSize[Large], Magenta, Point[intersection1]}],
Graphics[{PointSize[Large], Orange, Point[intersection2]}]}]