Skip to content

Fix batched 2D vector rotation - #2501

Merged
3b1b merged 1 commit into
3b1b:masterfrom
QinXi-ai:agent/fix-rotate-vector-batched-2d
Aug 17, 2026
Merged

3b1b merged 1 commit into
3b1b:masterfrom
QinXi-ai:agent/fix-rotate-vector-batched-2d

Conversation

@QinXi-ai

Copy link
Copy Markdown
Contributor

Motivation

VectorField calls vectorized functions with an (N, 2) array of sample coordinates. Passing that array to rotate_vector, as in the curl example from #2336, currently attempts to multiply it by a 3x3 rotation matrix and raises a shape-mismatch ValueError.

The helper already accepts a single 2D vector in its public usage. Supporting the vectorized form lets the same helper work naturally with VectorField and restores the pattern used by existing Manim examples.

Closes #2336.

Proposed changes

  • Detect vectors whose final dimension is 2 and rotate them with a 2x2 planar rotation matrix.
  • Preserve the existing SciPy axis-angle path for individual and batched 3D vectors.
  • Add regression coverage for individual and batched 2D and 3D inputs.

Test

Code:

python -m pytest tests/test_space_ops.py -q
python -m compileall -q manimlib tests/test_space_ops.py

The issue reproduction was also exercised through the real VectorField path:

axes = NumberPlane()
curl_func = lambda p: rotate_vector(p / 3, PI / 2)
field = VectorField(curl_func, axes)
result = curl_func(field.sample_coords)

Result:

  • 4 passed
  • field.sample_coords.shape == (561, 2)
  • result.shape == (561, 2) and all values are finite
  • compileall completed successfully

@QinXi-ai
QinXi-ai marked this pull request as ready for review August 14, 2026 05:08
@3b1b
3b1b merged commit 3e5bfce into 3b1b:master Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using Rotate_Vector in VectorField cause dimensions problem

2 participants