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.Thu, 05 May 2016 17:27:00 +0200Add a 3d graphics object to a tachyon scenehttps://ask.sagemath.org/question/33320/add-a-3d-graphics-object-to-a-tachyon-scene/I'm trying to understand how to add 3d graphics objects to a tachyon scene.
Suppose I define a tachyon scene
sage: s = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0))
and I define a torus and a 3d plot
sage: from sage.plot.plot3d.shapes import Torus
sage: t = Torus(0.5, 0.2)
sage: p = plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2))
How can I add `t` and `p` to `s`?
I know I can do `s.str()` and `t.tachyon()` and `p.tachyon()`
to get strings depicting `s`, `t` and `p` as tachyon scenes,
so I could fiddle with these strings, but is there a better way?
For instance, if I have a string depicting a tachyon scene,
can I turn it into a Sage tachyon scene, extract its objects,
add them to another scene's objects?
slelievreThu, 05 May 2016 17:27:00 +0200https://ask.sagemath.org/question/33320/Error rendering 3d scenehttps://ask.sagemath.org/question/29510/error-rendering-3d-scene/I'm working in the SageMath Cloud. The code block
x,y,t = var('x,y,t')
f = lambda x,y: x*abs(y)/sqrt(x^2+y^2) if (x,y)<>(0,0) else 0
a,b = 1,6
e = 0.1
parametric_plot3d( [b*t, -a*t, f(b*t,-a*t)], [t,-e,e], color="yellow", size=15 )
produces an error message:
error rendering 3d scene -- error downloading /blobs/682b952d-d577-45ce-98ff-4e7a06ddad32.sage3d?uuid=682b952d-d577-45ce-98ff-4e7a06ddad32
But if I change the fourth line to `e = 1`, then it works just fine.
A similar error was reported in http://ask.sagemath.org/question/27300/error-rending-3d-scene, but the fix there was easier.
Jeremy MartinSun, 20 Sep 2015 14:03:28 +0200https://ask.sagemath.org/question/29510/Get objects from a Graphics3dGrouphttps://ask.sagemath.org/question/26360/get-objects-from-a-graphics3dgroup/Dear all,
I would like to trasnform a 3d object into a set of faces (or triangles). For that, I take a 3d object and convert it to a STL file following [this procedure](http://trac.sagemath.org/ticket/7744).
The short questions is: how to get the 3d objects from a Graphics3dGroup?
The long question : I don't understand the nature of the 3d graphics.
For instance:
G1 = polygon3d([(0,0,0),(1,0,0),(2,1,1)])
print(type(G1))
G2 = polygon3d([(0,0,0),(1,0,0),(2,1,1)]) + polygon3d([(1,2,3),(1,0,0),(2,1,1)])
print(type(G2))
G3 = sphere((0,0,0),1)
print(type(G3))
1. In the first case it seems to be a set of faces and it's possible to convert it to a STL file.
2. In the second case it is a group of 3d object and -as a group- it has no face.
3. The sphere is a `TransformGroup` and has no face.
How to get the faces of the last two situations?
Thanks for yours answers.
Arnaud
Arnaud1418Fri, 27 Mar 2015 15:31:57 +0100https://ask.sagemath.org/question/26360/Plot Slope Field on Cylindrical Surface?https://ask.sagemath.org/question/25221/plot-slope-field-on-cylindrical-surface/I want to wrap a slope field graphics object (obtained with plot_slope_field) on a cylindrical surface.
Is there a general way to wrap a Graphics object onto a surface, such as by applying a Transform on a Graphics3D object?
Or a particular way to make a slope field on non-planar surfaces?
agartthaThu, 11 Dec 2014 17:24:43 +0100https://ask.sagemath.org/question/25221/Interactive viewers for 3d plots?https://ask.sagemath.org/question/10365/interactive-viewers-for-3d-plots/I've been spending much of today trying to create 3D plots. I find that the default viewer (jmol) works fine. I can't get java3d to work (and yes, I gave the java 3d libraries): in a console it does nothing; in a browser I get a still image, but "Click for interactive view" causes the browser to crash (firefox, chrome, midori, all under linux). Canvas3d does give me an interactive view, but some of the plot elements are missing. I have a surface, plane, curve, line, etc all plotted with something like
(S+P+C+L).show(viewer='canvas3d')
however for some reason the curve and line are missing. Maybe canvas3d doesn't like 2d elements...? So far only jmol has given me full interactivity of the entire plot. But I can't get it to export to an image file properly.
Is there any magic by which I can get java3d and canvas3d to work?AlasdairFri, 19 Jul 2013 05:10:14 +0200https://ask.sagemath.org/question/10365/Add text to Tachyon image?https://ask.sagemath.org/question/9322/add-text-to-tachyon-image/Hi folks, is there a way to add text to Tachyon images? I tried
S = sphere(opacity=0.8, aspect_ratio=[1,1,1])
T = text3d('hello world', (2,2,2))
M = S + T
M.show(viewer='tachyon', frame=False)
in the Sage notebook, but that didn't work. Got a sphere but no text. I also searched the docs, but couldn't find anything relevant.araichevSun, 16 Sep 2012 21:00:10 +0200https://ask.sagemath.org/question/9322/3D graphics bug?https://ask.sagemath.org/question/9177/3d-graphics-bug/Hi,
When I use the following code and I change the values of phi or theta, the previous red dot(point of projection) remains on the image and the new dot is added onto the image, giving two red dots. If I repeatedly change the values then more red dots appear. This problem does not occur if I get rid of the polygon inside the sphere. I'm not sure why this is happening...
---------------------------------
Works:
S = sphere(size=10,color="yellow",opacity=0.5)
north_pole = point3d((0,0,10), color="blue")
r = 10
@interact
def _(theta = slider(0,2*pi,pi/20, default = pi/3, label="theta"),
phi = slider(0,2*pi,pi/20, default = pi/4, label="phi")):
point_of_projection = point3d((r*sin(theta)*cos(phi),r*sin(theta)*sin(phi),r*cos(theta)), color="red")
show(S + north_pole + point_of_projection)
--------------------------------
Doesn't work:
Z = Polyhedron([[2,3,3],[3,0,3],[2,6,1],[1,0,1],[6,7,2]])
Z_set_as_graphics = Z.show()
S = sphere(size=10,color="yellow",opacity=0.5)
north_pole = point3d((0,0,10), color="blue")
r = 10
@interact
def _(theta = slider(0,2*pi,pi/20, default = pi/3, label="theta"), phi = slider(0,2*pi,pi/20, default = pi/4, label="phi")):
point_of_projection = point3d((r*sin(theta)*cos(phi),r*sin(theta)*sin(phi),r*cos(theta)), color="red")
show(Z_set_as_graphics + S + north_pole + point_of_projection)glee2Tue, 24 Jul 2012 14:04:56 +0200https://ask.sagemath.org/question/9177/3d animation with tachyonhttps://ask.sagemath.org/question/8947/3d-animation-with-tachyon/Hello!
I'm trying to create a 3d animations, frame per frame. I've discovered that tachyon plotter is very usefull to create images. But after that, I'm unable to make it as animation.
For example, I have copied a code and generate some scenes with tachyon with this:
saved = []
for j in srange(-0.9,1,0.3):
t = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0))
t.light((4,3,2), 0.2, (1,1,1))
t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1.0,0,0))
t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.3, opacity=1.0, color=(0,1.0,0))
t.texture('t2', ambient=0.2,diffuse=0.7, specular=0.5, opacity=0.7, color=(0,0,1.0))
k=0
for i in srange(-1,j,0.05):
k += 1
t.sphere((i,i^2-0.5,i^3), 0.1, 't%s'%(k%3))
saved.append(t)
In "saved" array I have all the png of the animation I want to do, and I can view it with saved[i].show().
I tried to unite all the frames with the command animate:
animate(saved[i].show() for i in range(0,len(saved)))
But it didn't work. What other alternatives do I have? (without using ffmpeg)
Thank you!RoctivThu, 17 May 2012 10:35:17 +0200https://ask.sagemath.org/question/8947/Plotting in 3D in spherical coordinateshttps://ask.sagemath.org/question/8081/plotting-in-3d-in-spherical-coordinates/My problem is that I am trying to plot (in full 3D spherical coordinates) a set of values stored in a 2D lookup table or LUT. The LUT is actually stored as a numpy 1801*3601 2D array indexed by theta and phi respectively in 0.1 degree steps. The LUT in fact represents an antenna radiation pattern (i.e. antenna gain/ radiation intensity as a function of theta and phi). However, my problem generalises to any one of plotting a function in spherical coordinates.
My first attempt at plotting this in Sage was to use the 'spherical_plot3d()' function. First I defined a function called:
getGain(phiInRadians, thetaInRadians)
which returned a value from the lookup table (LUT) representing antenna gain (a positive number in decibels). Then I tried plotting this as follows:
sage: spherical_plot3d(getGain,(-3.142,3.142),(0,3.142)).show(aspect_ratio=(1,1,1))
Now this *almost* does what I want, but not quite. My LUT has a high resolution with 0.1 degree intervals. However, the 3D plot which the above command delivers (via Jmol) seems to smooth the pattern where I don't want it to be smoothed (because it has abrupt edges), and is too 'blocky' where I would like the pattern to be smooth. Is there any way I can have fine control of the step-size in phi and theta (u and v in Sage-speak), or must I leave it to Sage to control these?
I also tried a different approach, which is to use list_plot3d, but to transform the coordinates from spherical to rectangular when building up my list to plot. To discuss this case we can simplify the problem to say that we wish to plot the radiation pattern of an isotropic antenna, i.e. one which has equal gain in all directions. Thus what we are simply trying to do is to plot a sphere in 3 dimensions from a list of 3-tuples, where each tuple represents an (x,y,z) coordinate in Cartesian space. However, when generating the points to plot I transform from spherical to cartesian coordinates when setting up the list of points to plot, thus:
sage: import numpy as np
sage: r=1 # Representing the gain of an isotropic antenna
sage: listOfPointsOnSurfaceOfSphere = [ (r* sin(theta) * cos(phi), r* sin(theta)* sin(phi), r* getGain(phi,theta)* cos(theta)) for theta in np.arange(0.1,pi,0.1) for phi in np.arange(-pi,pi,0.1) ]
sage: myPlot1 = list_plot3d(listOfPointsOnSurfaceOfSphere).show()
Now what I find is that my plot is all 'spiky', whereas I was hoping to see a smooth sphere. Of course, what is happening is that I have multiple points with the same (or similar) (x,y) coordinates, but very different z coordinates, since every point on the sphere 'above the equator' (i.e. above the x,y plane) has effective neighbours as mirror images below. This seems to be screwing up the interpolation routine, which isn't able to identify that it is actually nearby points ON THE SURFACE OF THE SPHERE which should be treated as neighbours. I can (sort of) solve this problem by only plotting my antenna radiation pattern over the range of theta for 0..pi/2 rather than 0..pi. This means that my pattern now interpolates nicely, and I can choose whatever resolution I desire (within reason). However, I can now only plot the upper (or lower) half of my radiation pattern plot at a time, and not the whole 3D pattern all together.
So, in summary, I have an almost but not quite satisfactory situation whereby I can choose between:
a) A full 3D plot, but can't control the resolution, so I get unwanted blockiness/smoothing in the wrong places, or
b) A plot where I get the resolution I desire, but I can only show either above or below the x,y plane, but not all at the same time
So if anyone could help me by advising me how I could achieve the best of both worlds (i.e. full 3D plot with full control of resolution) I would be most grateful. Thanks.
deebs67Tue, 19 Apr 2011 08:28:25 +0200https://ask.sagemath.org/question/8081/Jmol in published worksheetshttps://ask.sagemath.org/question/8053/jmol-in-published-worksheets/One of my main interests in publishing worksheets was the thought that it would be an easy way to let people interact with 3D diagrams I produced, using Jmol.
But now Jmol is finally working on the flask notebook server, and I've finally published a worksheet there constructing some 3D diagrams, and it seems that the diagrams aren't shown unless one logs in to "Edit" the worksheet. I thought maybe adding "#auto" tags to each cell would help, but alas it did not.
Is there another way to make sure people can use the Jmol 3D diagrams? Or does someone know how to use the Jmol "export" feature to export to a standalone format?
If you want to take a look, the published worksheet is [here](http://flask.sagenb.org/home/pub/23/). For now there's not much explanation, but there are two places where 3D diagrams (moduli spaces of quadrilaterals) are supposed to be drawn: `a.show()` and `g.show()`.nilesFri, 08 Apr 2011 18:01:27 +0200https://ask.sagemath.org/question/8053/Can I cache a rendered 3d graphic (for @interact)?https://ask.sagemath.org/question/7969/can-i-cache-a-rendered-3d-graphic-for-interact/I'd like to make a simple interact for the notebook which shows a certain 3d object, and lets the user move a point around in the object and see data about that point. (For example, the object could be the domain of a certain function, and the data could have to do with values of the function in `RR^2`). The problem is that the 3d object takes a few seconds to render, and every time the point moves, the object has to be re-rendered. This makes the interact unusable.
So can I somehow tell Sage to just add one point to the object which it's already rendered? Note that I am pre-computing the 3d object and storing it in a variable, `g`. Then my interact function just takes coordinates as input and does
(g + point3d(x,y,z)).show()
But this is still too slow :(
----
UPDATE: The method described in the question about [fast show for cached plots](http://ask.sagemath.org/question/517/fast-show-for-cached-plots-for-interact) will probably solve this problem too!nilesFri, 25 Feb 2011 16:44:16 +0100https://ask.sagemath.org/question/7969/box removalhttps://ask.sagemath.org/question/7813/box-removal/Is there any way to remove the box surrounding 3d output?dividenotTue, 14 Dec 2010 00:52:05 +0100https://ask.sagemath.org/question/7813/animate 3d plots?https://ask.sagemath.org/question/7666/animate-3d-plots/Is there an animation function for 3d plots? Specifically, I'm looking to animate some plots drawn with Tachyon, but I don't see any animation functions either in the [Tachyon documentation](http://www.sagemath.org/doc/reference/sage/plot/plot3d/tachyon.html) or in the [3d base classes documentation](http://www.sagemath.org/doc/reference/sage/plot/plot3d/base.html). I have seen that there is an animate function for [2d plots](http://www.sagemath.org/doc/reference/sage/plot/animate.html), but it says that the input needs to be a "graphics object", and I don't think Tachyon objects are recognized as such. So maybe modifying the 2d animation functions could do what I want, but is there something else already available?
For an example, an animation where the curve changes color from magenta to white would be great:
<pre>
sage: f = lambda t: (t,t^2,t^3)
sage: t = Tachyon(camera_center=(5,0,4))
sage: t.texture('t')
sage: t.light((-20,-20,40), 0.2, (1,1,1))
sage: t.parametric_plot(f,-5,5,'t',min_depth=6)
sage: t.show()
</pre>
p.s. If this **is** already available, I'll volunteer to add information about it to the Tachyon documentation.nilesSat, 04 Sep 2010 10:59:25 +0200https://ask.sagemath.org/question/7666/