Questions tagged [physics]

Physics is a science that studies the interactions of energy and matter. The physics tag should be used for questions about how physics can be simulated or implemented in programming.

Filter by
Sorted by
Tagged with
6
votes
1answer
206 views

Golf Physics “Game”

Continuation of this post I wrote a program in pygame that basically acts as a physics engine for a ball. You can hit the ball around and your strokes are counted, as well as an extra stroke for ...
6
votes
1answer
42 views

Module for isotopic masses and abundances

I have written a small module for accessing data on isotope masses and relative abundances. My long term aim is to build tools in Haskell for working with mass spectrometry data. Any comments on how ...
6
votes
1answer
566 views

Solving a one-dimensional Euler equation for fluid dynamics

I just wrote a program to solve one dimensional Euler equation for fluid dynamics. Attached is a snippet of the vtune profile result for one of the function. There are a few things which looks weird ...
6
votes
1answer
3k views

Java snow animation

I was inspired by this to write a graphic snow animation in Java/Processing. It works great, but it has some design issues. The full project is here on github; ...
6
votes
1answer
83 views

Pong Game in JS

I am new to game development and took on the task to create a Pong replica due to my curiosity and interest in the field. I decided to write it in JavaScript because the game is not too labor ...
5
votes
2answers
268 views

Simulation of spring-loaded inverted pendulum

I've finally committed to moving to Python 3 from MATLAB. I'm currently porting my MATLAB code, and I'm sure I'm missing a lot of common best-practices. For reference, I'm simulating a spring-loaded ...
5
votes
1answer
122 views

Calculating a table of deBroglie wavelengths for various electron energies

Here is the formula for the deBroglie wavelength of an electron versus its kinetic energy: $$ \lambda(E_k) = h\left/\sqrt{\frac{(E_k+m_eC^2)^2-m_e^2C^4}{C^2}}\right.$$ and here is simple script that ...
5
votes
3answers
141 views

Determining vehicle jump landing quality

I am writing a game where a car drives and makes jumps. When a jump is landed, the player is rewarded if they land all four wheels either at the same time, or near to the same time. If they don't, ...
5
votes
1answer
7k views

Comparing data to model and returning a chi squared value

This is quite basic but useful to test various (9) different models using one set of data. I have tried to make it clear and use the PEP8 formatting. I am currently creating a version that can read ...
5
votes
1answer
71 views

Gravity problem solver in Factor

After answering a question about Factor, I decided that it looked interesting. To get the hang of the syntax and such, I decided to write some basic physics code to "solve" the three-body problem. ...
5
votes
2answers
177 views

Computing the RPY tensor with C++/Eigen (linear algebra)

I'm mostly used to writing scientific code in MATLAB / Python / Julia and my experience with C++ is very limited. I've implemented a fairly simple computation of the Rotne-Prager-Yamakawa tensor in ...
4
votes
2answers
63 views

Modelling solar system, Runge-kutta 4 (n-Body problem)

I have a program that simulations all planets, where the forces due to each planet is considered during each time step.I'm looking to see where I could make some improvements. main.cpp ...
4
votes
3answers
666 views

Simulating a closed particle system in Java

I have this program that simulates a closed particle system. Closed in this context means that the sum of all energies is constant. My primary concern is code itself, yet I would like to hear comments ...
4
votes
2answers
209 views

Python object-oriented pipe cooling simulations

Here is my code simulating liquid in a pipe cooling under different conditions. How did I do approaching this in an object orientated way? Is there any way I can improve this code? ...
4
votes
1answer
65 views

Making basic physics object class

I'm creating a 2D game in JS, and I've made the generic class that all objects in the game will be (I've decided they are all circular for now). An object has ...
4
votes
1answer
124 views

Implementation of Point, Velocity and Acceleration in Haskell

I'm trying to implement point, velocity and acceleration types. They should be connected by some derive function which: takes time and velocity and returns a ...
4
votes
2answers
177 views

2D physics game engine

I'm writing a 2D game engine, and I just wrote the physics for it to handle collisions between AABBs and circles. It's on GitHub. Some of my worries are that my code isn't OOP, because I have to do ...
4
votes
2answers
172 views

Trapezoidal rule for set of data

Here is the question from the book of Mark Newman-Computational Physics Exc 5.1 a) Read in the data and, using the trapezoidal rule, calculate from them the approximate distance traveled by the ...
4
votes
2answers
61 views

Simple spatial grid for particle system

I am going to simulate a particle system, the particles are infinitesimal points which apply forces on the neighbors and I need a fast way of making proximity checks, they are going to have a maximum ...
4
votes
1answer
233 views

Gravity simulation using Numpy and Pygame

This is a simple gravity simulator coded in Python 3.7 using Numpy and Pygame. I was wondering if it can be optimized further. Initially I had coded it using pure Python lists, using nested loops to ...
4
votes
2answers
75 views

Generating Position

I'm written the following code to calculate the position of a motor during each timestep, the result of which will be compared with feedback from a quadrature encoder and subjected to a PID algorithm. ...
4
votes
0answers
70 views

Butter side up?

I've written a piece of code that determines if a piece toast with butter lands on the butter-side or not, depending on its initial velocity and the table height. The code is written in Mathematica ...
4
votes
0answers
2k views

Satellite orbit simulation in Matlab using Runge Kutta 4

I have a satellite orbit simulation in Matlab (Using Runge Kutta 4). It seems ugly and I don't know how to fix it. fx.m file: function v = fx(t,x,vx) v = vx; ...
3
votes
2answers
368 views

Calculating the push or pull force of a molecule at a vertex

