Plotting solids in space

I have an exam in vector analysis soon, and it happens quite often we're supposed to parametrize the surface of as solid. Is there a way to get maple to plot the solid so it's simpler to visualize the current situation?
Suppose for example that E is the solid defined by x^2+y^2+z^2=< 4*a^2 and x^2+y^2=>a^2 with a some constant and =< means less than or equal to and => means greater than or equal to. Suppose S is the boundary-surface of E. How do I plot S in the easiest way? It's for use for an exam so time is precious.

gkokovidis's picture

implicitplot3d

Take a look at the help files for implicitplot3d and see if that will do what you are looking for.

>?implicitplot3d

>restart:
>a:=4:
>with(plots):
>implicitplot3d(x^2+y^2+z^2>=a^2, x=-4..4, y=-4..4,z=-4..4);

After it plots, you can click on the plot and rotate it. You can change the "a" value and see what happens and alter the range values for x,y, and z as well.

Regards,
Georgios Kokovidis
Dräger Medical

John Fredsted's picture

Spherical coordinates

Maybe you know this (if so, just disregard this post), but whenever you see something like x^2 + y^2 + z^2 you should think of spherical coordinates (r,theta,phi), in which the Cartesian coordinates (x,y,z) may be parametrized as

x(r,theta,phi) := r*sin(theta)*cos(phi);
y(r,theta,phi) := r*sin(theta)*sin(phi);
z(r,theta,phi) := r*cos(theta);

They have the pleasant property

> simplify(x(r,theta,phi)^2 + y(r,theta,phi)^2 + z(r,theta,phi)^2);
                                2
                               r 

from which it follows that the surface S of the example you give can be parametrized as

x(theta,phi) := a*sin(theta)*cos(phi);
y(theta,phi) := a*sin(theta)*sin(phi);
z(theta,phi) := a*cos(theta);

Thanks for the comments. I

Thanks for the comments.
I will take a look at he implicitplot3d and see if it's any help.
I know about spherical coordinates, but thank you anyway :) I usually find it more convenient to change to cylindrical coordinates though. You always have trouble describing points on the z-axis in spherical coordinates, though I admit it has it uses from time to time.

Hmm it seems I somehow

Hmm it seems I somehow messed up my original post. Maybe it was because I tried to use the symbols "less than or equal to" (seems the forum messed that up). As I read it again now I can see I wasn't specific enough. The problem is I usually have 2 constraints:
x^2+y^2+z^2 (less than or equal to) 4a^2 and x^2+y^2 (greater than or equal to) a^2. (it is a sphere with a cylindrical hole through it). Any way to easily plot the surface of this solid?

EDIT: Ok it seems the forum doesn't like me typing "less than or equal to" symbols

John Fredsted's picture

Less than strikes again

In order to avoid that the browser interpretes < and > as the beginning and end of an HTML-tag, write them as &lt; and &gt;.

Ah yes, that seems to solve

Ah yes, that seems to solve the problem. Thank you

John Fredsted's picture

Sphere with cylindrical hole

Parametrize the sphere, using spherical coordinates:

xSphere := (theta,phi) -> 2*a*sin(theta)*cos(phi);
ySphere := (theta,phi) -> 2*a*sin(theta)*sin(phi);
zSphere := (theta,phi) -> 2*a*cos(theta);

Parametrize the cylinder, using cylindrical coordinates:

xCylinder := (phi,z) -> a*cos(phi);
yCylinder := (phi,z) -> a*sin(phi);
zCylinder := (phi,z) -> z;

Plot them as follows, using some specific, but otherwise arbitrary, value for a:

a := 1:
with(plots):
plot1 := plot3d(
	[xSphere(theta,phi),ySphere(theta,phi),zSphere(theta,phi)],
	theta = Pi/6..5*Pi/6,phi = 0..2*Pi
):
plot2 := plot3d(
	[xCylinder(phi,z),yCylinder(phi,z),zCylinder(phi,z)],
	phi = 0..2*Pi,z = -sqrt(3)*a..sqrt(3)*a
):
display(plot1,plot2,scaling = constrained);

Doug Meade's picture

Same solution, using plot3d,coords

Here is the same solution using the builtin coordinate support in plot3d:

a := 1;
S := plot3d( 2*a, theta=0..2*Pi, phi=Pi/6..5*Pi/6, coords=spherical );
C := plot3d( a, theta=0..2*Pi, z=-sqrt(3)*a..sqrt(3)*a, coords=cylindrical );
plots[display]( [S,C], scaling=constrained );

Note that my usage of theta and phi are different from those used in the previous post. In my experience, it is much more common to use theta for the angle with the postive x-axis and phi for the angle with the positive z-axis.

Doug

---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/

Common for whom?

It seems that what is common is not common. In particular, your current convention is quite uncommon for me.

It is not clear for me either, which is the divide.

After this article in Wikipedia, that is the northamerican (ie US) convention, and the rest of the world uses the other one.

On the other hand, Robert Israel in this thread argues that:

Physicists almost always (I think) use phi for the longitude and theta for colatitude, mathematicians do it the other way around.

.
I cannot say about mathematicians, but in regards to physicists I have the same impression (textbooks and papers that I can check right now seem to show that).

John Fredsted's picture

Illuminating links

Thanks for those illuminating links.

John Fredsted's picture

Spherical coordinates

Thanks for making me aware of that important simplification, which, I suppose, I would have known myself if only I would learn to carefully read the associated help pages.

However, your choice of theta and phi disagrees with the choice made in Maple itself, see ?spherical_coordinates.

Maple is largely inconsistent

Maple is largely inconsistent in this regard. Consider just a few examples:

in ?coords:

(u,v,w)...
x = u*cos(v)*sin(w)
y = u*sin(v)*sin(w)
z = u*cos(w)

in ?VectorCalculus,Coordinates:

(u,v,w) ...
x = u*cos(w)*sin(v)
y = u*sin(w)*sin(v)
z = u*cos(v)

in ?plot3d[coords]

(r,theta,phi)
...distance from the origin, r...
theta is the counterclockwise angle measured from the x-axis in the x-y plane.
phi is the angle measured from the positive z-axis, or the colatitude.

in ?Physics:-Vectors:

(r, theta, phi) = spherical coordinates
(_r, _theta, _phi) = spherical unit vectors

plus ?Physics:-Vectors:-ChangeBasis:

_i = (sin(theta)*cos(phi)*_r + cos(theta)*cos(phi)*_theta -sin(phi)*_phi)
_j = (sin(theta)*sin(phi)*_r + cos(theta)*sin(phi)*_theta + cos(phi)*_phi)
_k = (cos(theta)*_r - sin(theta)*_theta)

in ?SphericalY

...spherical coordinates (r,theta,phi)

in ?definition,sphericalcoordinates

(r, phi, theta)...
x=r*sin(phi)*cos(theta)
y=r*sin(phi)*sin(theta)
z=r*cos(phi)

For me, user friendliness means consistency throughout the whole system, much more than fancy GUI toys.

John Fredsted's picture

Seconded

I also prefer consistency throughout the system above any nifty GUI's, especially if some of these GUI's make original behaviour noisy. Here, of course, I refer to the introduction of the 2D math notation which, if I have not fundamentally misunderstood something, relies heavily on XML coding, the result, unfortunately, being that something as trivial as tabbing, compare my earlier complaints, does not work consistently anymore.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}