double_pendulum:随机双摆的动画

  • N0_945911
    了解作者
  • 58.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-19 02:27
    上传日期
Twitter机器人背后的代码,该动画发布了一个双摆的动画,该动画从一个随机位置释放了30秒。 基本用法 要创建一个随机双摆的动画: >> > from simulation import create_random_example , simulate >> > from animations import single_animation >> > rand_ex = create_random_example () >> > results = simulate ( rand_ex ) >> > single_animation ( results , rand_ex ) 动画保存为
double_pendulum-master.zip
  • double_pendulum-master
  • methods.py
    6.5KB
  • double_pendulum.png
    49.8KB
  • tweet_it.py
    1.6KB
  • README.md
    2.9KB
  • pendulum.py
    4.4KB
  • .gitignore
    89B
  • animations.py
    7.9KB
  • RK_DAE_solver.py
    4.3KB
  • simulation.py
    4.8KB
  • LICENSE.txt
    1KB
内容介绍
![Double pendulum](double_pendulum.png) The code behind [@pendulum_bot](https://twitter.com/pendulum_bot) Twitter bot which posts animations of a double pendulum released from a random position to swing for 30 seconds.   # Basic usage To create an animation of a random double pendulum: ```python >>> from simulation import create_random_example, simulate >>> from animations import single_animation >>> rand_ex = create_random_example() >>> results = simulate(rand_ex) >>> single_animation(results, rand_ex) ``` The animation is saved as .mp4 video in `animations` subdirectory. --- To create an animation and post it on Twitter, a valid API key is needed, and should be stored in `api_key.txt`. ```python >>> from tweet_it import new_tweet >>> new_tweet() # creates a new animation of random double pendulum # or >>> new_tweet('existing_file', 'My custom Twitter status') ``` --- To create double pendulum with the exact values for initial conditions: ```python >>> from pendulum import Pendulum, DoublePendulum >>> p1 = Pendulum(m=2.7, x=2.5, y=3.7, u=0, v=0) >>> p2 = Pendulum(m=3.1, x=0.2, y=6.3, u=0, v=0) >>> dp = DoublePendulum(p1, p2) ``` --- To create multiple pendulums with slight perturbations of initial conditions to observe chaotic behaviour: ```python >>> from simulation import create_random_example, create_perturbations, simulate_multiple_examples >>> from animations import multi_animation >>> rand_ex = create_random_example() >>> perturbed = create_perturbations(10, rand_ex, amount=1e-5) >>> results = simulate_multiple_examples(perturbed) >>> multi_animation(results, rand_ex) ```   # Installation ``` git clone https://github.com/narimiran/double_pendulum.git cd double_pendulum ``` ### Dependencies * Python 3 * numpy (running simulations) * matplotlib (creating animations) * ffmpeg or avconv/libavtools (saving videos) * twython (posting Twitter updates)   # FAQ Q: *Why do you use Cartesian coordinates? I prefer polar coordinates.* A: The initial task I was given was to implement double pendulum as DAE system in Cartesian coordinates. The idea for animations and Twitter bot came later, and Cartesian coordinates remained. Q: *Which Runge-Kutta methods can I use?* A: Any of these: * Forward Euler (`Euler`) * Explicit midpoint (`ExplicitMidpoint`) * Ralston's method (`Ralston`) * Kutta's 3rd order method (`Kutta3`) * *the* Runge-Kutta 4th order method (`RK4`) * Runge-Kutta-Fehlberg (`RKF`) * Cash-Karp (`Cash-Karp`) * Dormand-Prince method (`DOPRI5`) Q: *Why can't I use implicit Runge-Kutta methods?* A: Implicit methods require different solving method (solving a system of non-linear equations). This is not (yet) implemented. Q: *Is there any damping/friction?* There is no damping and no friction. The only force acting on the system is gravity. Q: *Couldn't all/some of this be done simpler?* A: Probably.   # License [MIT License](LICENSE.txt)
评论
    相关推荐