MATLAB: Deciding whether this point under Area or not

area

hello, i drawn a hexagon using fill and i want to specify whether a user in it or not.
I divided the hexagon to one square and 2 triangles ,the triangles has a 4 straight line ,i calculated the straight line equations and put in matlab ,i can decide that the user in the square area so there's no problem in the square area. So the problem is i want to decide whether the user in the traingles or not. The code is below if anyone can help :
%the code
close all;clear all;clc;
r=1;ax=0;ay=0;r1=sqrt(3)*r/2;r2=(r/2);
x=[ax ax+r1 ax+r1 ax ax-r1 ax-r1];
y=[ay+r ay+r2 ay-r2 ay-r ay-r2 ay+r2];
xsquare1=ax-r1; %limits of square in x axes
square2=ax+r1;
ysquare1=ay-r2; %limits of square in y axes
ysquare2=ay+r2;
yfirstline=(ax/sqrt(3))+ay-(x/sqrt(3))+r; %straight lines eqns
ysecondline=(-ax/sqrt(3))+ay+(x/sqrt(3))+r;
ythirdline=(-ax/sqrt(3))+ay+(x/sqrt(3))-r;
yfourthline=(ax/sqrt(3))+ay-(x/sqrt(3))-r;
fill(x,y,'w');grid on ;hold on ;plot(ax,ay,'bo')
RN1x=0.6;RN1y=0.3; %this is the user axes;
if ((RN1x > xsquare1)&&(RN1x < xsquare2))&&((RN1y > ysquare1)&&(RN1y < ysquare2))&&(RN1y < yfirstline)&&(RN1y < ysecondline)&&(RN1y < ythirdline)&&(RN1y < yfourthline)
pass=1
else
pass=0
end

Best Answer

doc inpolygon %?