mirror of
https://github.com/3b1b/manim.git
synced 2025-08-03 04:04:36 +08:00
Allow cross to take an 'out' array
This commit is contained in:
@ -22,7 +22,11 @@ if TYPE_CHECKING:
|
||||
from manimlib.typing import Vect2, Vect3, Vect4, VectN, Matrix3x3, Vect3Array, Vect2Array
|
||||
|
||||
|
||||
def cross(v1: Vect3 | List[float], v2: Vect3 | List[float]) -> Vect3 | Vect3Array:
|
||||
def cross(
|
||||
v1: Vect3 | List[float],
|
||||
v2: Vect3 | List[float],
|
||||
out: np.ndarray | None = None
|
||||
) -> Vect3 | Vect3Array:
|
||||
is2d = isinstance(v1, np.ndarray) and len(v1.shape) == 2
|
||||
if is2d:
|
||||
x1, y1, z1 = v1[:, 0], v1[:, 1], v1[:, 2]
|
||||
@ -30,12 +34,14 @@ def cross(v1: Vect3 | List[float], v2: Vect3 | List[float]) -> Vect3 | Vect3Arra
|
||||
else:
|
||||
x1, y1, z1 = v1
|
||||
x2, y2, z2 = v2
|
||||
result = np.array([
|
||||
if out is None:
|
||||
out = np.empty(np.shape(v1))
|
||||
out.T[:] = [
|
||||
y1 * z2 - z1 * y2,
|
||||
z1 * x2 - x1 * z2,
|
||||
x1 * y2 - y1 * x2,
|
||||
])
|
||||
return result.T if is2d else result
|
||||
]
|
||||
return out
|
||||
|
||||
|
||||
def get_norm(vect: VectN | List[float]) -> float:
|
||||
|
Reference in New Issue
Block a user