Basic physics simulation of a chain

Overview

Basic Chain Simulation

Compile using for example

$ g++ ChainElement.cpp ChainLink.cpp Chain.cpp Simulation.cpp main.cpp -std=c++11 -o run -O3

The output data is written to the subdirectory data/. Use for example the provided gnuplot script plot.plt to plot the results.

See also the demonstration for an example application for the simulation of the chain fountain or Mould effect as well as illustration of the model used here.

Simulation Setup

The setup of a simulation consists of two steps, configuring the boundaries (walls and other obstacles) and the chain itself. At first a simulation object has to be created,

Simulation thisSimulation;

This object stores all information on a single simulation.

  • boundary: There are two types of boundaries currently implemented. The walls are defined as segments with a start and end point. Geometric points are generally represented as Vector objects like
Vector thisVector(1.0, 1.0);

Furthermore, walls have an orientation associated with them. This orientation or surface normal is defined to point in a 90° angle (i.e. to the left) relative to the relative vector from start to end point of the wall. All wall-type boundaries are collected in the member walls of the simulation object, a std::vector . The procedure addTrailofWalls(..) can be used to comfortably introduce new walls into the system. Its argument is a std::vector with alternating start and end points, e.g.

thisSimulation.addTrailofWalls(std::vector
   
    {
	Vector(0.0, 0.0), Vector(1.0, 0.0), // wall segment 1 from (0,0) to (1,0)
	Vector(1.0, 0.0), Vector(1.0, 1.0) // wall segment 2 from (1,0) to (1,1)
});

   

The second option for creating boundary objects is the routine addSphericalBoundary(..) again for the simulation object in order to create a spherical boundary. The three required arguments are the x- and y-coordinates as well as the radius.

  • chain: The chain object for the simulation can be created by using for example
thisSimulation.initChain(numberOfSamples, chainThickness, chainStiffness, chainStiffnessOffset, chainStability);

Here, the parameters numberOfSamples denotes the total number of samples (or depending on the application the number of beads) used to simulate the chain, chainThickness the chain's cross section diameter/bead diameter, chainStiffness the strength of the resistance to being bent, chainStiffnessOffset the offset for the chain's stiffness allowing some amount of bending without internal forces, and chainStability the strength of the resistance to being pulled apart. While this sets up some of the internal data of the simulation object, it is required that the equilibrium state of the chain is defined as well (basically the distance between samples in the chain). This can be done by for example the procedure

thisSimulation.chain.quickArrangementEntwined(Vector(startX, startY), thisRadius, thisLoops, thisTranslation);

Using this the chain is first arranged in a two-dimensional helix shape starting at Vector(startX, startY) and with radius thisRadius and thisLoops number of loops as well as a rate of translation thisTranslation. Afterwards the relative distances between chain samples are stored as the chain's equilibrium position.

Execution

Using the method step(..) with the argument of the number of time steps (time step length is stored in the variable dt of the simulation object) on the simulation allows to advance the system in time. Use for example

thisSimulation.step(floor(1.0/60.0/thisSimulation.dt));

to perform time steps roughly equivalent to one 60th of a second. The numerical integration is done with a Runge-Kutta algorithm of fourth order. Inbetween calls to step(..) a sample-specific external acceleration/force can be configured by setting for example

thisSimulation.chain.elements[sampleIndex]->externalax = 9.81;

resulting in the sample sampleIndex (counting starts at zero) experiencing an external force equal to gravity but in the positive x-direction.

In- and Output

A simulation object allows to write its current state to a data file. First, the boundary elements created initially can be written to a file using

thisSimulation.writeWallsToFile("thisBoundary.dat");

The written file contains the x- and y-coordinates of wall segments as well as sampled spherical boundary elements such that it can easily be plotted with any common graphing utility like gnuplot. The chain itself can be written to a file by invoking

thisSimulation.writeChainToFile(someIndex);

This procedure writes the x- and y-coordinates of all chain samples to a file in the data/ subdirectory in the format outputXXXXX.dat where the blanks are filled with the 5-digit decimal representation of someIndex. Lastly, the current state of a chain can be written to a file using a different format suitable for a later restoration of a system state. Use

thisSimulation.saveChainBackup("thisChainBackup.dat");

