开发者

Check whether a line-segment intersects the perpendicular line draw from a particular point?

As shown in this image:

Check whether a line-segment intersects the perpendicular line draw from a particular point?

I have a set of line seg开发者_开发技巧ments. I want to check which line-segments intersect with the perpendicular line drawn from a given point (x0,y0).

(E.g.: AB passes the check and BC does not.)

The only information I've got is two points of the line-segment, (x1,y1), (x2,y2), and the target point (x0,y0).

Is it possible to derive a simple formula using these three points?

Thanks in advance.

umanga


As background, if you need to, you can read up on dot product, its geometric interpretation, and in particular scalar projection.

Define the vectors v0=(x0,y0)-(x1,y1) and v2=(x2,y2)-(x1,y1).

Then the intersection point is

(x1,y1) + ((v0v2)/(v2v2))v2

The intersection point will be on the line segment if the scalar value (v0v2)/(v2v2) is between 0 and 1.


For a line AB and a point X, both angles, ABX and BAX must be acute (or right).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