本文介绍了查找海拔与基准相交的点(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅给出一个锐角三角形顶点的坐标,我如何有效而快速地找到某个特定顶点的高度与相反的底点相交的点的坐标?
Given only the coordinates of the vertices of an acute triangle, how can I efficiently and quickly find the coordinates of the point at which the altitude from a particular vertex meets the opposite base?
仅使用数学,numpy或scipy的解决方案将非常有用.
A solution using only math, numpy, or scipy would be incredibly helpful.
推荐答案需要的点是顶点(例如顶点C)在包含相反面(例如AB)的线上的正交投影.
Needed point is orthogonal projection of vertex point (say vertex C) onto the line containing opposite side (say AB).
要找到投影点,请获取AB和AC的向量
To find projection point, get vectors for AB and AC
AB = (B - A) //in coordinates ab.x = b.x-a.x, ab.y = b.y-a.y AC = (C - A)并使用AB和AC的标量积查找参数
and find parameter using scalar product of AB and AC
t =(AB * AC) / (AB * AB) t =((b.x-a.x)*(c.x-a.x) + (b.y-a.y)*(c.y-a.y)) / ((b.x-a.x)*(b.x-a.x) + (b.y-a.y)*(b.y-a.y))投影点坐标
P = A + AB * t p.x = a.x + (b.x-a.x) * t p.y = a.y + (b.y-a.y) * t仅此而已
def orthoProjection(ax, ay, bx, by, cx, cy): abx = bx - ax aby = by - ay acx = cx - ax acy = cy - ay t = (abx * acx + aby * acy) / (abx * abx + aby * aby) px = ax + t * abx py = ay + t * aby return px, py print(orthoProjection(0, 0, 4, 4, -1, 5)) >>(2.0, 2.0)更多推荐
查找海拔与基准相交的点(Python)
发布评论