# Calculate 2D normal vectors to a plane

11 visualizaciones (últimos 30 días)
Miguel Albuquerque el 4 de Mayo de 2022
Comentada: Miguel Albuquerque el 8 de Mayo de 2022
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.
##### 10 comentariosMostrar 8 comentarios más antiguosOcultar 8 comentarios más antiguos
Miguel Albuquerque el 6 de Mayo de 2022
yes it will always be the case, either horizontal or vertical lines. If they are horziontal lines, it is only needed to calculate one normal, since that normal will always be orthogonal to every horizontal line. But in case I have a vertical one, that should be different.
Thanks for the help so far
David Goodmanson el 6 de Mayo de 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.

Iniciar sesión para comentar.

Matt J el 6 de Mayo de 2022
Editada: Matt J el 6 de Mayo de 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 comentariosMostrar 11 comentarios más antiguosOcultar 11 comentarios más antiguos
Matt J el 8 de Mayo de 2022
Editada: Matt J el 8 de Mayo de 2022
Then you could do as follows,
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];
distances=vecnorm(VTransmitter_target,2,2); %transmitter to target
I=reg(i).Image;
if iscolumn(I)
Vectors_product=VTransmitter_target(:,2)./distances;
else
Vectors_product=VTransmitter_target(:,1)./distances;
end
reg(i).angle_transmitter = 180-acosd(Vectors_product);
end
Miguel Albuquerque el 8 de Mayo de 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
% 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];
distances=vecnorm(VTransmitter_target,2,2); %transmitter to target
I=reg(i).Image;
if iscolumn(I)
Vectors_product=VTransmitter_target(:,2)./distances;
else
Vectors_product=VTransmitter_target(:,1)./distances;
end
angle_transmitter = 180-acosd(Vectors_product);
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
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

Iniciar sesión para comentar.

### Categorías

Más información sobre ARM Cortex-M Processors en Help Center y File Exchange.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by