plot transperant 3d sphere

HI.
How do I plot a transperant sphere within an existing 3d plot in which I already have ploted some analytical results?
the sphere need to have center in: x=16,55 y=14,85 z=9,15 and r=24,04
the x-axe has dobbelt unit compaired with y and z.
schal I use sphere or scatter3?
reguards Dorrit

 Respuesta aceptada

Dorrit
Dorrit el 10 de Mayo de 2011

1 voto

I want the grid lines but no color betwin the grid, because i have som point plotted that i wand to see insiden the sphere.

7 comentarios

Andrew Newell
Andrew Newell el 10 de Mayo de 2011
See above for a demo of this.
Patrick Kalita
Patrick Kalita el 10 de Mayo de 2011
In that case, you want to set the 'FaceColor' to 'none' (and you can forgo setting 'FaceAlpha'). I've edited my answer.
Dorrit
Dorrit el 10 de Mayo de 2011
I have tryed what you said, but i get a sphere in 2d in a seperat plot and not in the same 3d plot that i have alredy maid with my other set of data.-why?- I use hold on commando.
Andrew Newell
Andrew Newell el 10 de Mayo de 2011
If you're referring to my answer, take out the FIGURE command. In general, it's a good idea to add your comments to the appropriate answer.
Matt Fig
Matt Fig el 10 de Mayo de 2011
I must admit, this really was the best answer to the original question. ;)
Dorrit
Dorrit el 10 de Mayo de 2011
pleas give me a chance to learn how this site works before you juds me.
I just got the program and have never worked with it before and my english is not very good.
I,m more use to use Wolfram Matematica
Andrew Newell
Andrew Newell el 12 de Mayo de 2011
I quite understand how easy it is to click the wrong Accept This Answer button, so I'm not judging. I would recommend, however, that you vote for the good answers below.

Iniciar sesión para comentar.

Más respuestas (3)

Sean de Wolski
Sean de Wolski el 6 de Mayo de 2011

6 votos

One way:
Make a binary sphere using the formula for a sphere: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F
Then take calculate its isosurface using the isosurface function and make a patch of that with a low facealpha. E.g:
S = formula_for_a_sphere_applied;
[fv] = isosurface(S,0);
patch(fv,'facecolor','g','facealpha',0.2,'edgecolor','none');
Andrew Newell
Andrew Newell el 9 de Mayo de 2011

5 votos

As you suggested yourself, you can use sphere to generate the sphere:
r = 24.04;
[x,y,z] = sphere(50);
x0 = 16.5; y0 = 14.85; z0 = 9.15;
x = x*r + x0;
y = y*r + y0;
z = z*r + z0;
% Then you can use a surface command as Patrick suggests:
figure
lightGrey = 0.8*[1 1 1]; % It looks better if the lines are lighter
surface(x,y,z,'FaceColor', 'none','EdgeColor',lightGrey)
hold on
I'm in an artistic mood, so here is a ring of spheres inside.
r = 15;
theta = (0:.2:6)/3*pi;
x = r*cos(theta) + x0;
y = r*sin(theta) + y0;
z = z0*ones(size(x));
plot3(x,y,z)
I = 1:5:26;
h = plot3(x(I),y(I),z(I),'o','MarkerFaceColor','b','MarkerSize',24);
axis equal % so the sphere isn't distorted
view([1 1 0.75]) % adjust the viewing angle
zoom(2)
Patrick Kalita
Patrick Kalita el 9 de Mayo de 2011

1 voto

The best way to do this is to just use the surface command, given that it is relatively easy to generate the x, y, and z data that define a sphere.
Here's an example:
% Generate the x, y, and z data for the sphere
r = 5 * ones(50, 50); % radius is 5
[th, phi] = meshgrid(linspace(0, 2*pi, 50), linspace(-pi, pi, 50));
[x,y,z] = sph2cart(th, phi, r);
x = x + 16; % center at 16 in x-direction
y = y + 40; % center at 40 in y-direction
z = z + 2; % center at 2 in z-direction
% Let's say that this is how we make the existing 3D plot
surf(peaks);
% Now we use the surface command to add the sphere. We just need to set the FaceColor as desired.
surface(x,y,z,'FaceColor', 'none')

Etiquetas

Preguntada:

el 6 de Mayo de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by