Dibujar un rectángulo en pcshow

2 visualizzazioni (ultimi 30 giorni)
Jon López Cuesta
Jon López Cuesta il 31 Gen 2021
Risposto: Jaynik il 13 Mag 2024
Hola,
Busco dibujar un rectángulo en un pcshow y poder guardar esos puntos para poder aplicar un inpolygon después. Necesito poder hacer el rectángulo siempre del mismo tamaño y en la misma coordenada. ¿Alguien sabe cómo podría hacerlo?

Risposte (1)

Jaynik
Jaynik il 13 Mag 2024
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:
Hope this helps!

Prodotti

Community Treasure Hunt

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

Start Hunting!