Find a line intersecting a known line at right angles, given the point

This is basic graphical geometry and / or trigger, and I feel dumb to ask about it, but I can't remember how this happens. So:

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

I want to calculate the point (x ', y') that lies somewhere along the line in # 1, so when connected to the point from # 2, a new perpendicular line is created to the first line. enter image description here

Thank.

+5
source share
4 answers

, (x, y) (x1, y1) (x2, y2):

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

() (xp, yp)

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

x y

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

, t, E t

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

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

, , t

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

, t (x, y).

, , ...

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

<a, b> ax*bx + ay*by.

, n- .

+5

, , , . . , p p + r, - q.

, , ( s), s= p + 位 r 位.

q s r.

(q - ( p + 位 r)) 路 r= 0

- dot product. :

(q - p) r= 位 ( r r > )

:

位 = (q - p) r/ r - r >

, , r - r= 0, .

+5

:

y=ax+b
where a=(x1-x2)/(y2-y1)
      b=yp-(x1-x2)*xp/(y2-y1)

:

1) slope for the original line:   (y2-y1)/(x2-x1)

2) slope for the answer: -1/((y2-y1)/(x2-x1)) = (x1-x2)/(y2-y1)

3) Plug this into (xp,yp) we can have the result line.

( ... ).

+1

, (x1, y1) (x2, y2). , -.

y-, , , y x=0 x1.

b + (x1 - x0) * m = y1
b + (x1 -  0) * m = y1
b + (x1 * m)      = y1
b = y1 - x1 * m

(xp, yp) . x y, x, y.

m = slope_from_1_to_2  = (y2 - y1) / (x2 - x1)
n = slopePerpendicular = (-1) / m

b = intercept_for_1_to_2 = y1 - x1 * m
c = intercept_for_p      = yp - xp * n

, y = mx + b

1 2:

y(x) = mx + b

p:

y(x) = nx + c

y x '

mx' + b = nx' + c
(m-n)x' = c - b
     x' = (c - b) / (m - n)

And thus use any formula to calculate y '

y' = mx' + b

0
source

All Articles