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

前端 未结 4 1119
野性不改
野性不改 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:49

    If you want to avoid a sqrt, do the following:

    in: line_length, cap_length, rotation, position of line centre
    
    define points:
      tl (-line_length/2, cap_length)
      tr (line_length/2, cap_length)
      bl (-line_length/2, -cap_length)
      br (line_length/2, -cap_length)
    
    rotate the four points by 'rotation'
    offset four points by 'position'
    
    drawline (midpoint tl,bl to midpoint tr,br)
    drawline (tl to bl)
    drawline (tr to br)
    

提交回复
热议问题