Calculate 2D normal vectors to a plane

19 views (last 30 days)
Hey to all, Im having difficulties on trying to get normal vectors to a 2D plane.
I have a AoI=200 x 200 matrix, composed by zeros and ones( I define the position of the ones in the matrix), so, a binary matrix.
I want to get the normal vectors to the blocks where the ones are, imagine I have a target(1 in matrix) in row 2, column 4:7. I want to get this normal to this plane. And if i have more than one target, get all the normals to all the targets.
Thank you in advance.
  10 Comments
David Goodmanson
David Goodmanson on 6 May 2022
Hi Jan, re the comment of May 4 According to common usage and, for example the Wolfram Mathworld site, a 'normal vector' is a vector of any length that is perpendicular to a plane (or more generally one of many vectors perpendicular to a line), and a 'normalized vector' is one of unspecified direction that has unit length.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 6 May 2022
Edited: Matt J on 6 May 2022
reg=regionprops(bwconncomp(AoI,4),'Image');
N=numel(reg);
normals=nan(2,N);
for i=1:N
I=reg(i).Image; %EDITED
if isscalar(I)
continue;
elseif iscolumn(I)
normals(:,i)=[0;1];
elseif isrow(I)
normals(:,i)=[1;0];
end
end
  13 Comments
Miguel Albuquerque
Miguel Albuquerque on 8 May 2022
So now I have this: I also calculated angle receiver, between target and receiver (8,15). But In order to proceed with my code, to calculate status and so on, I needed for angle receiver, and angle transmitter to be calculate individually. So imagine in (2,5) there is a target, for this I will check if its vertical or horziontal, calculate vector-transmitter, vector-receiver and its angles to the normal to the line. And then check for that target status and so on, proceed with my code. In your code i have this solution
Angle_transmitter=[180;170;35;...]
I needed angle transmitter=[180] and on next iteration angle transmitter=[170] .... Same with distances, vectors_product
Thanks a lot for saving my skin on this code... Is there anyway I can show my apreciation?
Lp=1; % Pixel length
Nx= zeros(1,400); % dimension in x, horizontal of surveillance area
Ny= zeros(400,1); % dimension in y, vertical of surveillance area
AoI=Nx.*Ny; % Surveillance area
% Horizontal targets
AoI(2,(5:10)) = 1; % define target, set row 4, from column 7-10 to 1, no correlation to Lp
AoI(5,(5:7)) = 1;
AoI(6,10) = 1;
normal_ntarget1=[1 0]; % Define a normal vector to the target
% Receiver antenna position
X_receiver=8;
Y_receiver=15;
% Transmitter antenna position
X_transmitter=8;
Y_transmitter=5;
reg=regionprops(bwconncomp(AoI,4),'Image','PixelList');
N=numel(reg);
for i=1:N %loop over vertical/horizontal target groups
X_target=reg(i).PixelList(:,2);
Y_target=reg(i).PixelList(:,1);
VTransmitter_target=[X_target-X_transmitter Y_target-Y_transmitter];
VTarget_receiver=[X_receiver-X_target Y_receiver-Y_target]; % Vector Target-receiver
distances=vecnorm(VTransmitter_target,2,2); %transmitter to target
distances2=vecnorm(VTarget_receiver,2,2); %transmitter to target
I=reg(i).Image;
if iscolumn(I)
Vectors_product=VTransmitter_target(:,2)./distances;
Vectors_product2=VTarget_receiver(:,2)./distances2;
else
Vectors_product=VTransmitter_target(:,1)./distances;
Vectors_product2=VTarget_receiver(:,1)./distances2;
end
angle_transmitter = 180-acosd(Vectors_product);
angle_receiver = acosd(Vectors_product);
status=snell_function(angle_transmitter,angle_receiver);
Pr = LoS_receiver(X_receiver,Y_receiver,X_target,Y_target,AoI);
Pt = LoS_transmitter(X_transmitter,Y_transmitter,X_target,Y_target,AoI);
continue
if status ==1 && Pt ==1 && Pr ==1
R1=sqrt( (X_transmitter-X_target).^2 + (Y_transmitter-Y_target).^2); % Distance transmitter-target in meters
R2=sqrt( (X_receiver-X_target).^2 + (Y_receiver-Y_target).^2); % Distance Receiver-target in meters
Rd=sqrt( (X_receiver-X_transmitter).^2 + (Y_receiver-Y_transmitter).^2); % Distance Transmitter-Receiver in meters
fprintf('\n Coordenadas do alvo(%d,%d)',X_target,Y_target);
fprintf('\n Distância transmissor-alvo R1 %4.2f metros',R1);
fprintf('\n Distância alvo-recetor R2 %4.2f metros',R2);
fprintf('\n Distância transmissor-recetor Rd %4.2f metros',Rd);
continue
end
end

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by