当长度不相等时如何找到三角形的第三个顶点
How to find the third vertices of a triangle when lengths are unequal
我有一个三角形的两个顶点,它们的长度不相等。如何找到第三个顶点?
function [vertex_1a, vertex_1b] = third_vertex(x2, y2, x3, y3, d1, d3)
d2 = sqrt((x3 - x2)^2 + (y3 - y2)^2); % distance between vertex 2 and 3
% Orthogonal projection of side 12 onto side 23, calculated unsing
% the Law of cosines:
k = (d2^2 + d1^2 - d3^2) / (2*d2);
% height from vertex 1 to side 23 calculated by Pythagoras' theorem:
h = sqrt(d1^2 - k^2);
% calculating the output: the coordinates of vertex 1, there are two solutions:
vertex_1a(1) = x2 + (k/d2)*(x3 - x2) - (h/d2)*(y3 - y2);
vertex_1a(2) = y2 + (k/d2)*(y3 - y2) + (h/d2)*(x3 - x2);
vertex_1b(1) = x2 + (k/d2)*(x3 - x2) + (h/d2)*(y3 - y2);
vertex_1b(2) = y2 + (k/d2)*(y3 - y2) - (h/d2)*(x3 - x2);
end
平移所有点,使 P2 成为原点。
那你解决
x² + y² = d2²
(x - x3)² + (y - y3)² = d3²
(注意 d1
的重新编号)。
两个方程相减,
(2x - x3).x3 + (2y - y3).y3 = d2² - d3²
这是一个线性方程,形式为
a.x + b.y + c = 0
和参数形式
x = x0 + b.t
y = y0 - a.t
其中 (x0, y0)
是任意解,例如 (- ac / (a² + b²), - bc / (a² + b²))
.
现在求解t
中的二次方程
(x0 + b.t)² + (y0 - a.t)² = d2²
其中给出了两个解决方案,并撤消了初始翻译。
我有一个三角形的两个顶点,它们的长度不相等。如何找到第三个顶点?
function [vertex_1a, vertex_1b] = third_vertex(x2, y2, x3, y3, d1, d3)
d2 = sqrt((x3 - x2)^2 + (y3 - y2)^2); % distance between vertex 2 and 3
% Orthogonal projection of side 12 onto side 23, calculated unsing
% the Law of cosines:
k = (d2^2 + d1^2 - d3^2) / (2*d2);
% height from vertex 1 to side 23 calculated by Pythagoras' theorem:
h = sqrt(d1^2 - k^2);
% calculating the output: the coordinates of vertex 1, there are two solutions:
vertex_1a(1) = x2 + (k/d2)*(x3 - x2) - (h/d2)*(y3 - y2);
vertex_1a(2) = y2 + (k/d2)*(y3 - y2) + (h/d2)*(x3 - x2);
vertex_1b(1) = x2 + (k/d2)*(x3 - x2) + (h/d2)*(y3 - y2);
vertex_1b(2) = y2 + (k/d2)*(y3 - y2) - (h/d2)*(x3 - x2);
end
平移所有点,使 P2 成为原点。
那你解决
x² + y² = d2²
(x - x3)² + (y - y3)² = d3²
(注意 d1
的重新编号)。
两个方程相减,
(2x - x3).x3 + (2y - y3).y3 = d2² - d3²
这是一个线性方程,形式为
a.x + b.y + c = 0
和参数形式
x = x0 + b.t
y = y0 - a.t
其中 (x0, y0)
是任意解,例如 (- ac / (a² + b²), - bc / (a² + b²))
.
现在求解t
(x0 + b.t)² + (y0 - a.t)² = d2²
其中给出了两个解决方案,并撤消了初始翻译。