Opened 8 years ago

Last modified 8 years ago

#17025 new defect

can't view vectors with canvas3d

Reported by: Karl-Dieter Crisman Owned by:
Priority: minor Milestone: sage-6.4
Component: graphics Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by Karl-Dieter Crisman)

plot(vector([1,3,4]),viewer='canvas3d')

just ignores the viewer and uses jsmol instead. This first became obvious by trying

sage: x,y,z=var('x y z')
sage: plot_vector_field3d((x*cos(z),-y*cos(z),sin(z)), (x,0,pi), (y,0,pi), (z,0,pi),viewer='canvas3d')

but since that just adds vectors this is the underlying cause.

Note that some 3d graphics primitives work fine in canvas3d, such as sphere(viewer='canvas3d').

Change History (2)

comment:1 Changed 8 years ago by Karl-Dieter Crisman

Description: modified (diff)
Summary: canvas3d doesn't seem to work with vector field plotscan't view vectors with canvas3d

comment:2 Changed 8 years ago by Karl-Dieter Crisman

Here's the precise problem.

sage: V = vector([1,2,3])
sage: W = V.plot()
sage: W.json_repr(W.default_render_params())
[]
sage: W.default_render_params()
<class 'sage.plot.plot3d.base.RenderParams'>
sage: type(W)
<class 'sage.plot.plot3d.shapes2.Line'>

whereas most of the primitives are <class 'sage.plot.plot3d.base.TransformGroup'> or <type 'sage.plot.plot3d.parametric_surface.ParametricSurface'> or something similar.


Okay, specifically the file plot/plot3d/shapes2.py lacks json_repr methods, so it goes back to the (empty) default. Looks like Line, Point, and bezier3d. It turns out that the radius attribute gets you something because it relies on shapes.pyx.

sage: L = line3d([(0,0,0), (1,1,1)], radius=0.1)
sage: L.json_repr(L.default_render_params())
[[["{vertices:[{x:1,y:1,z:1},{x:0.978868,y:1.07887,z:0.942265},{x:1.04082,y:1.04082,z:0.91835},{x:1.07887,y:0.978868,z:0.942265},{x:1.07071,y:0.929289,z:1},{x:1.02113,y:0.921132,z:1.05774},{x:0.959175,y:0.959175,z:1.08165},{x:0.921132,y:1.02113,z:1.05774},{x:0.929289,y:1.07071,z:1},{x:-0.0211325,y:0.0788675,z:-0.057735},{x:0.0408248,y:0.0408248,z:-0.0816497},{x:0.0788675,y:-0.0211325,z:-0.057735},{x:0.0707107,y:-0.0707107,z:-6.93889e-18},{x:0.0211325,y:-0.0788675,z:0.057735},{x:-0.0408248,y:-0.0408248,z:0.0816497},{x:-0.0788675,y:0.0211325,z:0.057735},{x:-0.0707107,y:0.0707107,z:6.93889e-18},{x:0,y:0,z:0}],faces:[[0,2,1],[0,3,2],[0,4,3],[0,5,4],[0,6,5],[0,7,6],[0,8,7],[0,1,8],[1,2,10,9],[2,3,11,10],[3,4,12,11],[4,5,13,12],[5,6,14,13],[6,7,15,14],[7,8,16,15],[8,1,9,16],[9,10,17],[10,11,17],[11,12,17],[12,13,17],[13,14,17],[14,15,17],[15,16,17],[16,9,17]],color:'6666ff'}"]]]
sage: L = line3d([(0,0,0), (1,1,1)])
sage: L.json_repr(L.default_render_params())
[]

An easy fix to the problem here is to fix this:

        if plot_type == 'arrow' or plot_type == 'point':
            dimension = len(coords)
            if dimension == 3:
                from sage.plot.plot3d.shapes2 import line3d, point3d

                if plot_type == 'arrow':
                    return line3d([start, [(u+v) for u,v in zip(coords, start)]], arrow_head=True, **kwds)
                else:
                    return point3d(coords, **kwds)

Of course, in such a way that 'nice' things are relied upon, such as arrow3d

sage: X = arrow3d((0,0,0),(1,2,3))
sage: X.json_repr(X.default_render_params())
[[["{vertices:[{x:0.951893,y:1.90379,z:2.85568},{x:0.950307,y:1.92061,z:2.84499},{x:0.96967,y:1.90748,z:2.84729},{x:0.964466,y:1.88924,z:2.86119},{x:0.941886,y:1.8911,z:2.86747},{x:0.933136,y:1.91049,z:2.85746},{x:-0.00158573,y:0.0168285,z:-0.0106904},{x:0.0177771,y:0.00369219,z:-0.00838714},{x:0.0125726,y:-0.0145466,z:0.00550691},{x:-0.0100068,y:-0.0126825,z:0.0117906},{x:-0.0187571,y:0.00670842,z:0.00178008},{x:0,y:0,z:0}],faces:[[0,2,1],[0,3,2],[0,4,3],[0,5,4],[0,1,5],[1,2,7,6],[2,3,8,7],[3,4,9,8],[4,5,10,9],[5,1,6,10],[6,7,11],[7,8,11],[8,9,11],[9,10,11],[10,6,11]],color:'6666ff'}"],
  [["{vertices:[{x:1,y:2,z:3},{x:0.947136,y:1.95427,z:2.82361},{x:1.00522,y:1.91486,z:2.83052},{x:0.989611,y:1.86015,z:2.8722},{x:0.921873,y:1.86574,z:2.89105},{x:0.895622,y:1.92391,z:2.86102},{x:0.951893,y:1.90379,z:2.85568}],faces:[[0,2,1],[0,3,2],[0,4,3],[0,5,4],[0,1,5],[1,2,6],[2,3,6],[3,4,6],[4,5,6],[5,1,6]],color:'6666ff'}"]]]]

and LineSegment. So perhaps a different ticket could be actually fixing these base classes by providing json_repr() for them.

Note: See TracTickets for help on using tickets.