how to find a line perpendicular to another line?
71 次查看(过去 30 天)
显示 更早的评论
X = [126.3798 126.3818]
Y = [37.5517 37.5495]
I want to find a perpendicular line to this XY line at second point like this image.
Thanks.
0 个评论
采纳的回答
Jan
2022-10-21
编辑:Jan
2022-10-21
% 2 points to define a line:
X = [126.3798 126.3818];
Y = [37.5517 37.5495];
% Its direction:
v = [diff(X); diff(Y)];
n = v / vecnorm(v); % Normalized
% Orthogonal means dot(n,m) = 0 or:
% n(1) * m(1) + n(2) * m(2) = 0
% There are 2 solutions:
m_a = [n(2), -n(1)];
m_b = [-n(2), n(1)]; % Other orientation
Now choose one of these m's as direction of the line. Use any point to start from as initial point.
0 个评论
更多回答(2 个)
Matt J
2022-10-21
编辑:Matt J
2022-10-21
The equation is,
dot(X-Y,Z-Z0)=0
where Z0 is a known point on the desired line.
X = [126.3798 126.3818];
Y = [37.5517 37.5495];
Z0=(X+Y)/2;
line([X(1),Y(1)],[X(2),Y(2)],LineStyle='--'); hold on %original line
fimplicit(@(Z1,Z2) (X-Y)*[Z1-Z0(1);Z2-Z0(2)]); hold off %perpendicular bisector
0 个评论
Image Analyst
2022-10-21
Try this well commented demo:
% Define original line.
X = [126.3798 126.3818];
Y = [37.5517 37.5495];
% Plot it.
plot(X, Y, 'b.-', 'LineWidth', 2, 'MarkerSize', 30)
grid on;
% Determine slope of original line.
originalSlope = diff(Y)/diff(X)
% The slope of the perpendicular line is -1 over the original slope.
newSlope = -1/originalSlope
% To draw second perpendicular line use point slope formula
% (y-y2) = slope * (x-x2)
% Define range of x values for the new perpendicular line.
x = linspace(X(2), 126.385, 10);
% Get y values over that new x range.
yPerp = newSlope * (x - X(2)) + Y(2)
% Plot perpendicular line
hold on;
plot(x, yPerp, 'r.-', 'LineWidth', 2, 'MarkerSize', 30)
axis equal % Make it so it's scaled the same in x and y
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!