Skip to content

Commit

Permalink
✨ vector: 添加投影向量方法
Browse files Browse the repository at this point in the history
  • Loading branch information
snowykami committed Sep 6, 2024
1 parent 74daf9e commit b580a27
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mbcp/mp_math/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ def normalize(self):
self.y /= length
self.z /= length

def project(self, other: 'Vector3') -> 'Vector3':
r"""
返回自向量在另一个向量上的投影向量。
:::tip
投影向量计算公式:
$$ \text{proj}_v(u) = \frac{u \cdot v}{|v|^2} \cdot v $$
:::
Args:
other ([`Vector3`](#class-vector3)): 另一个向量
Returns:
[`Vector3`](#class-vector3): 投影向量
"""
return (self @ other / other.length) * other.unit

@property
def np_array(self) -> 'np.ndarray':
"""
Expand Down

0 comments on commit b580a27

Please sign in to comment.