The Question
Okay so basically what I'm trying to do, is calculating the Y location on a Cubic Curve / Bezier Curve / Spline when the X location is given.
I've searched everywhere on Stack Overflow and Google and I could find anything that actually worked!
The Curve Points
x1 = 50d;
y1 = 400d / 2d + 100d;
x2 = 400d;
y2 = 400d / 2d + 100d;
x3 = 600d - 400d;
y3 = 400d / 2d - 100d;
x4 = 600d - 50d;
y4 = 400d / 2d - 100d;
The reason that I calculate "600 - 400" and I don't just write "200" is because in my code "600" is actually the width of the window, which the Cubic Curve is rendered in. Thereby it actually says "width - 400" in my code.
So the following code after, can calculate the X & Y on a Cubic Curve when T is given!
t = 0.5d;
cx = 3d * (x2 - x1);
cy = 3d * (y2 - y1);
bx = 3d * (x3 - x2) - cx;
by = 3d * (y3 - y2) - cy;
ax = x4 - x1 - cx - bx;
ay = y4 - y1 - cy - by;
point_x = ax * (t * t * t) + bx * (t * t) + cx * t + x1;
point_y = ay * (t * t * t) + by * (t * t) + cy * t + y1;
So again, what I'm trying to calculate is the Y location of a Curve when you know an X location. But the only thing that I'm able to calculate is both an X & Y location on the Curve when T is given.
This is my first post, so if something isn't written 100% correctly, I apologize!