如何将笛卡尔平面 (NumberPlane()) 上的变换应用于极坐标平面?
How to apply transform on Cartesian plane (NumberPlane()) to Polar plane?
在 this video 中,Grant 执行非线性变换。
从笛卡尔坐标到极坐标的变换也是非线性的。我们发现雅可比矩阵的行列式为 1/r。我可以 replicate the transform that Grant did, but how to animate this cartesian to polar using manim. In other words, what would be f1 and f2. I tried (x^2 + y^2)^0.5 和 arctan(y/x)
def construct(self):
def arctan(x, y):
if x and y == 0:
return 0
else:
return np.arctan(y / x)
grid = NumberPlane()
grid.prepare_for_nonlinear_transform()
self.play(
grid.apply_function,
lambda p: p + np.array([
(p[0]**2 + p[1]**2)**0.5,
arctan(p[0], p[1]),
0,
]),
run_time=3,
)
class AV(Scene):
def construct(self):
def polar2c(p):
return np.array([
p[0]*np.cos(p[1]),
p[0]*np.sin(p[1]),
0
])
grid = NumberPlane(
x_line_frequency=PI/4,
y_line_frequency=PI/4,
x_min=-PI,
x_max=PI,
y_min=-PI,
y_max=PI
)
func = FunctionGraph(lambda x: 0.5*np.sin(5*x)+2,x_min=-PI,x_max=PI)
grid.add(func)
self.add(grid)
grid.faded_lines[4:9].fade(1)
grid.faded_lines[12:].fade(1)
grid.background_lines[4:9].fade(1)
grid.background_lines[12:].fade(1)
self.play(Rotating(func,radians=PI,axis=UR,about_point=ORIGIN,run_time=2,rate_func=smooth))
grid.generate_target()
grid.target.prepare_for_nonlinear_transform()
grid.target.apply_function(lambda p: polar2c(p))
self.play(
MoveToTarget(grid,run_time=4)
)
self.wait(3)
在 this video 中,Grant 执行非线性变换。 从笛卡尔坐标到极坐标的变换也是非线性的。我们发现雅可比矩阵的行列式为 1/r。我可以 replicate the transform that Grant did, but how to animate this cartesian to polar using manim. In other words, what would be f1 and f2. I tried (x^2 + y^2)^0.5 和 arctan(y/x)
def construct(self):
def arctan(x, y):
if x and y == 0:
return 0
else:
return np.arctan(y / x)
grid = NumberPlane()
grid.prepare_for_nonlinear_transform()
self.play(
grid.apply_function,
lambda p: p + np.array([
(p[0]**2 + p[1]**2)**0.5,
arctan(p[0], p[1]),
0,
]),
run_time=3,
)
class AV(Scene):
def construct(self):
def polar2c(p):
return np.array([
p[0]*np.cos(p[1]),
p[0]*np.sin(p[1]),
0
])
grid = NumberPlane(
x_line_frequency=PI/4,
y_line_frequency=PI/4,
x_min=-PI,
x_max=PI,
y_min=-PI,
y_max=PI
)
func = FunctionGraph(lambda x: 0.5*np.sin(5*x)+2,x_min=-PI,x_max=PI)
grid.add(func)
self.add(grid)
grid.faded_lines[4:9].fade(1)
grid.faded_lines[12:].fade(1)
grid.background_lines[4:9].fade(1)
grid.background_lines[12:].fade(1)
self.play(Rotating(func,radians=PI,axis=UR,about_point=ORIGIN,run_time=2,rate_func=smooth))
grid.generate_target()
grid.target.prepare_for_nonlinear_transform()
grid.target.apply_function(lambda p: polar2c(p))
self.play(
MoveToTarget(grid,run_time=4)
)
self.wait(3)