How to find common tangents between 2 ellipses ?
15 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am trying to find the common tangents between 2 ellipses by using solve function. I have f(x1) and g(x2) which are my 2 elipses (ellipse 1 the smallest and ellipse 2) equations and the 2 unknows (x1 and x2) and their derivative at each point which gives me the slope of their tangents at each point.
Then, my equations to solve are:
and here my Matlab code:
syms x1 x2
f_x1 = -sqrt(b1^2*(1-((x1-xC1)/a1)^2)) + yC1;
g_x2 = sqrt(b2^2*(1-((x2-xC2)/a2)^2)) + yC2;
f_x1_prime = b1^2*(x1-xC1)/(a1^2*sqrt(b1^2*(1-((x1-xC1)/a1)^2)));
g_x2_prime = -b2^2*(x2-xC2)/(a2^2*sqrt(b2^2*(1-((x2-xC2)/a2)^2)));
eq1 = (g_x2 - f_x1)/(x2 - x1) == f_x1_prime;
eq2 = f_x1_prime == g_x2_prime;
[S] = solve(eq1, eq2, x1, x2, 'ReturnConditions', true, 'Real', true);
assume(S.conditions)
restriction = [S.x1>xC1, S.x1<xC1+a1, S.x2<xC2, S.x2>xC2-a2];
solx = solve(restriction, S.parameters);
x1 = subs(S.x1, S.parameters, solx);
x2 = subs(S.x2, S.parameters, solx);
As result, I have something in S but the warning and no solution after having assume the condition and solve the parameter.
S =
struct with fields:
x1: [1×1 sym]
x2: [1×1 sym]
parameters: [1×1 sym]
conditions: [1×1 sym]
and the warning:
Warning: Unable to find explicit solution. For options, see help.
> In sym/solve (line 317)
In findTangentPoints (line 24)
In testTangent (line 11)
Does anyone can help me to use this function solve or see any errors ? I am going to be crazy...
Thanks a lot everyone and have a nice evening!
1 个评论
John D'Errico
2020-12-25
编辑:John D'Errico
2020-12-25
Note that as you have written f and g, you are restricting an ellipse to a specific branch of that curve. That happens as soon as you take a sqrt. In fact, a pair of non-intersecting ellipses will have FOUR common tangent lines.
采纳的回答
Matt J
2020-12-25
编辑:Matt J
2021-2-1
alpha1=30; alpha2=-45; %EDIT
a1=0.015; b1=0.020; xC1=0.13; yC1=0.09;
a2=0.08; b2=0.10; xC2=0.27; yC2=0.11;
T1=eye(3); T1(1:2,end)=[-xC1;-yC1]; %translation matrix
T2=eye(3); T2(1:2,end)=[-xC2;-yC2];
E1=diag(1./[a1^2,b1^2 -1]);
E2=diag(1./[a2^2,b2^2,-1]);
R=@(t) [cosd(t), -sind(t) 0; sind(t) cosd(t) 0; 0 0 1]; %EDIT
C1=T1.'*R(alpha1).'*E1*R(alpha1)*T1; %homogeneous ellipse equation matrix
C2=T2.'*R(alpha2).'*E2*R(alpha2)*T2;
syms Lx Ly Lz %line coefficients
equ1=[Lx,Ly,Lz]/C1*[Lx;Ly;Lz]==0; %tangent to ellipse 1
equ2=[Lx,Ly,Lz]/C2*[Lx;Ly;Lz]==0; %tangent to ellipse 2
equ3=Lx^2+Ly^2+Lz^2==1; %resolve the scale ambiguity in the coefficients
sol=solve([equ1,equ2,equ3]);
sol=double([sol.Lx,sol.Ly,sol.Lz]); %convert symbolic solutions to numeric doubles
sol=sol(2:2:end,:);%discard redundant solutions
%%% Display the solutions
fimplicit(@(x,y) qform(x,y,C1));
hold on
fimplicit(@(x,y) qform(x,y,C2));
for i=1:4
fimplicit(@(x,y) lform(x,y,sol(i,:))); %dumb warnings - ignore
end
hold off
axis equal, grid on
axis([0.1,0.4,0,.24])
function val=qform(x,y,Q)
sz=size(x);
xy=[x(:),y(:),x(:).^0];
val=reshape( sum( (xy*Q).*xy ,2) ,sz);
end
function val=lform(x,y,L)
sz=size(x);
val=reshape( [x(:),y(:),x(:).^0]*L(:) ,sz);
end
26 个评论
Matt J
2023-7-3
编辑:Matt J
2023-7-3
@Niki Amini-Naieni You would have to have studied some projective geometry for any brief explanation to make sense to you. Basically, given an ellipse, E, the equation coefficients of lines tangent to E form a dual ellipse D. Therefore, given two ellipses E1 and E2, the common tangents must therefore lie in the intersection of their duals D1 and D2.
This wiki page talks about deriving the dual ellipse when the given ellipse is non-rotated,
The extension to rotated ellipses isn't that hard.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!