to write the backup file. Restoring a specific system state requires that the system setup is performed in a compatible manner. This means that the chain has to be initialized with initChain(..) and the previous equilibrium distances between samples have to be configured indentically (using for example the same arguments for a call to quickArrangementEntwined(..).

Owner
Steffen Richters-Finger
Steffen Richters-Finger
Resources for DFIR Professionals Responding to the REvil Ransomware Kaseya Supply Chain Attack

Resources for DFIR Professionals Responding to the REvil Ransomware Kaseya Supply Chain Attack Yesterday Sophos and Huntress Labs identified that Kase

Cado Security 168 Jun 25, 2022
A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control.

N.A.G.E.K.I. A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control. 中文版

NanaNana 27 Jun 17, 2022
A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control.

N.A.G.E.K.I. PLEASE CHECK Main Project A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Us

NanaNana 11 Dec 30, 2021
A PIC/FLIP fluid simulation based on the methods found in Robert Bridson's "Fluid Simulation for Computer Graphics"

GridFluidSim3d This program is an implementation of a PIC/FLIP liquid fluid simulation written in C++11 based on methods described in Robert Bridson's

Ryan Guy 712 Jun 22, 2022
Integrate the ZENO node system into Blender for creating robust physics animations!

ZenoBlend Integrate the ZENO node system into Blender for creating robust physics animations! End-user Installation Goto Release page, and click Asset

Zenus Technology 31 Jun 10, 2022
This repository consists an implementation of the Algorithms encountered in Computer Science, Physics and Mathematics.

All the Algorithms you'll ever need xD This repository contains all the algorithms we have encountered in the fields of Computer Science, Mathematics

ACM VIT 7 Jan 2, 2022
Open source C++ physics engine library in 3D

ReactPhysics3D ReactPhysics3D is an open source C++ physics engine library that can be used in 3D simulations and games. www.reactphysics3d.com ?? Fea

Daniel Chappuis 1k Jun 20, 2022
Improved version of real-time physics engine that couples FEM-based deformables and rigid body dynamics

Enhanced version of coupled FEM and constrained rigid body simulation Description This little playground aimed to test our Conjugate Gradients based M

Andrey Voroshilov 25 Apr 11, 2022
Real-time oriented physics engine and library that's currently best suited for 2D games.

PlayRho A way to play with physical behaviors like the conservation of momentum. PlayRho is a real-time oriented physics engine and library that's cur

Louis Langholtz 85 Jun 25, 2022
2D physics header-only library for videogames developed in C using raylib library.

Physac Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop to simluate physics. A physics step contai

Víctor Fisac 218 Jun 24, 2022
A simulation of Newton's law of universal gravitation

Newton's law of universal gravitation This simulation uses the famous equation of Isaac Newton

Long Nguyen 54 Feb 24, 2022
A line follower simulation created in CoppeliaSim, with a C++ interface for CoppeliaSim's Remote API

Wall-E-Sim A line follower simulation created in CoppeliaSim, with a C++ interface for CoppeliaSim's Remote API This is a simuation of SRA's Wall-E bo

Anushree Sabnis 17 Apr 24, 2022
This is a simulation of Livox lidar

Livox Laser Simulation A package to provide plug-in for Livox Series LiDAR.

lvfengchi 48 May 25, 2022
A Rideshare Simulation built in C++, using OpenStreetMap data

My Capstone project for the C++ Nanodegree at Udacity, a rideshare simulator. It extends the concurrency project based on a traffic simulation, as well as taking in parts of the earlier route planning project, in order to simulate ridesharing apps that are able to pick up passengers

Michael Virgo 10 Apr 3, 2022
Simulation of VT100 terminal hardware

Simulation of the VT100 hardware About This is a software simulation of the VT100 hardware. The original firmware ROM is built in and executed by an 8

Lars Brinkhoff 48 Mar 26, 2022
A ROS based Open Source Simulation Environment for Robotics Beginners

A ROS based Open Source Simulation Environment for Robotics Beginners

Sulegeyixiu 101 Jun 25, 2022
a poc implementation arm64 tracer based on simulation

sim-trace a poc implementation arm64 tracer based on simulation Build Test ndk-build NDK_DEBUG=1 Run Test adb push test /data/local/tmp/test && adb s

null 26 Jun 17, 2022
New lateral movement technique by abusing Windows Perception Simulation Service to achieve DLL hijacking code execution.

BOF - Lateral movement technique by abusing Windows Perception Simulation Service to achieve DLL hijacking ServiceMove is a POC code for an interestin

Chris Au 170 Jun 20, 2022
This is a simple simulation of NASA's Sojourner Mars rover.

This is a simple simulation of NASA's Sojourner Mars rover. The rover starts moving on its own over a simulated martian surface and can be controlled using the keyboard.

Ernesto Corbellini 4 Nov 15, 2021