# plotting half an ellipse, a linear line and the interceptions between

6 views (last 30 days)
Yuval on 21 Jun 2024
Commented: Yuval on 22 Jun 2024
Hi all
i would like to plot an ellipse that will grow in a for loop.
i also have a linear line that doesnt change.
i would like to find the interceptions between the linear line and the ongrowing ellipses.
the code looks like that:
x1 = p0/OCR:0.1:x_int;
yeta=+3*x1-3*p;
t=0:0.01:pi;
plot(p0/2+p0/2*cos(t),p0/2*M*sin(t), 'k')
and then i change the p0 value with a for loop, giving me a bigger ellipse.
plot(p(i),q(i),'ko','MarkerFaceColor', 'k', 'MarkerSize', 4)
how do i shoe the interceptions, and not the p value? (attached pic, the 1st subplot)

Hassaan on 21 Jun 2024
% Parameters
p0 = 400; % Initial p0 value
M = 1.5; % Ratio for the ellipse equation
% Linear line equation
x1 = 400:0.1:600;
yeta = 3 * x1 - 1200;
% Plot the static linear line
figure;
subplot(2, 2, 1);
plot(x1, yeta, 'r', 'LineWidth', 1.5);
hold on;
% Initial plot for the first ellipse
t = 0:0.01:pi;
p_values = p0/2 + p0/2 * cos(t);
q_values = p0/2 * M * sin(t);
plot(p_values, q_values, 'k', 'LineWidth', 1.5);
hold on;
% Plot ellipse and calculate intersections in a loop
for k = 1:5
p0 = p0 + 10; % Increase p0 for the growing ellipse
p_values = p0/2 + p0/2 * cos(t);
q_values = p0/2 * M * sin(t);
% Plot the growing ellipse
plot(p_values, q_values, 'k', 'LineWidth', 1.5);
% Find intersections
for i = 1:length(x1)
% Intersection condition
idx = find(abs(p_values - x1(i)) < 1e-1 & abs(q_values - yeta(i)) < 1e-1);
if ~isempty(idx)
plot(p_values(idx), q_values(idx), 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 4);
end
end
end
% Set axis properties
axis equal;
xlim([350 650]);
ylim([0 250]);
xlabel('p [kPa]');
ylabel('q [kPa]');
title('Intersections of Ellipses and Linear Line');
grid on;
hold off;
Yuval on 21 Jun 2024
Edited: Yuval on 21 Jun 2024
Hassan thanks.
in your code, only the first line gets a markercolor, why? and how can we show on every ellipse?
is it possible to do so with an array? so the interceptions will help in other subplots as well?
Yuval on 22 Jun 2024
UPDATE
i used the code you suggested, im not recieving all interceptions, please advise

### Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

R2024a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!