MRaster examples 21.0.0.0
Image Processing Library
|
For each pixel, simulate a double pendulum system over 2sec and color the pixel according to the pendulum end state. More...
Go to the source code of this file.
For each pixel, simulate a double pendulum system over 2sec and color the pixel according to the pendulum end state.
Copyright (c) 2025, Mitchell Jay Richling https://www.mitchr.me All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The equations of motion for the double pendulum may be written as a system of first degree differential equations:
\[\begin{eqnarray} \frac{\mathrm{d}\theta_1}{\mathrm{d}t} & = & \omega_1 \\ \frac{\mathrm{d}\theta_2}{\mathrm{d}t} & = & \omega_2 \\ \frac{\mathrm{d}\omega_1}{\mathrm{d}t} & = & \frac{-g (2 m_1+m_2) \sin(\theta_1)-m_2 g \sin(\theta_1-2 \theta_2)-2 m_2 (\omega_2^2 L_2+\omega_1^2 L_1 \cos(\theta_1-\theta_2))\sin(\theta_1-\theta_2)}{L_1 (2 m_1+m_2-m_2 \cos(2 \theta_1-2 \theta_2))} \\ \frac{\mathrm{d}\omega_2}{\mathrm{d}t} & = & \frac{2 \sin(\theta_1-\theta_2) (\omega_1^2 L_1 (m_1+m_2)+g (m_1+m_2) \cos(\theta_1)+\omega_2^2 L_2 m_2 \cos(\theta_1-\theta_2))}{L_2 (2 m_1+m_2-m_2 \cos(2 \theta_1-2 \theta_2))} \end{eqnarray}\]
Where
\[\begin{array}{lll} L_1 & = & \text{ Length of top bar} \\ L_2 & = & \text{ Length of bottom bar} \\ m_1 & = & \text{ Mass of top weight} \\ m_2 & = & \text{ Mass of bottom weight} \\ g & = & \text{ Acceleration of gravity} \\ \theta_1 & = & \text{ Vertical angle of top bar} \\ \theta_2 & = & \text{ Vertical angle of bottom bar} \\ \omega_1 & = & \text{ Angular velocity of top bar} \\ \omega_2 & = & \text{ Angular velocity of bottom bar} \end{array}\]
The idea is to run a double pendulum simulation for each pixel. Each pixel is mapped to a pair of angles – the x coordinate is mapped to \( \theta_1 \), and the y coordinate is mapped to \( \theta_2 \). These angles are used for the initial conditions for the double pendulum equations. We then solve these equations over a time span of 2 seconds using 200 steps of Euler's method. We dump an image of the final state of the simulation at the end.
Two ways are provided to map pixels to angles controlled by the boolean CENTER
. If it's true
, then the angles are mapped left to right & top to bottom from \(0\) to \(2\pi\). If it's false
, we map from \(-\pi\) to \(\pi\). The effect is that when CENTER
is true the larger angles are at the center of the image, and they are at the corners otherwise.
Inspired by a reddit post: https://www.reddit.com/r/FractalPorn/comments/1i4gdy8/visualization_of_a_double_pendulum_pixel_x_and_y/
Definition in file doublePendulum.cpp.