MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_zero_vector

Function is_zero_vector

maths/points_are_collinear_3d.py:77–93  ·  view source on GitHub ↗

Check if vector is equal to (0, 0, 0) or not. Since the algorithm is very accurate, we will never get a zero vector, so we need to round the vector axis, because we want a result that is either True or False. In other applications, we can return a float that represents the coll

(vector: Vector3d, accuracy: int)

Source from the content-addressed store, hash-verified

75
76
77def is_zero_vector(vector: Vector3d, accuracy: int) -> bool:
78 """
79 Check if vector is equal to (0, 0, 0) or not.
80
81 Since the algorithm is very accurate, we will never get a zero vector,
82 so we need to round the vector axis,
83 because we want a result that is either True or False.
84 In other applications, we can return a float that represents the collinearity ratio.
85
86 >>> is_zero_vector((0, 0, 0), accuracy=10)
87 True
88 >>> is_zero_vector((15, 74, 32), accuracy=10)
89 False
90 >>> is_zero_vector((-15, -74, -32), accuracy=10)
91 False
92 """
93 return tuple(round(x, accuracy) for x in vector) == (0, 0, 0)
94
95
96def are_collinear(a: Point3d, b: Point3d, c: Point3d, accuracy: int = 10) -> bool:

Callers 1

are_collinearFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected