ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 03 Feb 2019 07:47:58 -0600How plot revolution of a circle to generate a sphere by animation view?http://ask.sagemath.org/question/45287/how-plot-revolution-of-a-circle-to-generate-a-sphere-by-animation-view/ I would like to plot a sphere $x^2+y^2+z^2=4$ by revolving a circle $x^2+y^2=4$ with respect to diameter. The whole revolution process will be shown by animation. How can I do this? GeometrySun, 03 Feb 2019 07:47:58 -0600http://ask.sagemath.org/question/45287/How to plot a diagram of a circle obtained by section of a sphere by a planehttp://ask.sagemath.org/question/45285/how-to-plot-a-diagram-of-a-circle-obtained-by-section-of-a-sphere-by-a-plane/A circle is a section of a sphere by a plane, the equation
\begin{equation}
x^2+y^2+z^2+2gx+2fy+2hz+d=0\tag{1}
\end{equation}
and
\begin{equation}
ax+by+cz=p\tag{2}
\end{equation}
together represent a circle.
How do I plot like these diagram for given $g,f,h,a,b,c,p$. How to input by using @interact for the parameter $a,b,c,p$ to move the plane through the sphere ?
![image description](https://www.real-world-physics-problems.com/images/xphysics_bowling_1.png.pagespeed.ic.Qx3rjy72P9.png)MKSSun, 03 Feb 2019 07:31:32 -0600http://ask.sagemath.org/question/45285/Plotting spherical datahttp://ask.sagemath.org/question/8448/plotting-spherical-data/I'd like to know how to plot spherical data in a 3D plot (or to request this feature).
Basically, I have a list of data points in spherical coordinates which represent an antenna pattern. I'd like to plot them and have it look something like this:
http://i.imgur.com/35Lyh.png
My data is only taken every 15 degrees. So I can't do something like this person did:
http://ask.sagemath.org/question/512/plotting-in-3d-in-spherical-coordinates
The reason is that if I create a continuous interpolated function I'd be fabricating data (unless I can re-create a picture like the one above closely).
Ideally a spherical list plot would be ideal, but it seems like the current list plot is only cartesian.
After I successfully get my data plotted, the next steps for my antenna plot viewer would be
1) Make the color map scale set-able (so that multiple antenna plots have colors on the same scale, even if data ranges are different).
2) Make grid-lines visible, like on my picture above.
3) Apply a bicubic interpolation to my data mesh, so it would then look like this (for visual purposes): http://i.imgur.com/U4hPW.png
4) Make the xyz axes visible, like the pic.
All these seem pretty easy, except maybe #2, if anyone knows how that could be done it would be greatly appreciated.
Thanks so much everyone for working on this software. I look forward to this becoming a great tool for engineers and scientists. JasonSun, 06 Nov 2011 18:49:06 -0600http://ask.sagemath.org/question/8448/2D interpolating function from numpy arrays to spherical-plot3dhttp://ask.sagemath.org/question/8424/2d-interpolating-function-from-numpy-arrays-to-spherical-plot3d/I need to plot an antenna emission pattern. I am importing data from a tabbed .txt file (theta[i,j],phi[i,j],r[i,j]) as numpy arrays. I then employ the same data to build a 2D interpolating function with the scipy module scipy.interpolate.interp2d. The interpolating function successfully works in plot3d, but somehow breaks spherical_plot3d. Is there anyway to build a working 2D interpolating function for spherical_plot3D?
-----Toy Data---------
v_phi=array([ 0. , 1.57079637, 3.14159274, 4.71238911, 6.28318548])
v_theta=array([ 0. , 0.78539819, 1.57079637, 2.35619456, 3.14159274])
m_r=array([[ 0.16763356, 0.25683223, 0.16649297, 0.10594339,
0.55282422],
[ 0.16763356, 0.19993708, 0.31403568, 0.47359696,
0.55282422],
[ 0.16763356, 0.25683223, 0.16649297, 0.10594339,
0.55282422],
[ 0.16763356, 0.19993708, 0.31403568, 0.47359696,
0.55282422],
[ 0.16763356, 0.25683223, 0.16649297, 0.10594339,
0.55282422]])
------Traceback from spherical_plot3d---------
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_326.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("c3BoZXJpY2FsX3Bsb3QzZChmLCh4LDAsMipwaSksKHksMCxwaSksY21hcD0ncGluaycsYWRhcHRpdmU9VHJ1ZSkuc2hvdyhhc3BlY3RfcmF0aW89KDEsMSwxKSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpR1mM9J/___code___.py", line 3, in <module>
exec compile(u"spherical_plot3d(f,(x,_sage_const_0 ,_sage_const_2 *pi), (y,_sage_const_0 ,pi),cmap='pink',adaptive=True).show(aspect_ratio=(_sage_const_1 ,_sage_const_1 ,_sage_const_1 ))" + '\n', '', 'single')
File "", line 1, in <module>
File "base.pyx", line 1052, in sage.plot.plot3d.base.Graphics3d.show (sage/plot/plot3d/base.c:9313)
File "base.pyx", line 957, in sage.plot.plot3d.base.Graphics3d._process_viewing_options (sage/plot/plot3d/base.c:9112)
File "base.pyx", line 198, in sage.plot.plot3d.base.Graphics3d._determine_frame_aspect_ratio (sage/plot/plot3d/base.c:3404)
File "base.pyx", line 214, in sage.plot.plot3d.base.Graphics3d._safe_bounding_box (sage/plot/plot3d/base.c:3521)
File "parametric_surface.pyx", line 318, in sage.plot.plot3d.parametric_surface.ParametricSurface.bounding_box (sage/plot/plot3d/parametric_surface.c:2991)
File "parametric_surface.pyx", line 366, in sage.plot.plot3d.parametric_surface.ParametricSurface.triangulate (sage/plot/plot3d/parametric_surface.c:3521)
File "parametric_surface.pyx", line 361, in sage.plot.plot3d.parametric_surface.ParametricSurface.triangulate (sage/plot/plot3d/parametric_surface.c:3451)
File "parametric_surface.pyx", line 576, in sage.plot.plot3d.parametric_surface.ParametricSurface.eval_grid (sage/plot/plot3d/parametric_surface.c:5152)
File "<string>", line 4, in <lambda>
File "expression.pyx", line 3501, in sage.symbolic.expression.Expression.substitute (sage/symbolic/expression.cpp:15529)
File "expression.pyx", line 2089, in sage.symbolic.expression.Expression.coerce_in (sage/symbolic/expression.cpp:10788)
File "parent_old.pyx", line 229, in sage.structure.parent_old.Parent._coerce_ (sage/structure/parent_old.c:3420)
File "parent.pyx", line 1047, in sage.structure.parent.Parent.coerce (sage/structure/parent.c:7734)
TypeError: no canonical coercion from <type 'numpy.ndarray'> to Symbolic Ring
------------Code-------------
#importing Libraries
import numpy as np
import scipy
import scipy.interpolate
#Importing data
data=np.loadtxt('/home/giova/data/work/electrodynamics/gmm/shell/maps/test.msc')
#getting the data
theta=data[:,0]
phi=data[:,1]
r=data[:,2];
#reshaping the data
side=sqrt(len(r));m_r=r.reshape(side,side);m_r=m_r.T;
v_theta=theta[::side]
v_phi=phi[0:side]
#building interpolating 2D function
f=scipy.interpolate.RectBivariateSpline(v_phi,v_theta,m_r)
#plotting the function
x,y = var('x,y')
plot3d(f,(x,0,2*pi),(y,0,pi))
#Spherical Plotting
x,y = var('x,y')
spherical_plot3d(f,(x,0,2*pi),(y,0,pi)) Does not work!!!!!
#Workaround
def g(s,t):
out1=f(s,t).tolist()
out2=out1[0][0]
return out2
spherical_plot3d(g,(x,0,2*pi),(y,0,pi)) Does work!!!!!GiovanniMon, 31 Oct 2011 01:37:11 -0500http://ask.sagemath.org/question/8424/Plotting in 3D in spherical coordinateshttp://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 01:28:25 -0500http://ask.sagemath.org/question/8081/