How calculate the points inside the square and triangle?
2 次查看(过去 30 天)
显示 更早的评论
I did calculate the points (scatteres) located inside the circle as presented in the code. I'm wondering how I can do it for square and triangle?
I cannot find proper tag for this question.
Phantom.x_size = 50/1000; % Width of phantom [mm]
Phantom.y_size = 10/1000; % Transverse width of phantom [mm]
Phantom.z_size = 60/1000; % Height of phantom [mm]
Phantom.z_start = 30/1000; % Start of phantom surface [mm];
N = Calculate_number_of_scatterers(Phantom);
N = 1000*ceil(N/1000);
% Create the general scatterers
x = (rand (N,1)-0.5)*Phantom.x_size;
y = (rand (N,1)-0.5)*Phantom.y_size;
z = rand (N,1)*Phantom.z_size + Phantom.z_start;
% Generate the amplitudes with a Gaussian distribution
amplitudes = randn(N,1);
%Make the cyst
r = 15/2/1000; %radius of cyst[mm]
xc = 10/1000; %place of the cyst
zc = 40/1000 + Phantom.z_start;
inside = ( ((x-xc).^2 + (z-zc).^2) < r^2); % scatteres inside the cyst
amplitudes = amplitudes .* (1-inside); % amplitude of the scatteres inside the cyst
Phantom.positions = [x y z];
Phantom.amplitudes = amplitudes;
figure; plot3(Phantom.positions(:,1), Phantom.positions(:,3),Phantom.amplitudes,'.')
回答(1 个)
KSSV
2018-6-6
Read about inpolygon. This function will give you indices of the points lying inside a polygon.
2 个评论
Image Analyst
2018-6-10
You forgot to include Calculate_number_of_scatterers() so we can't do much. Give us code that at least runs and demonstrates why inpolygon() does not solve your problem.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!