No soy hablante nativa de español, así que intentaré responder esta pregunta en inglés. Gracias por su comprensión.
I understand that you want to draw a rectangle in "pcshow" and save those points to apply "inpolygon" later. You also want the rectangle to have the same size and coordinates.
To ensure the rectangle is always the same size and located at the same coordinates, you should first define its corners explicitly. You can do the same as follows:
% Rectangle size
width = ; % Width of the rectangle
height = ; % Height of the rectangle
% Center point of the rectangle
cx = ; % X coordinate of the center
cy = ; % Y coordinate of the center
cz = ; % Z coordinate (height) of the center
% Calculating the corner points based on the center and size
rectangleCorners = [cx - width/2, cy - height/2, cz; % Bottom left
cx + width/2, cy - height/2, cz; % Bottom right
cx + width/2, cy + height/2, cz; % Top right
cx - width/2, cy + height/2, cz]; % Top left
Once the corners have been obtained, you can save them as a '.mat' file for later use as follows:
save('rectangleCorners.mat', 'rectangleCorners');
% Load the rectangle corners from the .mat file
load('rectangleCorners.mat', 'rectangleCorners');
You can directly use the variable 'rectangleCorners' after loading:
rectX = rectangleCorners(:,1);
rectY = rectangleCorners(:,2);
% Assuming X, Y are the coordinates of points to test
% Check which points are inside the rectangle
inside = inpolygon(X, Y, rectX, rectY);
You can refer to the following documentation to read more about each function:
- https://www.mathworks.com/help/matlab/ref/inpolygon.html
- https://www.mathworks.com/help/matlab/ref/save.html
- https://www.mathworks.com/help/matlab/ref/load.html
Hope this helps!