How can I find the position of the center point of a circle tangent to two ellipses?
3 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
Given the information about two ellipses, I want to know how to find a circle with a fixed radius tangent to the ellipse.
When we know information about ellipses E1 and E2, we want to know the center point of circle C.
I first tried the following way
I solve for the circle parameters v1,v2 plus the two points of tangency x1,y1,x2,y2
That's 6 unknowns, and 6 equations
I was trying to calculate the unknown using MATLAB's solve function.
Below is the code I wrote in matlab
%% Ellipse information
% E1 coeff
% ax^2 + bxy + cy^2 + dx + ey + f=0
a=0.06137;
b=-0.61943;
c=6.23450/2;
d=0/2;
e=0/2;
f=-0.28671;
%
% % E2 coeff
% % a1x^2 + b1xy + c1y^2 + d1x + e1y + f1=0
a1=0.16785;
b1=1.00923;
c1=6.20813/2;
d1=0.74001/2;
e1=3.73117/2;
f1=0.1492;
%% Ellipse plot
syms x y
% ellipse3=(x*cs1+y*sn1)^2/(a_1^2)+(-x*sn1+y*cs1)^2/(b_1^2)-1==0
ellipse1=a*x^2 + b*x*y + 2*c*y^2 + 2*d*x + 2*e*y + f == 0
ellipse2=a1*x^2 + b1*x*y + 2*c1*y^2 + 2*d1*x + 2*e1*y + f1 == 0
figure(1)
fimplicit(ellipse1)
% fimplicit(ellipse3)
hold on
fimplicit(ellipse2)
%% Find circles
r=50; % circle radius
% x0, y0 : Points of tangency (E1, C)
% x1, y1 : Points of tangency (E2 ,C)
syms x0 y0 x1 y1 v1 v2 % 6 unknowns
equ1=a*x0^2 + b*x0*y0 + 2*c*y0^2 + 2*d*x0 + 2*e*y0 + f == 0 % E1(x0,y0)
equ2=a1*x1^2 + b1*x1*y1 + 2*c1*y1^2 + 2*d1*x1 + 2*e1*y1 + f1 == 0 % E2(x1,y1)
equ3=(x0-v1)^2+(y0-v2)^2-r^2==0 % C(x0,y0)
equ4=(x1-v1)^2+(y1-v2)^2-r^2==0 % C(x1,y1)
% Jacobian Matrix
Jacob_E1=jacobian(a*x0^2 + b*x0*y0 + 2*c*y0^2 + 2*d*x0 + 2*e*y0 + f,[x0,y0]); % Jacobian Matrix of E1(x0,y0)
Jacob_E2=jacobian(a1*x1^2 + b1*x1*y1 + 2*c1*y1^2 + 2*d1*x1 + 2*e1*y1 + f1,[x1,y1]); % Jacobian Matrix of E2(x1,y1)
Jacob_C_xy=jacobian((x0-v1)^2+(y0-v2)^2-r^2,[x0,y0]); % Jacobian Matrix of C(x0,y0)
Jacob_C_x1y1=jacobian((x1-v1)^2+(y1-v2)^2-r^2,[x1,y1]); % Jacobian Matrix of C(x1,y1)
Jacob_combine_E1C=[Jacob_E1 ; Jacob_C_xy]; % jacobian of E1(x0,y0),C(x0,y0)
Jacob_combine_E2C=[Jacob_E2 ; Jacob_C_x1y1]; % jacobian of E2(x1,y1),C(x1,y1)
% Determinant of Jacobian
Det_Jacob_E1C=det(Jacob_combine_E1C); % Determinant of [E1(x0,y0) ; C(x0,y0)]
Det_Jacob_E2C=det(Jacob_combine_E2C); % Determinant of [E2(x0,y0) ; C(x0,y0)]
equ5=Det_Jacob_E1C==0; % Determinant of (jacbian(E1) ; jacobian(C))
equ6=Det_Jacob_E2C==0; % Determinant of (jacobian(E2) ; jacobian(C))
sol=solve([equ1,equ2,equ3,equ4,equ5,equ6]); % find roots
but it didn't work when Matlab finds roots (last line)
What did I do wrong..?
----------------------------------------------------------------------------------------------------------------------
If we can't do it this way, I'd like to discuss another way.
If you look at the link below, the ellipse is expressed as a matrix and the straight line tangent to the two ellipses is calculated using solve. I wonder if the circle can be obtained in the same way.
https://kr.mathworks.com/matlabcentral/answers/635464-how-to-find-common-tangents-between-2-ellipses
If an ellipse and a circle are expressed as a matrix, they can be expressed in the following quadratic form.
Isn't there a way to use matrices A, B, and C to formulate an expression only for the unknowns v1 and v2?
1 个评论
回答(1 个)
SAI SRUJAN
2023-10-20
Hi ,
I understand that you are trying to find the center point of a circle with a fixed radius 'r' which is tangent to two ellipses.
We assume that the intersection of circle and ellipse A as (x1,y1) and intersection of circle and ellipse B as (x2,y2). Additionally centre point of circle as (a,b).
The following six equations are important as we proceed to finding the centre point of the circle
- Equation of ellipse A.
- Equation of ellipse B.
- Equation of point (x1,y1) on the circle.
- Equation of point (x2,y2) on the circle.
- Distance between centre of circle and centre of ellipse A is equal to the sum of radius and distance between (x1,y1) and centre of ellipse A.
- Distance between centre of circle and centre of ellipse B is equal to the sum of radius and distance between (x2,y2) and centre of ellipse B.
You can follow the below given example to model your equations.
syms x1 x2 y1 y2 x y a b
% In this example
% radius of circle = 4
% centre of ellipse A = (2,1)
% centre of ellipse B = (10,1)
% Point (x1,y1) is on ellipse A
eqn1 = (x1-2)^2/4+(y1-1)^2==1;
% Point (x2,y2) is on ellipse B
eqn2 = (x2-10)^2/4+(y2-1)^2==1;
% Point (x1,y1) is on the circle.
eqn3 = (x1-a)^2+(y1-b)^2==16;
% Point (x2,y2) is on the circle.
eqn4 = (x2-a)^2+(y2-b)^2==16;
% Distance between centre of circle and ellipse A is equal to the
% sum of raidus and distance between (x1,y1) and centre of ellipse A
eqn5 = (a-2)^2 + (b-1)^2==16;
% Distance between centre of circle and ellipse A is equal to the
% sum of raidus and distance between (x1,y1) and centre of ellipse A
eqn6 = (a-10)^2 + (b-1)^2==16;
solve([eqn1 eqn2 eqn3 eqn4 eqn5 eqn6],'Real',true);
You can refer to the following documentation to understand more about "solve" function in MATLAB.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Equation Solving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!