How to generate a 2D sphere matrix and not a disc
Mostrar comentarios más antiguos
Hello,
I have a question for all, how can i create a matrix image 512*512 of a half sphere ? It is not a disk but a half sphere that can be said that it is 2.5D and not 2D.
An image example generated automatically : (I want to have an image like this but generated with matlab code :-) )

When we show this image by 'surf' function we get this result :

Does anyone have an idea on how to generate this half sphere with a matlab itterative code ? thank you
2 comentarios
Respuesta aceptada
Más respuestas (1)
Bruno Luong
el 10 de Oct. de 2018
Editada: Bruno Luong
el 10 de Oct. de 2018
phi=linspace(0,2*pi,512);
theta=linspace(0,pi/2,512).';
x=cos(phi).*cos(theta);
y=sin(phi).*cos(theta);
z=ones(size(phi)).*sin(theta);
surf(x,y,z,'edgecolor','none')
axis equal
3 comentarios
telkab01
el 10 de Oct. de 2018
Bruno Luong
el 10 de Oct. de 2018
Editada: Bruno Luong
el 10 de Oct. de 2018
Sorry to be pedantic, but the first solution you accept actually is not a half sphere but a half-sphere surrounded by a flat rectangle with a hole in the middle, the hole is take place by the half-sphere (use SURF to see this evidence).
You could replace the rectangle part by NaN, but then if you plot the surface using SURF you'll get the "hairs" in the border.
But if it meets your need than I'm OK.
Rik
el 10 de Oct. de 2018
You're being pedantic, or I'm caught red-handed in a trick, either way you bring up an important distinction between our solutions, which I'dd encourage telkab to explore.
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!