Ask Your Question
2

Problem with plotting a 3d Bezier curve

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

RozaTh gravatar image

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

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)],
  [(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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

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

vdelecroix gravatar image

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

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)
    else:
        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)
        else:
            G += line3d([p0,curve[0]], **options)
        p0 = vector(curve[-1])   # this was the wrong line!
    return G
edit flag offensive delete link more

Comments

The fix is incorporated in sage 9.3!

vdelecroix gravatar imagevdelecroix ( 2021-06-09 23:09:03 +0100 )edit

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

Stats

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

Seen: 77 times

Last updated: Apr 11