如何在Manim中创建椭圆曲线的动画?

发布于 2025-01-27 22:40:07 字数 517 浏览 2 评论 0 原文

我正在与Manim一起玩,我想创建一个具有椭圆曲线的动画。这是我的代码,在file functions.py中:

from manim import *

class EllipticCurve(Scene):

    def construct(self):
        basic_ec = FunctionGraph(
           lambda x: x**1.5 - x**0.5 + 19**0.5
        )

        self.play(Create(basic_ec))

执行此命令 manim -pql functions.py ellipticcurve ,我得到以下错误:

value eRROR:value eRror:array不得包含infs或nans

我相信方法 functiongraph 期望功能,而不是曲线,但是我如何对椭圆曲线进行动画和绘制呢?还有其他方法吗?我想念什么吗?

I'm playing with manim and I'd like to create an animation with an elliptic curve. This is my code, in the file functions.py:

from manim import *

class EllipticCurve(Scene):

    def construct(self):
        basic_ec = FunctionGraph(
           lambda x: x**1.5 - x**0.5 + 19**0.5
        )

        self.play(Create(basic_ec))

When I execute this command manim -pql functions.py EllipticCurve, I get the following error:

ValueError: array must not contain infs or NaNs

I believe the the method FunctionGraph expects a function, instead of a curve, but how can I animate and plot an elliptic curve? Is there any other method? Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2025-02-03 22:40:07

您正正确地将函数传递到 functiongraph ,问题是,如果您没有明确指定图的 x_range ,则Manim将选择范围 [ - config.frame_x_radius,config.frame_x_radius] (也就是说,它跨越整个宽度
框架;默认情况下为-7.11至+7.11)。

插入功能中的负值是有问题的,因此Manim抱怨。通过 x_range = [0,7] to functiongraph ,或者查看 对于使用椭圆曲线更有用)。

还有一个最后的提示:获得 functiongraph 的理智缩放可能有点棘手.plot 或 axes.plot_implitic 方法。

You are passing the function to FunctionGraph correctly, the problem is that if you don't explicitly specify a x_range for the plot, Manim will choose the range [-config.frame_x_radius, config.frame_x_radius] (that is, it spans over the entire width
of the frame; by default from -7.11 to +7.11).

Plugging in negative values in your function is problematic, and so Manim complains. Either pass x_range=[0, 7] to FunctionGraph, or check out ImplicitFunction (which to me seems more useful for working with elliptic curves).

And one final hint: It can be a bit tricky to get sane scaling for FunctionGraph, you might want to consider creating an Axes mobject and then use the corresponding Axes.plot or Axes.plot_implicit methods.

心凉怎暖 2025-02-03 22:40:07

以下对我有用:

#!/usr/bin/env python
"""
# python -m manim --quality l simple_ec.py EllipticCurve1 -p
"""
from manim import *

class EllipticCurve(Scene):
    def construct(self):
        ax = Axes(x_range=[-3.2, 6.2, 1], y_range=[-21, 21, 10]
                  , x_length=14         , y_length=7.5
                  , color=BLUE
                  , x_axis_config={"numbers_to_include": range(-3, 6 + 1, 1),
                                   "font_size": 24,}
                  , y_axis_config={"numbers_to_include": range(-20, 20 + 10, 10),
                                   "font_size": 24,}
                  , tips=False)
        
        a = ax.plot_implicit_curve(lambda x, y: -y**2 + x**3 - x + 19
                                   , color=YELLOW)

        plane = NumberPlane(x_range=[-3.2, 6.2, 1], y_range=[-21, 21, 10]
                            , x_length=14         , y_length=7.5
                            , color=GRAY)

        self.add(ax, a, plane)
        self.wait(5)
        

它使用隐式图,轴对象的方法 plot_implitic_curve axe> ax ,并且正在产生:

”

注意:从评论中提取了通缉的椭圆曲线。它是曲线y²=x³-x + 19 。 (当然,我们无法通过从RHS中提取平方根“术语”来隔离y-无论术语的符号是什么...)曲线(在理由上看到)没有扭转点,其等级是一个,是一个,并且发电机为(2,5)。

The following worked for me:

#!/usr/bin/env python
"""
# python -m manim --quality l simple_ec.py EllipticCurve1 -p
"""
from manim import *

class EllipticCurve(Scene):
    def construct(self):
        ax = Axes(x_range=[-3.2, 6.2, 1], y_range=[-21, 21, 10]
                  , x_length=14         , y_length=7.5
                  , color=BLUE
                  , x_axis_config={"numbers_to_include": range(-3, 6 + 1, 1),
                                   "font_size": 24,}
                  , y_axis_config={"numbers_to_include": range(-20, 20 + 10, 10),
                                   "font_size": 24,}
                  , tips=False)
        
        a = ax.plot_implicit_curve(lambda x, y: -y**2 + x**3 - x + 19
                                   , color=YELLOW)

        plane = NumberPlane(x_range=[-3.2, 6.2, 1], y_range=[-21, 21, 10]
                            , x_length=14         , y_length=7.5
                            , color=GRAY)

        self.add(ax, a, plane)
        self.wait(5)
        

It uses an implicit plot, the method plot_implicit_curve of the axes object ax, and is producing:

elliptic curve yy = xxx - x + 19

Note: The wanted elliptic curve was extracted from the comments. It is the curve y² = x³ - x + 19 . (Of course, we cannot isolate y by extracting the square root "termwise" from the R.H.S. - whatever the signs of the terms may be...) The curve (seen over the rationals) has no torsion points, its rank is one, and a generator is (2, 5).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文