Syntax: Select all

def PointIsInside(pt, cpt1, cpt2):

if (

((pt[0] >= cpt1[0]) | (pt[0] >= cpt2[0])) & \

((pt[0] <= cpt2[0]) | (pt[0] <= cpt1[0])) & \

((pt[1] >= cpt1[1]) | (pt[1] >= cpt2[1])) & \

((pt[1] <= cpt2[1]) | (pt[1] <= cpt1[1])) & \

((pt[2] >= cpt1[2]) | (pt[2] >= cpt2[2])) & \

((pt[2] <= cpt2[2]) | (pt[2] <= cpt1[2])) \

):

return True

else:

return False

Syntax: Select all

# pt - Point (x, y, z)

# cpt1 - Start Cube Diagonal (x, y, z)

# cpt2 - End Cube Diagonal (x, y, z)

cube = [

(-2, -2, -2), # Start

(2, 2, 2), # End

]

point = (1, 2, -2)

print(f'{PointIsInside(point, cube[0], cube[1]) = }') # True

point = (1, 2, -3)

print(f'{PointIsInside(point, cube[0], cube[1]) = }') # False

I think that this algorithm is useful to many when working with graphs and calculations :p