ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 11 Apr 2021 02:07:59 +0200Possible problem in bezier_path.pyhttps://ask.sagemath.org/question/56608/possible-problem-in-bezier_pathpy/ It seems that the path that is stored by BezierPath is not correct.
Let
p2d = [[(3.0,0.0),(3.0,0.13),(2.94,0.25),(2.8,0.35)],
[(2.7,0.44),(2.6,0.5),(2.5,0.5)],
[(2.36,0.5),(2.24,0.44),(2.14,0.35)],
[(2.05,0.25),(2.0,0.13),(2.0,6.1e-17)]]
then
bezier_path(p2d)[0].path
is different than the given path p2d. There are several consequences to this, for example, the stored path cannot be fed again to bezier_path, so this won't work (results in weird errors):
bezier_path(bezier_path(p2d)[0].path)
and also affects the plot3d method of the class.
The issue seems to stem from line 64 of bezier_path.py:
vertices = self.path[0]
Since the list of vertices changes size after the line so does self.path. I believe the line should be
vertices = deepcopy(self.path[0])RozaThSun, 11 Apr 2021 02:07:59 +0200https://ask.sagemath.org/question/56608/Problem with plotting a 3d Bezier curvehttps://ask.sagemath.org/question/56590/problem-with-plotting-a-3d-bezier-curve/ I have a problem with plotting a Bezier spline in 3d.
In 2d this simply works:
p2d = [[(3.0,0.0),(3.0,0.13),(2.94,0.25),(2.8,0.35)],
[(2.7,0.44),(2.6,0.5),(2.5,0.5)],
[(2.36,0.5),(2.24,0.44),(2.14,0.35)],
[(2.05,0.25),(2.0,0.13),(2.0,6.1e-17)]]
bezier_path(p2d)
But when I want to plot it in 3d, this line
bezier_path(p2d).plot3d()
or
p3d = [[(3.0,0.0,0.0),(3.0,0.13,0.0),(2.94,0.25,0.0),(2.8,0.35,0.0)],
[(2.7,0.44,0.0),(2.6,0.5,0.0),(2.5,0.5,0.0)],
[(2.36,0.5,0.0),(2.24,0.44,0.0),(2.14,0.35,0.0)],
[(2.05,0.25,0.0),(2.0,0.13,0.0),(2.0,6.1e-17,0.0)]]
bezier3d(p3d)
both give me the following error: TypeError: unable to convert -(t - 1)^3 to an integer.
What am I doing wrong?RozaThSat, 10 Apr 2021 09:12:55 +0200https://ask.sagemath.org/question/56590/Concatenate bezier paths?https://ask.sagemath.org/question/54573/concatenate-bezier-paths/I have two bezier paths path1 and path2 (constructed using arc(...)). They have the same beginning point and end point, and I'd like to join them into a single path and fill the interior. What's the right way to do this? If I just try to concatenate the lists path1.path and path2.path and then call bezier_curve() and the result, it generates an error when I try to display it.
Here is a simple failed attempt.
arc1 = arc((0,1),sqrt(2),sector=(5*pi/4,7*pi/4))
arc2 = arc((0,-1),sqrt(2),sector=(pi/4,3*pi/4))
path1 = arc1[0].bezier_path()
path2 = arc2[0].bezier_path()
combo = bezier_path(path1[0].path+path2[0].path)
combo.show()John LSat, 05 Dec 2020 16:46:12 +0100https://ask.sagemath.org/question/54573/how to get y component of bezier control points?https://ask.sagemath.org/question/49460/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.
alienfetuseaterThu, 09 Jan 2020 04:36:39 +0100https://ask.sagemath.org/question/49460/