The basic idea of the code is to calculate the push or pull force at a vertex, given the number of "push causing molecules" and "pull causing molecules" at a polygon vertex. The code thus mainly ...
3
votes
3answers
423 views

Creating and manipulating FITS files

I wrote a program that manipulated data from VLA observations and created FITS files to be used in creating spectral energy distributions of high redshift radio galaxies. I really tried to be as ...
3
votes
1answer
648 views

Explosion animation plugin for a game

I have been writing a small particle plugin since I want to learn how physics works for games. Now I have tried to get this as clean as I possible could but It feels something is missing. Am I ...
3
votes
1answer
52 views

Dynamical system animation framework

Introduction I am developing a dynamical system simulation/animation framework, which provides three abstract base classes, DynamicalSystem, ...
3
votes
1answer
90 views

Molecular dynamics simulation

I'm looking for some fresh ideas on how to optimize a couple of functions in my C++ code. I run the code through a profiler and it shows that they take 20% and 40% of the time respectively. The ...
3
votes
1answer
150 views

Very slow frame rate in C++ N-body simulation using Barnes-Hutt and RK4

I am writing the code for my EPQ project and am aiming to produce a graphic showing the collapse of a particle cloud with around 10^5/6 particles. My current code will spawn a specified number of ...
3
votes
1answer
112 views

Quickly applying gravity force between bodies

I have a function for applying gravity forces between every possible pair of bodies on my game. It is the most used function, and can run more than 100k times per frame so every minor improvement on ...
3
votes
1answer
94 views

Diffusion Limited Aggregation Simulator

Based on my answer to another code review question I wrote my own python script for DLA (Diffusion Limited Aggregation). The DLA algorithm task: Place seed at the center of the canvas. Release a ...
3
votes
1answer
114 views

Optical dispersion calculation from spectrograms with Python

First, I'd like to provide a little explanation on what my code is supposed to do. It is part of a middle-sized project. I restructured the code to work on its own, and also added little comments to ...
3
votes
1answer
103 views

Simplified three-body simulation

The code below simulates a given Newtonian 3 body system. Each row per slice is supposed to represent a Cartesian component for the initial trajectory vector and for the distance vectors to the other ...
3
votes
2answers
523 views

Simulating a system of moving points

This is an update of the code from my previous question. I'm simulating a system of particles which interact with each other and move and rotate due to the interaction. There are 2000 particles in ...
3
votes
2answers
758 views

Program based on a physics concept

I am a beginner and I wanted to make programs that would help me while I learnt Java. I made a program to help me in my assignments. Any suggetions? Main method ...
3
votes
1answer
2k views

Solving an ODE numerically with forward Euler method

The goal is to solve an ODE numerically with forward Euler method. The programs works well (numerical solution really near analytical one). The problem I see is that the Euler scheme don't jump to ...
3
votes
1answer
100 views

N-Body Gravitational Simulation of Point-Masses in Python

I made an n-body gravitational simulation in python. The algorithm does produce an approximate solution, which is shown at the bottom of the post. Additional methods to produce animations (among other ...
3
votes
1answer
108 views

Evolutionary algorithm to optimize the range of a glider

I created an evolutionary algorithm that optimises the range of a "glider"...ignore the accuracy of the physics behind the problem! Any comments on how to improve the algorithm/my coding style would ...
3
votes
1answer
97 views

Trajectory optimizations

Here's a function doing some trajectory optimization in the following manner: ...
2
votes
2answers
4k views

My first Physics Engine C++

I have made my first physics engine for simulating circles in a plane. Let me know what you think about it. ...
2
votes
4answers
527 views

Calculating energy from mass and light speed

I'm learning Java JDK 1.8 since one day and I'm using Java's methods to the first time. I have never used Java before because I'm a Python/Django developer. I created a method which let to get energy ...
2
votes
1answer
2k views

Calculator for finding mass

I've been trying to create a calculator to find mass using any and all known equations. The program will also return the steps used to find mass so the user can 'check their work' on physics ...
2
votes
3answers
3k views

Calculating work using dot product in C++

Write a C++ program fulfilling the following task: The user should enter the 3 dimensional force vector F and a 3 dimensional length vector s. The force is assumed to be constant. The program then ...
2
votes
1answer
97 views

d3.js canvas performance

I've just rewritten this code (a simple gravitational restricted n-body simulation) to display using canvas, rather than SVG. The reason being that I'd like to be able to run it with many thousands of ...
2
votes
2answers
4k views

Simulation of 2D elastic balls

Following this SO post and this Wikipedia article, I wrote a Python script to simulate physics of 2D elastic balls. I define the physical behaviour of each ball in the ...
2
votes
2answers
2k views

Simulating motion of particles

Description The code does particle simulation. In this code, some particles take steps with a certain distribution length. if particles go beyond a curve, the code put them back. Code ...
2
votes
1answer
407 views

Cross product to find Lorentz force in C++

User enters velocity vector \$v\$, charge \$q\$ of particle and magnetic field vector \$B\$ and the code prints the Lorentz force \$F = q * (v * B)\$ ...
2
votes
1answer
2k views

2D Physics Simulation (game-like)

My program is meant to simulate 2D physics(hopefully 3D as well in the future), namely classical mechanics and eventually electromagnetism. Currently it simulates projectile motion by firing a ...
2
votes
1answer
78 views

Accurately calculating gravity for large systems

I'm in the middle of a program to simulate gravity between particles for > 50000 particles. It works so far, but the way I calculate gravity seems to be a tad askew. Generally, it works. It fails when ...
2
votes
1answer
681 views

Velocity verlet implementation

My code is meant to update the positions and velocities of planets. There are a few methods in this class, but updatePosition and ...