Effacer les filtres
Effacer les filtres

deciding whether this point under Area or not

2 vues (au cours des 30 derniers jours)
Ahmed Hassaan
Ahmed Hassaan le 8 Mar 2012
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

Réponse acceptée

Sean de Wolski
Sean de Wolski le 8 Mar 2012
doc inpolygon %?
  3 commentaires
Sean de Wolski
Sean de Wolski le 8 Mar 2012
Why not?
x and y are the xv anv yv inputs in inpolygon...?
Ahmed Hassaan
Ahmed Hassaan le 8 Mar 2012
its working thanks man :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by