Ask Your Question

Problem with plotting a 3d Bezier curve

asked 2021-04-10 09:12:55 +0200

RozaTh gravatar image

updated 2021-04-11 10:49:59 +0200

vdelecroix gravatar image

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)],


But when I want to plot it in 3d, this line



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)],


both give me the following error: TypeError: unable to convert -(t - 1)^3 to an integer.

What am I doing wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-10 19:30:42 +0200

vdelecroix gravatar image

updated 2021-04-11 09:50:20 +0200

This looks like a bug and I opened the ticket #31640 to track the issue. Thanks for your report!

The issue turns out to be a missing vector conversion in the code. I posted a fix and should hopefully make it for a later release.

As a work around you can use the following function (that contains the fix I provided in the ticket)

def bezier3d(path, **options):
    from . import parametric_plot3d as P3D
    from sage.modules.free_module_element import vector
    from sage.symbolic.ring import SR

    p0 = vector(path[0][-1])
    t = SR.var('t')
    if len(path[0]) > 2:
        B = (1-t)**3*vector(path[0][0])+3*t*(1-t)**2*vector(path[0][1])+3*t**2*(1-t)*vector(path[0][-2])+t**3*p0
        G = P3D.parametric_plot3d(list(B), (0, 1), **options)
        G = line3d([path[0][0], p0], **options)

    for curve in path[1:]:
        if len(curve) > 1:
            p1 = vector(curve[0])
            p2 = vector(curve[-2])
            p3 = vector(curve[-1])
            B = (1-t)**3*p0+3*t*(1-t)**2*p1+3*t**2*(1-t)*p2+t**3*p3
            G += P3D.parametric_plot3d(list(B), (0, 1), **options)
            G += line3d([p0,curve[0]], **options)
        p0 = vector(curve[-1])   # this was the wrong line!
    return G
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-04-10 09:12:55 +0200

Seen: 30 times

Last updated: Apr 11