clc
clear
x1 = input("Give me the x value of sun (focus 1): ");
y1 = input("Give me the Y value of the sun(focus1): ");
x2 = input("Give me the x value of focus 2: ");
y2 = input("Give me the Y value of focus 2: ");
hold on
hold on
drawellipse(x1,x2,y1,y2)
hold off
Sun(x1,y1,'yellow')
function drawellipse(x1,x2,y1,y2)
Rp = sqrt ((x1)^2 + (y1)^2);
Ra = sqrt((x2)^2 + (y2)^2);
eccentricity = (Ra-Rp)/(Ra+Rp);
numPoints = 500;
a = 0.5 * (Rp + Ra);
c = eccentricity*a;
b = sqrt(a^2 - c^2);
t = linspace(0, 2 * pi, numPoints);
X = a * cos(t);
Y = b * sin(t);
angles = atan2(y2 - y1, x2 - x1);
x = (x1 + x2) / 2 + X * cos(angles) - Y * sin(angles);
y = (y1 + y2) / 2 + X * sin(angles) + Y * cos(angles);
subplot(1, 1, 1);
plot(x,y,'b-', 'LineWidth', 1);
grid on;
axis equal
end
function Sun(s,v,color)
hold on
color=color+".";
plot(s,v,color,'MarkerSize',75);
hold off
end