简体   繁体   English

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

[英]How to create animations of elliptic curves in manim?

I'm playing with manim and I'd like to create an animation with an elliptic curve.我正在玩 manim,我想创建一个带有椭圆曲线的动画。 This is my code, in the file functions.py:这是我的代码,在文件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:当我执行此命令manim -pql functions.py EllipticCurve时,我收到以下错误:

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?我相信FunctionGraph方法需要一个函数,而不是曲线,但我怎样才能动画和绘制椭圆曲线? Is there any other method?还有其他方法吗? Am I missing something?我错过了什么吗?

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

Plugging in negative values in your function is problematic, and so Manim complains.在你的函数中插入负值是有问题的,所以 Manim 抱怨。 Either pass x_range=[0, 7] to FunctionGraph , or check out ImplicitFunction (which to me seems more useful for working with elliptic curves).要么将x_range=[0, 7]传递给FunctionGraph ,要么查看ImplicitFunction (在我看来,这对于使用椭圆曲线更有用)。

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.最后一个提示:为FunctionGraph获得合理的缩放可能有点棘手,您可能需要考虑创建一个Axes mobject,然后使用相应的Axes.plotAxes.plot_implicit方法。

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:它使用隐式绘图,即轴对象axplot_implicit_curve方法,并产生:

椭圆曲线 yy = xxx - x + 19

Note: The wanted elliptic curve was extracted from the comments.注意:想要的椭圆曲线是从评论中提取的。 It is the curve y² = x³ - x + 19 .它是曲线y² = x³ - x + 19 (Of course, we cannot isolate y by extracting the square root "termwise" from the RHS - 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). (当然,我们不能通过从 RHS 中“逐项”提取平方根来隔离 y - 无论这些项的符号是什么......)曲线(从有理数上看)没有扭转点,它的等级是 1,生成器是 (2, 5)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM