Line against line, plane and polygon — Shape4D 0.08 documentation

# Line against line, plane and polygon

## Point vs line

To check if a point is on a line/segement.

1. PointInLine(P0,P,L)

It serves to check if P0 falls in the line (P,L).

    >>> P0 = np.array([0.5,0.5,0.5])
    >>> P = np.array([0,0,0])
    >>> L = np.array([1.1,1.1,1.1])               # slope
    >>> ret = PointInLine(P0,P,L)

Here, ret == True.

2. PointInSegment(P0,P1,P2)

It serves to check if P0 falls in the segment (P1,P2).

    >>> P0 = np.array([0.5,0.5,0.5])
    >>> P1 = np.array([0,0,0])
    >>> P2 = np.array([0.4,0.4,0.4])
    >>> ret = PointInLine(P0,P1,P2)

Here, ret == False.

## Point vs plane

The point might be single or multiple.）

3. PointInPolygon(P0, polygon)

It serves to check if P0 falls in the polygon.

    >>> Point =  np.array([0.5,0.5,0.5])
    >>> vertices = [(0,0,0),(1,0,0),(1,1,1),(0,1,1)]
    >>> polygon = np.array(vertices)
    >>> ret = PointInPolygon(Point, polygon)

Here, ret == True.

4. PointsInPolygon2D(P0s, polygon)

It serves to check if multiple points P0s fall in the 2D polygon.

    >>> Points = np.array([(0,0),(0.5,0),(1,0),(1.5,0),(2,0)])
    >>> polygon = np.arraynp.array([(1,-1),(1,3),(2,1),(1.75,0)])
    >>> ret = PointsInPolygon2D(Points, polygon)

Here, ret == array([False, False, True, True, False]).
For the case of a matrix of points, it returns a matrix of the same sizes holding boolean values.

    >>> Points = np.array([[(0,0),(0.5,0)],[(1,0),(1.5,0)],[(2,0),(2.5,0]])
    >>> polygon = np.arraynp.array([(1,-1),(1,3),(2,1),(1.75,0)])
    >>> ret = PointsInPolygon2D(Points, polygon)

Here, ret == array([[False, False], [True, True], [False,False]])

5. PointsInPolygon(P0s, polygon)

It serves to check if multiple points P0s fall in the 3D polygon.

    >>> Points = np.array([(0,0,0),(0.5,0,0),(1,0,0),(1.5,0,0),(2,0,0)])
    >>> polygon = np.arraynp.array([(1,-1,0),(1,3,0),(2,1,0),(1.75,0,0)])
    >>> ret = PointsInPolygon(Points, polygon)

Here, ret == array([False, False, True, True, False])

6. Flow chart for their algorithm