Line against line, plane and polygon

Line vs line

1. P = LineXLine(P1,L1,P2,L2)

Provided with points and slopes, the function returns the intersecting point of two lines, in the form of numpy.array. Generally, it return one of the following messages :

1.Intersection point Array (P)

2.None for two parallel/different lines

3.'Line' for the two are one line

>>> P1, L1 = (0,0,0),(1,1,1)
>>> P2, L2 =(0,1,0),(1,-1,1)
>>> P = LineXLine(P1,L1,P2,L2)

output is [0.5 0.5 0.5]

Line vs plane

2. P = LineXPlane(P0,L,R0,n)

A line is given by a point and a slope, while a plane is given by a point and its normal vector. The function return one of the following values,

1.P1, the intersection point

2.None, the line is over the plane

3.'Line', the line is on the plane.

>>> P0,L =Array([0,0,0]),Array([2,1,0])
>>> R0,n = Array([0,0,0]),Array([0,-1,1])
>>> P=LineXPlane(P0,L,R0,n)

Output is array([0. , 0., 0.])

Line vs polygon

3. P = LineXPolygon(P0,L,Polygon):

A line is given by a point and a slope, while a polygon is given by an array of vertices, in the counter-clockwise order for outer loop and clockwise order for inner loop.It returns one of the following output pairs,

1.P1: the intersection point

2.None,None : no intersection

3.'Line', one edge of polygon is part of the line

>>> P0 = Array([-0.5,0,0.5])
>>> L  = Array([1,1,0])
>>> vertices1 = [(0,0,0),(1,0,0),(1,1,1),(0,1,1)]
>>> polygon1 = np.array(vertices1)
>>> P = LineXPolygon(P0,L,vertices)

Outpout is array([0. , 0.5, 0.5])