Find if point lies within n circles
Show older comments
I have a problem where I am trying to find which of the points in iv1 of code below lies within all the circles specified by C(it stores the centres of n circles, nx2 matrix). My code is shown below:
function [ctv]=ctrivec(iv1,c,r)
ctv=zeros(3,2);
n=size(iv1,1);
count=1;
flag=0;
for i=1:1:n
flag=findptin(iv1(i,:),c,r);
if flag==1
ctv(count,:)=iv1(i,:);
count=count+1;
end
end
end
function [f]=findptin(p,c,r)
n=size(c,1);
f=1;
for i=1:1:n
t=(p(1)-c(i,1))^2+(p(2)-c(i,2))^2-r^2;
if t>0
f=0;
return;
end
end
end
I am supposed to get three coordinates a smy output in the ctv vector(incidentally ctv stores the coordinates of the circular triangle formed by the intersection of 3 circles(the area of intersection to be specific)). However, I am not getting the desired outputs.
Example - consider the given case c=[3 5;7 2;2 2];
iv1 =
4.5000 0.3417
4.5000 3.6583
4.9187 2.6938
0.0813 4.3062
5.9950 4.8266
4.0050 2.1734
For this I should get the three points on ctv, but i am not getting it..
Pl help me out with this
P.S. I have not vectorized the code as i am not comfortable with this feature of MATLAB, I am more of a C programmer. Ignore this :)
Answers (1)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!