Extract a sphere out of a cube

4 views (last 30 days)
Mario
Mario on 29 Aug 2014
Commented: Mario on 23 Oct 2014
Hello, I have been working with points with specific distances and angles between them, because this properties are constants I can reproduce a large bulk of points, the problem is that so far I can only generate cuboids. What I need is to extract a sphere of a cube maintaining the location of the points, the easiest way that I can think of is something like define a sphere and cut-off the points outside of it, but I have no idea how to do that, any hint is very welcome.
Thank you

Accepted Answer

Michael Haderlein
Michael Haderlein on 29 Aug 2014
Do you mean something like this?
[X,Y,Z]=meshgrid(linspace(0,1,20),linspace(0,1,20),linspace(0,1,20));
x=X(:);y=Y(:);z=Z(:);
rem=((x-.5).^2+(y-.5).^2+(z-.5).^2)>.5^2;
x(rem)=[];y(rem)=[];z(rem)=[];
figure, scatter3(x,y,z)

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!