How calculate the points inside the square and triangle?

조회 수: 2 (최근 30일)
Neda
Neda 2018년 6월 6일
댓글: Neda Azarmehr 2018년 6월 10일
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
KSSV 2018년 6월 6일
Read about inpolygon. This function will give you indices of the points lying inside a polygon.
  댓글 수: 2
Neda
Neda 2018년 6월 10일
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 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 CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by