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

后端 未结 6 654
隐瞒了意图╮
隐瞒了意图╮ 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:08

    To all those poor souls looking for a concrete example using vectors... here I build upon Gareth's answer.

    You have a vector from p to r (from 0,0 to 50,-50) and another point, q, which is at (50, 0). The right-angle intersection of q and the vector from p to r is { x: 25. y: -25 } and is derived with the following code.

    const p = [0, 0];
    const r = [50, -50];
    const q = [50, 0];
    const l = math.add(p, r);
    const m = math.dot(math.subtract(q, p), r) / math.dot(r, r);
    
    console.log('intersecting point',  math.multiply(l, m));

提交回复
热议问题