Info
This question is closed. Reopen it to edit or answer.
How to create a 2D ring placed in 3D matrix, with user defined radius?
3 views (last 30 days)
Show older comments
I want to create a ring with user defined radius, the ring should be placed in 3D volume and the output should be only one 3D matrix containing the ring.
3 Comments
Answers (1)
KSSV
on 3 Oct 2016
clc; clear all ;
N = 100 ;
R1 = 0.5 ; % inner radius
R2 = 1 ; % outer radius
th = linspace(0,2*pi,N) ;
% inner circle
x1 = R1*cos(th) ; y1 = R1*sin(th) ;
% Outer circle
x2 = R2*cos(th) ; y2 = R2*sin(th) ;
% merge both
x = [x1 NaN fliplr(x2)] ;
y = [y1 NaN fliplr(y2)] ;
%%Make a mesh
x0 = min(x) ; x1 = max(x) ;
y0 = min(y) ; y1 = max(y) ;
xx = linspace(x0,x1,N) ;
yy = linspace(y0,y1,N) ;
[X,Y] = meshgrid(xx,yy) ;
%%Get points inside the ring
D = (X.^2+Y.^2) ;
D(D<R1) = NaN ;
D(D>R2) = NaN ;
pcolor(D) ;
shading interp ;
D will be a single matrix. Is it okay?
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!