@@ -286,9 +286,17 @@ def normalized_and_length(self) -> Tuple["Vec2d", float]:
286
286
return Vec2d (0 , 0 ), 0
287
287
288
288
def perpendicular (self ) -> "Vec2d" :
289
+ """Get a vertical vector rotated 90 degrees counterclockwise from the original vector.
290
+
291
+ :return: A new vector perpendicular to this vector.
292
+ """
289
293
return Vec2d (- self .y , self .x )
290
294
291
295
def perpendicular_normal (self ) -> "Vec2d" :
296
+ """Get a vertical normalized vector rotated 90 degrees counterclockwise from the original vector.
297
+
298
+ :return: A new normalized vector perpendicular to this vector.
299
+ """
292
300
length = self .length
293
301
if length != 0 :
294
302
return Vec2d (- self .y / length , self .x / length )
@@ -314,15 +322,18 @@ def get_distance(self, other: Tuple[float, float]) -> float:
314
322
def get_dist_sqrd (self , other : Tuple [float , float ]) -> float :
315
323
"""The squared distance between the vector and other vector
316
324
It is more efficent to use this method than to call get_distance()
317
- first and then do a sqrt () on the result.
325
+ first and then do a square () on the result.
318
326
319
327
:return: The squared distance
320
328
"""
321
329
assert len (other ) == 2
322
330
return (self .x - other [0 ]) ** 2 + (self .y - other [1 ]) ** 2
323
331
324
332
def projection (self , other : Tuple [float , float ]) -> "Vec2d" :
325
- """Project this vector on top of other vector"""
333
+ """Project this vector on top of other vector
334
+
335
+ :return: The projected vector
336
+ """
326
337
assert len (other ) == 2
327
338
other_length_sqrd = other [0 ] * other [0 ] + other [1 ] * other [1 ]
328
339
if other_length_sqrd == 0.0 :
@@ -341,6 +352,10 @@ def cross(self, other: Tuple[float, float]) -> float:
341
352
return self .x * other [1 ] - self .y * other [0 ]
342
353
343
354
def interpolate_to (self , other : Tuple [float , float ], range : float ) -> "Vec2d" :
355
+ """Vector interpolation between the current vector and another vector.
356
+
357
+ :return: The interpolated vector
358
+ """
344
359
assert len (other ) == 2
345
360
return Vec2d (
346
361
self .x + (other [0 ] - self .x ) * range , self .y + (other [1 ] - self .y ) * range
@@ -349,6 +364,10 @@ def interpolate_to(self, other: Tuple[float, float], range: float) -> "Vec2d":
349
364
def convert_to_basis (
350
365
self , x_vector : Tuple [float , float ], y_vector : Tuple [float , float ]
351
366
) -> "Vec2d" :
367
+ """Converts the vector to a new basis defined by the given x and y vectors.
368
+
369
+ :return: Vec2d: The vector converted to the new basis.
370
+ """
352
371
assert len (x_vector ) == 2
353
372
assert len (y_vector ) == 2
354
373
x = self .dot (x_vector ) / Vec2d (* x_vector ).get_length_sqrd ()
0 commit comments