Using Rotate_Vector in VectorField cause dimensions problem
Describe the error
When I was using rotate_vector to write a function for VectorField, there is a dimension error, which is not a problem in past versions.
Code and Error
Code:
from manimlib import * # type: ignore
class Simulation(Scene):
def construct(self) -> None:
axes = NumberPlane()
def div_func(p: np.ndarray) -> np.ndarray:
return p / 3
field_dir = VectorField(div_func, axes)
self.play(FadeIn(field_dir))
def curl_func(p): # <- this function
return rotate_vector(p / 3, PI / 2)
field_curl = VectorField(curl_func, axes)
self.play(
ReplacementTransform(field_dir, field_curl), run_time=1
)
Error:
Traceback (most recent call last):
File "/Users/cengyi/miniconda3/envs/manimgl/bin/manimgl", line 8, in
Environment
OS System: MacOS manim version: master (have used the changes in PR #2330) python version:3.13.2
This is an example of the usage of rotate_vector in 3B1B's video in _2018 dir_curl:
class Introduction(MovingCameraScene):
CONFIG = {
"stream_lines_config": {
"start_points_generator_config": {
"delta_x": 1.0 / 8,
"delta_y": 1.0 / 8,
"y_min": -8.5,
"y_max": 8.5,
}
},
"vector_field_config": {},
"virtual_time": 3,
}
def construct(self):
# Divergence
def div_func(p):
return p / 3
div_vector_field = VectorField(
div_func, **self.vector_field_config
)
stream_lines = StreamLines(
div_func, **self.stream_lines_config
)
stream_lines.shuffle()
div_title = self.get_title("Divergence")
self.add(div_vector_field)
self.play(
LaggedStartMap(ShowPassingFlash, stream_lines),
FadeIn(div_title[0]),
*list(map(GrowFromCenter, div_title[1]))
)
# Curl
def curl_func(p):
return rotate_vector(p / 3, 90 * DEGREES)
It's all written in the error:
ValueError: shapes (561,2) and (3,3) not aligned: 2 (dim 1) != 3 (dim 0).
p should have 3 columns instead got 2. I believe it's a 2D vector, it should be 3D