How can I write a program to find nodes that are in the region of two intersecting circles

3 次查看(过去 30 天)
I have written a script for two equal intersecting circles having the same radius. nodes in blue at the centre of the two circles are stationary, while others are mobile. I also generated a random moving node having different energy and successful transmit probability. The problem now is how can I write a code that will determine the nodes that fall in the intersecting boundary. Thanks

回答(1 个)

KSSV
KSSV 2016-10-21
编辑:KSSV 2016-10-21
Get the coordinates of intersection circle (this will form closed region), use inpolygon() to know whether given point lies inside closed region or outside the closed region. You may have a look on the below code:
clc; clear all ;
N1 = 100 ; N2 = 50 ;
th = linspace(0,2*pi,N1)' ;
r1 = 1. ; r2 = 1. ; % radii of circles
c1 = [0 0] ; % center of first cirlce
c2 = [1.5 0] ; % center of second circle
a1 = repmat(c1,[N1 1])+[r1*cos(th) r1*sin(th)] ;
a2 = repmat(c2,[N1 1])+[r2*cos(th) r2*sin(th)] ;
%
plot(a1(:,1),a1(:,2),'r') ;
hold on
plot(a2(:,1),a2(:,2),'r') ;
axis equal
%%Get points of fitst circle lying in second circle
in12 = inpolygon(a1(:,1),a1(:,2),a2(:,1),a2(:,2)) ;
P1 = a1(in12,:) ;
plot(a1(in12,1),a1(in12,2),'.b') ;
%%Get points of second circle lying in first circle
in21 = inpolygon(a2(:,1),a2(:,2),a1(:,1),a1(:,2)) ;
P2 = a2(in21,:) ;
plot(a2(in21,1),a2(in21,2),'.b') ;
%%form the oval / intersection boundary
R = [P1 ;P2] ;
%%Form a suare grid around ovel region
x = linspace(c1(1),c2(1),N2) ;
y = linspace(-r1,r2,N2) ;
[X,Y] = meshgrid(x,y) ;
XX = X(:) ; YY = Y(:) ;
%%Get the random points inside the region
l = 1 ;
ax = min(R(:,1)) ; bx = max(R(:,1)) ;
ay = min(R(:,2)) ; by = max(R(:,2)) ;
while l ==1
x = (bx-ax).*rand(1,1) + ax;
y = (by-ay).*rand(1,1) + ay;
in = inpolygon(x,y,R(:,1),R(:,2)) ;
if in
plot(x,y,'.g') ;
drawnow
end
end
  2 个评论
Akande Oluwole
Akande Oluwole 2016-10-21
I have gone through this and have tried to see how i can determine the region, but the answer is quite different from this particular problem since not all nodes are in the region. What I need is to be able to determine the region of intersection, and pick out those nodes that are in the intersecting region.
KSSV
KSSV 2016-10-21
That's what I suggested you already...Get the coordinates of intersection circle (this will form closed region), use inpolygon() to know whether given point lies inside closed region or outside the closed region

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by