
How to fade out the edges of random spheres?
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm using the method described here to generate 3D points that are uniformly distributed on a sphere. I combine several of those together with uniformly distributed scatters to get something like this:

The points are stored in a Nx3 vector. The difference of density in the spheres and outside would be lower later, this is just for better visualisation.
My goal now is to fade out the edges of the spheres a bit, so that there are not so sharp edges but a more smooth transition. How could I achieve this? I was thinking of a gaussian filter but couldn't get the desired result.
As a student I have access to most toolboxes if that's required.
댓글 수: 0
답변 (1개)
Dave B
2021년 1월 4일
Starting in R2020b you can set the alpha independently when using scatter, so I used scatter for a large sphere.
If 2020b isn't an option, you could potentially use color (again, I'd recommend scatter for this) and choose colors near the edges that are closer to white.
rng(0,'twister')
n=10000;
rvals = 2*rand(n,1)-1;
elevation = asin(rvals);
azimuth = 2*pi*rand(n,1);
radii = 3*(rand(n,1).^(1/3));
[x,y,z] = sph2cart(azimuth,elevation,radii);
figure(1);clf
scatter3(x,y,z,10,'o','filled','AlphaData',max(radii)-radii.^2,'MarkerFaceAlpha','flat')
axis equal

댓글 수: 3
Dave B
2021년 1월 4일
Ah that makes, sense, you just wanted less points near the outside of the sphere. How about if you just changed the exponent in radii, e.g.
radii = 3*(rand(n,1).^2);
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!