给定一个点,找到与直角相交的直线 [英] Find a line intersecting a known line at right angle, given a point

查看:113
本文介绍了给定一个点,找到与直角相交的直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是基本的图形几何图形和/或触发器,我觉得这很愚蠢,但我不记得这是怎么回事。所以:


  1. 我有一条由两点(x1,y1)和(x2,y2)定义的线。

  2. 我有第三点(xp,yp),它位于别处。

我想计算点x',y'),它们位于#1中的某条线上,因此,当与#2中的点相连接时,会创建一条垂直于第一条线的新线。



谢谢。

解决方案

通过考虑第一个泛型点(x,y) code>(x1,y1)(x2,y2)

  x = x1 + t *(x2  -  x1)
y = y1 + t *(y2 - y1)

并计算从这个点到(code>(xp,yp) code $
$ b $ pre $ E =(x - xp)** 2 +(y - yp)** 2

代替 x 和<$ c的定义$ c> y 给出

  E =(x1 + t *(x2  -  x1) -  xp )** 2 + 
(y1 + t *(y2 - y1) - yp)** 2

然后找到这个距离的最小值变化 t 我们派生 E 相对于<$ c $ (x1 + t *(x2-x1)),其中c> t

  dE / dt = 2 * -  xp)*(x2  -  x1)+ 
2 *(y1 + t *(y2 - y1) - yp)*(y2 - y1)



< (x1 - xp)*(x2 - x1)+(x1 - xp)*(x2 - x1)+ (y1-yp)*(y2-y1)+
t *((x2-x1)** 2 +(y1-y2)** 2))
pre>

寻找这个导数是零的时候,我们得到一个明确的方程: t

  t =((xp  -  x1)*(x2  -  x1)+(yp  -  y1)*(y2  -  y1))/ 
(x2 - x1)** 2 +(y2 - y1)** 2)

点可以在(x,y)

的定义中使用 t 的值来计算。 b
$ b

使用向量表示法,这与Gareth提出的公式完全相同......

  t =< p  -  p1,p2  -  p1> /< p2-p1,p2-p1> 

其中< a,b> 表示点积操作 ax * bx + ay * by



还要注意,在n维空间。

This is basic graphics geometry and/or trig, and I feel dumb for asking it, but I can't remember how this goes. So:

  1. I have a line defined by two points (x1, y1) and (x2, y2).
  2. I have a third point (xp, yp) which lies somewhere else.

I want to compute the point (x', y') that lies somewhere along the line in #1, such that, when joined with the point from #2, creates a new perpendicular line to the first line.

Thanks.

解决方案

You can find that point by considering first a generic point (x, y) along the line from (x1, y1) to (x2, y2):

x = x1 + t*(x2 - x1)
y = y1 + t*(y2 - y1)

and the computing the (squared) distance from this point from (xp, yp)

E = (x - xp)**2 + (y - yp)**2

that substituting the definition of x and y gives

E = (x1 + t*(x2 - x1) - xp)**2 +
    (y1 + t*(y2 - y1) - yp)**2

then to find the minimum of this distance varying t we derive E with respect to t

dE/dt = 2*(x1 + t*(x2 - x1) - xp)*(x2 - x1) +
        2*(y1 + t*(y2 - y1) - yp)*(y2 - y1)

that after some computation gives

dE/dt = 2*((x1 - xp)*(x2 - x1) + (y1 - yp)*(y2 - y1) +
           t*((x2 - x1)**2 + (y1 - y2)**2))

looking for when this derivative is zero we get an explicit equation for t

t = ((xp - x1)*(x2 - x1) + (yp - y1)*(y2 - y1)) /
    ((x2 - x1)**2 + (y2 - y1)**2)

so the final point can be computed using that value for t in the definition of (x, y).

Using vector notation this is exactly the same formula suggested by Gareth...

t = <p - p1, p2 - p1> / <p2 - p1, p2 - p1>

where the notation <a, b> represents the dot product operation ax*bx + ay*by.

Note also that the very same formula works in an n-dimensional space.

这篇关于给定一个点,找到与直角相交的直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