How do you find a point at a given perpendicular distance from a line?

前端 未结 4 1125
野性不改
野性不改 2020-11-29 19:27

I have a line that I draw in a window and I let the user drag it around. So, my line is defined by two points: (x1,y1) and (x2,y2). But now I would like to draw \"caps\" at

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 19:47

    You just evaluate the orthogonal versor and multiply by N/2

    vx = x2-x1
    vy = y2-y1
    len = sqrt( vx*vx + vy*vy )
    ux = -vy/len
    uy = vx/len
    
    x3 = x1 + N/2 * ux
    Y3 = y1 + N/2 * uy
    
    x4 = x1 - N/2 * ux
    Y4 = y1 - N/2 * uy
    

提交回复
热议问题