how to detect horizontal or vertical lines code on OCTAVE

I created a program that would help a user find the equation of a line while they input values for two points. now i need to figure out how to write the program so it can determine what kind of line will be formed (horizontal or vertical). this is a preview of what my current program lookes like;
x1 = input ('enter value of x1: ')
x2 = input ('enter value of x2: ')
y1 = input ('enter value of y1: ')
y2 = input ('enter value of y2: ')
%find the slope of the line
m = (y2-y1) / (x2-x1);
%find the equation of the line
b = y1-m*x1;
fprintf('Your two points (%d,%d) and (%d,%d) form a line\n', x1,x2,y1,y2);
fprintf('the equation of your line is: y = %.3fx + %.3 f\n',m,b);

댓글 수: 1

The definition of a horizontal line is when the slope (m) = 0. The limit x2 ->x1 of (y2 - y1)/x2-x1 is a vertical line.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 3월 31일
if y1 == y2
% Horizontal line.
elseif x1 == x2
% Vertical line.
else
% Slanted line.
end

카테고리

도움말 센터File Exchange에서 Installing Products에 대해 자세히 알아보기

질문:

2020년 3월 31일

답변:

2020년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by