how to get y component of bezier control points?
or is there a utility in sage that returns the bezier control points of a curve given that curve?
im writing a program that takes a curve in polynomial form and returns those control points, this is the part in question:
def bezierControlPoints(poly):
a = sage.var('a')
b = sage.var('b')
c = sage.var('c')
d = sage.var('d')
t = sage.var('t')
bezier = ((1 - t) ** 3) * a + 3 * ((1 - t) ** 2) * t * \
b + 3 * ((1 - t) * (t ** 2)) * c + (t ** 3) * d
eqn1 = poly.substitute(t=0)
eqn2 = poly.substitute(t=.33)
eqn3 = poly.substitute(t=.66)
eqn4 = poly.substitute(t=1)
cb1 = bezier.substitute(t=0)
cb2 = bezier.substitute(t=.33)
cb3 = bezier.substitute(t=.66)
cb4 = bezier.substitute(t=1)
solns = sage.solve([eqn1 == cb1, eqn2 == cb2, eqn3 == cb3,
eqn4 == cb4], a, b, c, d, solution_dict=True)
return [[s[a].n(30), s[b].n(30), s[c].n(30), s[d].n(30)] for s in solns]
but the control points are coordinates, and this returns single numbers like coefficients. for example
f(x) = x^4 - 10*x^3 + 35*x^2 - 50*x + 24
returns
[24.000000, 3.8069265, -4.2949254, -0.30555556]
[-0.30555556, 0.85185185, 0.85185185, -0.30555556]
[-0.30555556, -1.3680046, -1.2661527, 0.00000000]
so how do i finish processing these portions of the control points?
background
the parts of the program i have written that i didnt share take the polynomial of arbitrary order, break it up into simpler subcurves, parameterize those subcurves, and those parameterized subcurves are the arguements of the bezierControlPoints(), which is called iteratively depending on the order of the polynomial.
Did you give a look at https://doc.sagemath.org/html/en/reference/plotting/sage/plot/bezier_path.html ?
I am not sure about what you're trying to do (find control points knowing some function
f), which is the reverse of the usual Bezier problem (find a polynomial knowing,the control points).If I understand you correctly, you are looking for a "good" approximation of some function
f(here a polynomialpoly), by a cubic Bezier curvec. Such a curve has four "control points"P[0]..P[3].Here,
P(0]andP[3]are fully determined to be(0, f(0))and(1, f(1))respectively. Furthermore, the equality of slopes in 0 and 1 determine the slopes ofP[0]-P[1]andP[2]-P[3].You are left with only two unknowns, which are the abcissæ of
P[1]andP[2]. to fix them, you must define the criteria of a "good" approximation offbyc, which should solve your problem.@Emmanuel Charpentier: yes, this is the reverse of the typical bezier problem. what I am doing is taking hand drawn curves that I ultimately need rendered in a browser. this curves are polynomials of various order. So I am taking the curves parameterzing them, and the parameterized curves are then the argument for the above
bezierControlPoints()method. i do realize thatpoint P[0] = (0, poly(0))and thatpoint P[3] = (1, poly(1)). what thebezierControlPoints()method above does is set up a system of linear equations for various values oft, solving for the coefficients of the cubic bezier. and so my question is how do i take those results, those coefficients and convert them into coordinates of ordered pairs?@Emmanuel Charpentier if i were to substitute those coefficients into
polyi would just get some point along that curve, but the coefficients that i solve for withbezierControlPoints()are not the parameters of cubic bezier, that is whattis, so this is where my confusion liesOkay, I see what you mean.
And my previous command is wrong: choose a change of scale and origin coaxing the problem on the intervl
[0 1]and letf0andf1the values of the function at the extremities,d0andd1the derivatives at the same points. Then:Now, all that remains to do is to equate this to the canonical solution of Bezier curves. The difficulty is to find the "right" notation. Let me think ...(more)