# how to extend a straight line passing through two points until it meets the y axis of the Cartesian plane

21 ビュー (過去 30 日間)
ELISABETTA BILLOTTA 2022 年 10 月 8 日
コメント済み: Star Strider 2022 年 10 月 8 日
I have a graph of this type and I have created the straight line dashed in red that passes through the point of coordinates 0-0 and the point marked with the red dot. now I should extend this line until it meets the y axis, always maintaining the same inclination as the straight line. this is because then I need to identify the coordinates of the points of intersection between the straight line and the other curved lines with values 10 - 1 and 0.01.
how can I do? can anyone help me?
##### 2 件のコメント表示非表示 1 件の古いコメント
Ghazwan 2022 年 10 月 8 日
It looks like you are doing this manually. It is way better to make a code for this line. With the code, we can make an equation for and find the intersection points.

サインインしてコメントする。

### 採用された回答

Star Strider 2022 年 10 月 8 日
It already meets the y-axis at the origin (0,0).
If you want to extend it to , that is straightforward —
slope = -53634 / -234311;
intercept = 0;
yfit = -5E+5*slope + intercept
yfit = -1.1445e+05
figure
plot([-5E+5 0], [yfit 0], '--r')
grid
axis([-5E+5 1E+5 -3.1E+5 2.5E+5])
I do not have your contourf plot, so I cannot plot it with that as well.
.
##### 2 件のコメント表示非表示 1 件の古いコメント
Star Strider 2022 年 10 月 8 日
As always, my pleasure!

サインインしてコメントする。

### その他の回答 (1 件)

Image Analyst 2022 年 10 月 8 日
Is this like what you want?
x = [1, 5];
y = [2, 7];
plot(x, y, 'b.-', 'LineWidth', 2, 'MarkerSize', 30)
grid on;
xlim([0, 6])
ylim([0, 8])
% Fit a line through x and y
coefficients = polyfit(x, y, 1);
% Get the value on the y axis, which is when x=0.
x0 = 0;
y0 = polyval(coefficients, x0)
y0 = 0.7500
% Plot a line from the y axis to the point [x1, y1]
hold on;
plot([x0, x(1)], [y0, y(1)], 'r-', 'LineWidth', 2)

サインインしてコメントする。

### カテゴリ

Find more on Surface and Mesh Plots in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by