c# - Bezier Curve - Using (Graph)X to Solve Y -


i trying take 2 points , 2 tangents , solve y given x. however, resources have found online doing online bit different need. of resources have allowed me find x , y given percentage between 0 , 1. not need. try explain mean picture below:

curve

i know curve multiple bezier lines, trying make point. bit easier demonstrate on curvy line. if try y output percentage of .5 on formulas have found online got (probably) approximately red point. not want. want solve .5 on graph, , not use percentage of graph. want solve blue line. know how can accomplish this? also, if make loop lines, possible find both y values?

if kind enough write me small sample, using c#, , variables: vector2 start, tan1, end, tan2;//each contain x , y float float time;//the time on graph want solve (between 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]

you have equation unknown t , given xvalue. open brackets , solve resulting cubic equation t. note equation might have upto 3 solutions.

 (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 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -