how to detect horizontal or vertical lines code on OCTAVE
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
matquest
2020-3-31
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
2020-3-31
if y1 == y2
% Horizontal line.
elseif x1 == x2
% Vertical line.
else
% Slanted line.
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Octave 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!