I am trying to draw the Fresnel ellipse and a line between two points (x1,y1) and (x2,y2). In addition I am trying to rotate the ellipse using atan2. First, I cannot understand why the drawn red axis is not same with ellipse's imaginative major axis. They have both different angle and length. Secondly, I am not sure if I am using the correct formulas for drawing a ellipse with rotation.
f=217.25;
Ht=45;
Hr=2.5;
figure (10);
x1=0;
x2=2.415512976422468e+04;
y1=2.609242854399548e+02+Ht;% Ht is trasmitter antenna height
y2=40.819199999995895+Hr;% Hr is receiver antenna height
% plot line of sight (major axis of ellipse)
hold on,plot([x1 x2],[y1 y2],'r')
% Plot 1st Fresnel zone - ELLIPSE
fr=f*1e6;% f in Hz
c=2.997925e8;% speed of light in m/s
lambda=c/fr; % wavelength in meters
a = 1/2*sqrt((x2-x1)^2+(y2-y1)^2); %majoraxis/2
r = sqrt(lambda*a/2);% b=r %secondaxis/2
t = linspace(0,2*pi,300);
X = a*cos(t);
Y = r*sin(t);
w = atan2(y2-y1,x2-x1); %angle of two points
x = (x1+x2)/2 + X*cos(w) - Y*sin(w);
y = (y1+y2)/2 + X*sin(w) + Y*cos(w);
hold on, plot(x,y,'-k')
grid on