How calculate the points inside the square and triangle?

5 vues (au cours des 30 derniers jours)
Neda
Neda le 6 Juin 2018
Commenté : Neda Azarmehr le 10 Juin 2018
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,'.')

Réponses (1)

KSSV
KSSV le 6 Juin 2018
Read about inpolygon. This function will give you indices of the points lying inside a polygon.
  2 commentaires
Neda
Neda le 10 Juin 2018
thank you for the comment, it's true, but it inpolygon didn't solve my issue. I used
[in,out] = inpolygon(xc,zc,x,z);
amplitudes = amplitudes .* (1-in);% amplitude of the scatteres inside the cyst
Image Analyst
Image Analyst le 10 Juin 2018
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by