From b580a27b271da942fb07c117da803d4be8f296f4 Mon Sep 17 00:00:00 2001 From: snowykami Date: Sat, 7 Sep 2024 00:44:06 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20vector:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=8A=95=E5=BD=B1=E5=90=91=E9=87=8F=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mbcp/mp_math/vector.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mbcp/mp_math/vector.py b/mbcp/mp_math/vector.py index d2d020d..920ce91 100644 --- a/mbcp/mp_math/vector.py +++ b/mbcp/mp_math/vector.py @@ -104,6 +104,20 @@ class Vector3: 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': """