How do I receive the touching points of a circle with given radius inside a curve?

1 view (last 30 days)
Hello,
I am trying to receive the two touching points of a circle inside a body that is not symmetrically shaped, to then receive the center point of this circle. For example an object with four corners, in which there is a circle of a smaller radius. The object is defined through a lot of x- and y coordinates that are loaded into matlab. I know the radius of that circle.
I know the circle equations and have tried to equal these and then solve the quadratic equation that gives me the following:
for i=1:1:length(x1)
for j=1:1:length(x2)
if x1(i)~=x2(j) && y1(i)~=y2(j)
a=1+((2*y2(j)-2*y1(i))^2)/(2*x2(j)-2*x1(i))^2;
b=(x1(i)*2*(2*y2(j)-2*y1(i))/(2*x2(j)-2*x1(i))+((-2*x2(j)^2*(2*y2(j)-y1(i))-2*y2(j)^2*(2*y2(j)-2*y1(i))+2*x1(i)^2*(2*y2(j)-2*y1(i))+2*y1(i)^2*(2*y2(j)-2*y1(i)))/(2*x2(j)- 2*x1(i))^2)-2*y1(i));
c=x1(i)^2-((2*x1(i)*(x2(j)^2+y2(j)^2-x1(i)^2-y1(i)^2))/(2*x2(j)-2*x1(i)))+((x2(j)^4+2*x2(j)^2*y2(j)^2-2*x2(j)^2*x1(i)^2-2*x2(j)^2*y1(i)^2+y2(j)^4-2*y2(j)^2*x1(i)^2-2*y2(j)^2*y1(i)^2+x1(i)^4+2*x1(i)^2*y1(i)^2+y1(i)^4)/(2*x2(j)-x1(i))^2)+y1(i)^2-rsoll^2;
My1=(-b+sqrt(b^2-4*a*c))/2*a;
My2=(-b-sqrt(b^2-4*a*c))/2*a;
if abs(My1)<abs(My2)
My=My1;
else My=My2;
end
Mx=(x2(j)^2+y2(j)^2-x1(i)^2-y1(i)^2-My*(2*y2(j)-2*y1(j)))/(2*x2(j)-2*x1(i));
But I don't know how to continue. If I try to run the function with all data it never stops running! Furthermore I defined this
for o=1:1:length(x1)
tt=sqrt((x1(o)-Mx).^2+(y1(o)-My).^2);
disp('tt:')
disp(tt)
m=sqrt(Mx^2+My^2);
disp('m:')
disp(m)
if min(tt)==rsoll
cx=Mx;
cy=My;
break
else continue
m00=m0;
m0=m;
end
end
But then the programm never stops running.
I also thought of using fminsearch but with my function:
z0=[0,0];
fun=@(z)(abs(((xx-z(1)).^2+(yy-z(2)).^2).^0.5-r^2));
z=fminsearch(fun,z0,optimset('TolX',1e-10,'TolFun',1e-10));
cx=z(1);
cy=z(2);
I only receive an error
Subscripted assignment dimension mismatch.
Error in fminsearch (line 191)
fv(:,1) = funfcn(x,varargin{:});
Does anybody have any idea on how I could solve this problem?
  2 Comments
Athul Prakash
Athul Prakash on 20 Jan 2020
Hey Nina,
I see you're looping through every possible pair of (x,y) points and solving the Circle Equation:
However, in your input 'fun' to fminsearch, you seem to be using an extra square root operation (.^0.5) which doesn't produce the correct minimizing equation.
Beyond that, solving this equation with 2 (x,y) points would give you a circle which passes through both the points, not necessarily touching (tangent to) the body at those points.
I also understand that your 2-D body is described using a set of points. Are you certain that the required circle would touch the body at these exact points? For a given shape, it could be possible that the 2 tangent points you are looking for are not a part of the sample of points that you have.

Sign in to comment.

Answers (1)

KSSV
KSSV on 20 Jan 2020
  2 Comments
Athul Prakash
Athul Prakash on 20 Jan 2020
Since the OP has only the radius of the circle, not points on the circle, how would you apply InterX to solve his problem?
Also, we still need to eliminate the intersection points which are not tangential since the circle should be touching the given shape and InterX naturally finds points where they pass through as well.

Sign in to comment.

Categories

Find more on Mathematics 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!