MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / angle

Method angle

linear_algebra/src/lib.py:175–193  ·  view source on GitHub ↗

find angle between two Vector (self, Vector) >>> Vector([3, 4, -1]).angle(Vector([2, -1, 1])) 1.4906464636572374 >>> Vector([3, 4, -1]).angle(Vector([2, -1, 1]), deg = True) 85.40775111366095 >>> Vector([3, 4, -1]).angle(Vector([2, -1])) Trac

(self, other: Vector, deg: bool = False)

Source from the content-addressed store, hash-verified

173 return math.sqrt(sum(squares))
174
175 def angle(self, other: Vector, deg: bool = False) -> float:
176 """
177 find angle between two Vector (self, Vector)
178
179 >>> Vector([3, 4, -1]).angle(Vector([2, -1, 1]))
180 1.4906464636572374
181 >>> Vector([3, 4, -1]).angle(Vector([2, -1, 1]), deg = True)
182 85.40775111366095
183 >>> Vector([3, 4, -1]).angle(Vector([2, -1]))
184 Traceback (most recent call last):
185 ...
186 Exception: invalid operand!
187 """
188 num = self * other
189 den = self.euclidean_length() * other.euclidean_length()
190 if deg:
191 return math.degrees(math.acos(num / den))
192 else:
193 return math.acos(num / den)
194
195
196def zero_vector(dimension: int) -> Vector:

Callers 1

show_phase_responseFunction · 0.80

Calls 1

euclidean_lengthMethod · 0.95

Tested by

no test coverage detected