Functions about point inside shapes

Beside shape functions, we also define functions about their relationship, such as containing point in line or polygon.

Accordingly, the VisualShapes also refer to them.

Point vs line

To check if a point is on a line.

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
PointInLine(P0,P,L)
>>>  True
_images/pointXline1.png

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])
PointInLine(P0,P1,P2)
>>>  False
_images/pointXline2.png

Point(s) in a 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)
PointInPolygon(Point, polygon)
>>>  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)
>>>  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)
>>>  array([[False, False], [True,  True], [False,False]])
_images/pointsandpolygon.png

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)
>>>  array([False, False,  True,  True, False])

6. Flow chart for their algorithm

_images/PointEdge.png _images/PointInPolygon.png