如何找到用于绘制给定两点的垂直线的点 [英] How to Find points for draw a Perpendicular line of given two points
本文介绍了如何找到用于绘制给定两点的垂直线的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个点(x1,y1)和(x2,y2),这是一条直线。现在我想通过与主线垂直的终点绘制两条线。
附加图片你可以看到我需要的东西。
Pointsfind.png - Google云端硬盘 [ ^ ]
如果有人知道该怎么办请帮助
先谢谢。
解决方案
垂直于(a,b)的向量是(-b,a)。这个可以通过标量积(也称为点积)的帮助来证明。
在你的情况下(a,b)=(x2,y2) - (x1,y1)。现在,使用这个(-b,a)向量,可以很容易地分别计算出四个(?,?)向量的代表(抱歉,我找不到正确的英文单词)。
因为(?,?)未指定更精确,我个人会使用上面提到的计算。另一种方法是使用单位矢量(-b,a),但是在图形的情况下,必须注意,不要失去精确度。
对不起对于我糟糕的英语,我希望它有所帮助。
它是简单的向量计算。即使其他人认为它更多。
感谢所有人的回复。
i使用以下代码做同样的事情
dx = x1-x2
dy = y1-y2
dist = sqrt(dx * dx + dy * dy)
dx / = dist
dy / = dist
x3 = x1 +(N / 2)* dy //其中N是行的长度抽奖。
y3 = y1 - (N / 2)* dx
x4 = x1 - (N / 2)* dy
y4 = y1 +(N / 2)* dx
和我发现x5,y5和x6 y6的方式相同。
Hi,
I have two point (x1,y1) and (x2,y2) which makes a straight line. Now I want to draw two lines through the terminal points which will be perpendicular to the main line.
in attached image you can see what i need.
Pointsfind.png - Google Drive[^]
if anyone know how to do please help
Thanks in Advance.
解决方案
A vector perpendicular to (a,b) is (-b,a). This one can prove by the help of scalar product (also named dot product).
In your case (a,b)= (x2,y2)-(x1,y1). Now, with this (-b,a) vector one can easily calculate the four (?,?) vectors respectively their "representants" (sorry I do not find the right word in English).
Because (?,?) is not specified more precise, I personally would use the above mentioned calculations. Another way is to use "unit vector" for (-b,a), but in case of graphics one has to pay attention, not to lose precisions.
Sorry for my bad English, I hope it helps.
It is simple vector computation. Even if others here think it is more.
Thanks to all for your reply.
i did the same by using the following code
dx = x1-x2
dy = y1-y2
dist = sqrt(dx*dx + dy*dy)
dx /= dist
dy /= dist
x3 = x1 + (N/2)*dy // where N is the length of line to be draw.
y3 = y1 - (N/2)*dx
x4 = x1 - (N/2)*dy
y4 = y1 + (N/2)*dx
and same way i found the x5,y5 and x6 y6.
这篇关于如何找到用于绘制给定两点的垂直线的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文