Find a line intersecting a known line at right angle, given a point

后端 未结 6 641
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 15:53

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
6条回答
  •  [愿得一人]
    2020-12-29 16:13

    Based on this article

    let x1, x2, y1, y2, slope, xp, yp, m, x, y
    x1 = 0
    y1 = 0 
    x2 = 50
    y2 = -50
    xp = 50
    yp = 0
    
    slope = (y1 - y2) / (x1 - x2)
    m = -1 / slope
    x = (m * xp - yp - slope * x1 + y1) / (m - slope)
    y = m * x - m * xp + yp
    
    console.log('x: ', x, ', y: ', y )

提交回复
热议问题