Find if point lies within n circles

조회 수: 3 (최근 30일)
Saptarshi Bhattacharjee
Saptarshi Bhattacharjee 2012년 1월 7일
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 :)

답변 (1개)

Saptarshi Bhattacharjee
Saptarshi Bhattacharjee 2012년 1월 7일
Update : I think the problem is because when I am computing the value of t from the line
t=(p(1)-c(i,1))^2+(p(2)-c(i,2))^2-r^2;
the output is coming as
t =
1.6813e-004
I think this is making the problem during the check and that's why the points are getting omitted. Any idea why the result is i terms of e, and how can I change that to a normal value(as in decimal)??

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by