Weird behavior in sagecell

43 views
Skip to first unread message

david.guichard

unread,
Nov 30, 2018, 6:43:00 PM11/30/18
to sage-support
In this page,


I have two sagecells, each to do a 3d plot. If I evaluate the first one, it works as expected. If I then evaluate the second, it graphs correctly, but it also replaces the first plot with a copy of the second. Neither of them is "live", that is, I can't rotate either version.

If I first evaluate the second cell, it works as expected. If I then evaluate the first one, it also works as expected: I end up with two (different) plots, both live.

I'd appreciate knowing how to fix this, if it's possible. I have tried a few things, such as changing the outputLocation, but nothing has worked so far.

Thanks,
David

slelievre

unread,
Nov 30, 2018, 8:02:27 PM11/30/18
to sage-support

Fri 2018-11-30 23:43:00 UTC, David Guichard:
Not sure how to explain what happens there,
or how to really fix it if sticking to jsmol is important.

If you do the 3D-plotting with three.js however,
the problem goes away.

This just amounts to adding viewer='threejs'
at the end of the plotting commands:

----
    # Trefoil knot tube
    t, u = SR.var('t u')
    assume(t, u, 'real')
    # First define the Trefoil knot spacecurve
    r = vector((sin(3 * t), 2 * sin(2 * t) + sin(t), cos(t) - 2 * cos(2 * t)))
    # Next compute the T, N, and B vectors
    rp = diff(r, t)
    T = rp / rp.norm()
    Tp = diff(T, t)
    N = Tp / Tp.norm(2)
    B = T.cross_product(N)
    # Define the function to use for the radius of the circle
    radius(t) = 1/2
    # Define the vector function for the surface and plot it
    tube = r + radius(t) * cos(u) * N + radius(t) * sin(u) * B
    parametric_plot3d(tube, (t, 0, 2 * pi), (u, 0, 2 * pi),
                      plot_points=[100, 30], aspect_ratio=[1, 1, 1]
                      viewer='threejs')
----
----
    # The cone
    u, v = var('u v')
    assume(u, v, 'real')
    # Define the surface as a vector function
    r = vector((v * cos(u), v * sin(u), v))
    # Plot it
    parametric_plot3d(r, (u, 0, 2*pi), (v, 0, 5), aspect_ratio=[1, 1, 1],
                      viewer='threejs')
----

Samuel Lelièvre

unread,
Nov 30, 2018, 8:14:25 PM11/30/18
to sage-s...@googlegroups.com
Sat 2018-12-01 01:02 UTC, slelievre:
>
> Fri 2018-11-30 23:43 UTC, David Guichard:
>>
>> In this page,
>>
>> http://skink.whitman.edu/~guichard/sage/two_plots_clean.html
>>
>> I have two sagecells, each to do a 3d plot. If I evaluate the first one, it works as expected. If I then evaluate the second, it graphs correctly, but it also replaces the first plot with a copy of the second. Neither of them is "live", that is, I can't rotate either version.
>>
>> If I first evaluate the second cell, it works as expected. If I then evaluate the first one, it also works as expected: I end up with two (different) plots, both live.
>>
>> I'd appreciate knowing how to fix this, if it's possible. I have tried a few things, such as changing the outputLocation, but nothing has worked so far.
>>
>> Thanks,
>> David
>
>
> Not sure how to explain what happens there,
> or how to really fix it if sticking to jsmol is important.
>
> If you do the 3D-plotting with three.js however,
> the problem goes away.
>
> This just amounts to adding viewer='threejs'
> at the end of the plotting commands.

See a similar report on the sage-cell mailing list:
https://groups.google.com/d/topic/sage-cell/BL9h7xLiwG4/discussion

In the discussion there, Andrey Novoseltsev points out
that SageMathCell uses only one jsmol instance, and
if there are several plots using it, they might conflict in
hard to predict ways. He recommends using three.js.

three.js (called "threejs" in Sage) is a javascript 3D-plotting library.
https://threejs.org/

david.guichard

unread,
Nov 30, 2018, 8:19:59 PM11/30/18
to sage-support
Thanks!

Kwankyu

unread,
Dec 1, 2018, 5:53:19 AM12/1/18
to sage-support
See a similar report on the sage-cell mailing list:
https://groups.google.com/d/topic/sage-cell/BL9h7xLiwG4/discussion

In the discussion there, Andrey Novoseltsev points out
that SageMathCell uses only one jsmol instance, and
if there are several plots using it, they might conflict in
hard to predict ways. 

Actually there is an easy fix for this issue. Follow the discussion linked above. 
Reply all
Reply to author
Forward
0 new messages