deciding whether this point under Area or not

1 次查看(过去 30 天)
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

采纳的回答

Sean de Wolski
Sean de Wolski 2012-3-8
doc inpolygon %?
  3 个评论
Sean de Wolski
Sean de Wolski 2012-3-8
Why not?
x and y are the xv anv yv inputs in inpolygon...?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by