Polygons with true and false statements

Hi. I'm trying to make a polygon with true and false statements in a meshgrid of linear spaces. I managed to make a circle and a square, but nothigh further than that. Here's the code for mi circle and square
Circle:
xv = linspace(-32,32,256);
yv = linspace(-32,32,256);
[mx my] = meshgrid(xv,yv);
dat1 = (mx.*mx + my.*my > 16);
figure(1);imshow(dat1);
Square:
dat = zeros(128,128);
vtamx = 32;
vtamy = 32;
dat(64-vtamy/2:64+vtamy/2,64-vtamx/2:64+vtamx/2) = 1;
imshow(dat);

Answers (1)

KSSV
KSSV on 10 Jul 2020
Read about inpolygon. You can define your required polygon vertices, and inpolygon will give you indices lying inside with 1 and lying outside with 0.

Categories

Answered:

on 10 Jul 2020

Community Treasure Hunt

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

Start Hunting!