Intersection of lines and lines

How to determine if a line (direction d and -d from point p) intersects a line segment (between points p1 and p2) in 2D? If they do, how can I get their intersection point.

There are many examples of how to determine if two line segments intersect, but this should be an even simpler case.

I found this, but I don’t understand what the side statement is: http://www.loria.fr/~lazard//ARC-Visi3D/Pant-project/files/Line_Segment_Line.html

+5
source share
3 answers

If this is a 2D problem (the line and the segment are in the same plane and they are given by two-dimensional coordinates), this is easy.

, d ( ), n.

n. (p1-p) n. (p2-p). , . , . , p, p1-p p2-p.

+5

, ( ) .

1: (x, y) (t) = p + t * d; 2: (x, y) (t) = p1 + k * (p2 - p1)

: p + t * d = p1 + k * (p2 - p1) - ( x y)

k t . 0 < k < 1 (p1, p2)

k t, (x, y) (t) = p + t * d (x, y) (t) = p1 + k * (p2 - p1)

+3

let p(x,y) a D = a.x+b b = y - a.x

let p1(x1,y1) p2(x2,y2) , D' = a'.x+b' x [x1;x2] a' = (y2-y1)/(x2-x1) b' = y2 - a'.x2 = y1 - a'.x1

, [x1;x2] x, D = D' , X = (b'-b)/(a-a') [x1;x2] Y = a.X+b = a'.X+b p(x,y)

:

let p(255,255), a = 1 = > b = 0

let p1(60,179) p2(168,54)

= > a' = -125/108

= > b' = 24596/99

= > X = (24596/99 - 0)/(1+125/108) = 115,1587983

= > Y = (24596/99 - 0)/(1+125/108) = 115,1587983

x 60 168, p(x,y)

0

All Articles