5 views (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?

KSSV
on 20 Jan 2020

Use this:

Also you need not to use loops as Athul Prakash commented.

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.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/500615-how-do-i-receive-the-touching-points-of-a-circle-with-given-radius-inside-a-curve#comment_787790

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/500615-how-do-i-receive-the-touching-points-of-a-circle-with-given-radius-inside-a-curve#comment_787790

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/500615-how-do-i-receive-the-touching-points-of-a-circle-with-given-radius-inside-a-curve#comment_787923

⋮## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/500615-how-do-i-receive-the-touching-points-of-a-circle-with-given-radius-inside-a-curve#comment_787923

Sign in to comment.