how to detect horizontal or vertical lines code on OCTAVE
Ältere Kommentare anzeigen
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 Kommentar
matquest
am 31 Mär. 2020
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.
Antworten (1)
Image Analyst
am 31 Mär. 2020
if y1 == y2
% Horizontal line.
elseif x1 == x2
% Vertical line.
else
% Slanted line.
end
Kategorien
Mehr zu Octave finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!