I'm trying to write a code to find the intersection between an ellipse and a circle. This is what I've got so far:
%ellipse
e=0.284576477148; %eccentricity
a=0.803468308684*150*10^6; c=e*a; b=sqrt(a^2-c^2); %parameters of ellipse
beta=linspace(0,2*pi,100);X=a*cos(beta)-b*sin(beta)+c; %ellipse is shifted
Y=a*cos(beta)+b*sin(beta);plot(X,Y,'r'), hold on%circle
r=150*10^6; %radius
x=r*cos(beta);y=r*sin(beta);plot(x,y,'b')axis squarez=[];for i=1:length(beta) f1=a*cos(beta(i))-b*sin(beta(i))+c-r*cos(beta(i)); %X coordinates of the ellipse - x coordinates of the circle
f2=a*cos(beta(i))+b*sin(beta(i))-r*sin(beta(i)); %Y coordinates - y coordinates
if f1<=0.1*10^-20 && f2<=0.1*10^-20 z=[z beta(i)]; endendfor k=1:length(z) p=r*cos(z(k)); q=r*sin(z(k)); plot(p,q,'*'), hold onend
I'm trying to look for the angle beta where the curves intersect by looking for the value of beta that makes the expressions f1 and f2 close to zero. However, this code finds too many points that are actually quite far from the intersections, no matter how low I set the tolerance (if I set it to 0 no points are shown). What am I doing wrong? Thanks!
Best Answer