deciding whether this point under Area or not

조회 수: 1 (최근 30일)
Ahmed Hassaan
Ahmed Hassaan 2012년 3월 8일
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...?
Ahmed Hassaan
Ahmed Hassaan 2012년 3월 8일
its working thanks man :)

댓글을 달려면 로그인하십시오.

추가 답변 (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