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.

learn more… | top users | synonyms

6
votes
1answer
185 views

Calculators for gas law equations

I've made a C++ program that calculates a missing variable in an equation for one of the five following laws of gas: Boyle's Law Charles' Law Gay-Lussac's Law Avogadro's Principle Ideal Gas Law The ...
8
votes
2answers
188 views

Kinematic Equations

I'm learning the kinematic equations in Concepts of Engineering and so here are the equations I am learning: To complete the lesson, I was told to create a Python program that outputs the horizontal ...
14
votes
1answer
131 views

“Do I understand the gravity of the situation?”

What is this? This is a two-dimensional physics simulator that models gravity and collisions between circular objects (though it doesn't model rotation). How do you use it? You can tweak the ...
3
votes
1answer
57 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 ...
5
votes
1answer
83 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 ...
12
votes
4answers
214 views

Lines, intersections and terrible unit tests

I needed Line and LineF for the next stage of a project I'm working on, so I developed them. I also needed to determine if two ...
2
votes
0answers
53 views

didSimulatePhysics to animate a ball, taking 45% of CPU

According to my time profiler this is taking 45% of my cpu usage: have tried to optimize, and someone on stack overflow -- recommended to post here. Time profiler says 99% of the time is spent on the ...
4
votes
1answer
59 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 ...
3
votes
1answer
92 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 ...
2
votes
0answers
78 views

Physical simulation of diffusion-limited aggregates

The following code generates Diffusion Limited Aggregates on a two-dimensional square lattice. Some of the code has been omitted (e.g. support for differing lattice types and dimensions) for code-...
1
vote
0answers
139 views

Snell's law using Zoeppritz equation by matrices

I have created the following code to calculate Snell's law angles, based on Zoeppritz equations on complex plane. The code works, seems it is returning valid values, but after all the code just looks ...
2
votes
2answers
404 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 ...
8
votes
1answer
361 views

2D colliding disks in JavaScript (ideal billiard balls)

I am implementing a simulation of colliding disks (ideal 2D billiard balls) in JavaScript. I follow an event-driven algorithm that avoids discretizing time; the algorithm goes as follows at each step:...
0
votes
1answer
65 views

Calculating an object's stopping distance

I'm trying to smooth the movement of a cursor which has a set acceleration and max speed. I wrote this function to calculate the stopping distance of an object given its speed and acceleration, and it ...
3
votes
1answer
187 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 ...
6
votes
3answers
220 views

1D shock tube problem written in Fortran

I have written a simple Euler solver for the 1D shock tube problem. Eventually, I plan to extend this code to solve the full 3D compressible Navier-Stokes equations. Therefore, I want to start with ...
12
votes
2answers
563 views

Gravitational Brute Force N-body Algorithm

I've just started dabbling with code, and as a learning exercise I've written a simple algorithm for solving gravitational n-body problems numerically in JavaScript. I would be very grateful for ...
3
votes
3answers
114 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 ...
6
votes
1answer
599 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; ...
5
votes
1answer
83 views

Visual solution of the Newtonial differential equation with Python

I wrote this Python code that plots the movement of an object under the effect of a given force function in 2D by solving the Newton's movement equation numerically. One can add other force functions, ...
2
votes
1answer
219 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 ...
8
votes
0answers
168 views

Fluid Simulation with SDL

I have always wanted to write a fluid simulation, and with the help of a paper and some StackOverflow users I've got something that works. My goal is to have a program that someone can run right away ...
7
votes
3answers
85 views

Solving for every variable in a number of physics formulas

I'm working on making an iOS app to solve physics problems and I'm starting by just having it solve basic kinematics problems with the following formulas (I've coded it in C instead of Swift to start ...
11
votes
1answer
184 views

Basketball Collisions with Box2d

I'm working on a new prototype that is a simple drag and shoot arcade basketball game. For this project I am working with LibGDX and the Box2d physics library. You can play the game here: Play ...
8
votes
2answers
548 views

Solar System model

I have a model that works, as far as I know, but it's so messy! I am very new to Java, so I'd really appreciate some help tidying up. In particular, a lot of my constructors are empty which is ...
14
votes
3answers
856 views

Orbital Trajectory simulator

I have written a simple program to do trajectory simulation in the Earth-Moon system, it still has a long way to go I am working on making it more class oriented and am looking into implementing a ...
17
votes
4answers
312 views

Ising Model - Atom Vibration Simulation in Scala

I am an experienced Java developer (12+ years) and have recently switched to Scala and I love it. However I feel not comfy yet and I have a feeling that I might use to many paradigms from the good old ...
6
votes
2answers
129 views

Simulating gravitational attraction between bodies - follow up

I've decided to revisit a chunk of code I wrote a while back, and see what I could do to make some changes. As a result, I know have slow, but working piece of code which is able to simulate ...
3
votes
1answer
69 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 ...
4
votes
2answers
75 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? ...
6
votes
3answers
149 views

Python differential analysis of heat loss across a pipe

I made a differential equation solver to forecast heat loss through a pipe with heat loss coefficient contours. It does what I want it to do but I had to use global variables to change the outputs of ...
6
votes
1answer
39 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 ...
3
votes
2answers
136 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 ...
8
votes
2answers
276 views

Roll-a-ball controller

I've been toying around with Unity 5 lately, and in an effort to start making an actual game, I've built a ball controller similar to the one found in the Unity tutorial Roll-a-ball. In essence, the ...
6
votes
1answer
258 views

Kinematic Equations Calculator

The program allows user to enter values for 3 of the following initial velocity final velocity acceleration displacement time and to specify an unknown (one of the previously mentioned variables)....
6
votes
4answers
941 views

Artillery game C++ practice project

I've completed a program as a learning experience to make sure I've got the concepts down. I found a practice project online and decided to try it out. The program compiles and runs exactly how it ...
7
votes
1answer
90 views

Animating a 2D particle “web”

I have written a small class to generate and animate one of those trendy particle webs. I plan to use this as the main background of my personal website, so naturally I'm concerned about the ...
4
votes
2answers
67 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
2answers
88 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 ...
8
votes
2answers
99 views

Particle swarm optimization - follow-up

This is a followup post to Particle Swarm Optimization. I wrote a script in Python for particle swarm optimization and I posted it here to get comments on the design. I was told that encapsulating ...
15
votes
3answers
512 views

Simulating gravitational attraction between bodies

I'm currently working on a simple simulator in Unity3D that involves planets orbiting each other. I wrote the following C# script to do that. It uses the classic gravitational formula, $$F=G\frac{...
6
votes
1answer
139 views

N-body sim with Barnes-Hut - Follow up

Link to previous question: Barnes-Hut N-body simulator It still has issues I'm sure. Node.h ...
16
votes
2answers
2k views

Barnes-Hut N-body simulator

I've written an n-body simulator, implementing the Barnes-Hut algorithm. Please comment on anything you can see wrong with this. Wikipedia Barnes-Hut page This is a screen shot of the simulation 20 ...
5
votes
1answer
64 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. ...
7
votes
1answer
126 views

Processing.js physics simulation

I've been fooling around in JavaScript again, and I've come up with this simple physics simulation. I think it has a pretty simple setup, here's "psuedocode" of sorts to explain it. Constructor ...
8
votes
4answers
4k views

Brute Force N Body Implementation in C++

I have wrote the following code in C++ for the n-body problem. This code is sequential as later on I am planning to parallelize it using OpenMP. I want to know whether I have wrote the correct ...
10
votes
1answer
364 views

Simulating a polygon

This code simulates a polygon (say a triangle) with a person at each vertex, every person is looking at the next adjacent vertex/person. They all start moving towards each other with a constant ...
7
votes
1answer
426 views

Quad Tree and Collision Detection Implementation

I have an implementation of a quad tree and abstract collision detection classes. The code works but looks very ugly, but I don't know what I could change to make it better. The reason I used two ...
6
votes
4answers
1k views

Rocket controller for a Unity game

I'm currently learning C# so I can make real games with Unity. This is the first C# program I've built in Unity. Essentially what is does is control the thrust, and rotation of a ...
17
votes
1answer
1k views

Asteroids game clone

I have recently been teaching a JavaScript module on a games programming undergraduate course and I made this game as a learning exercise and as an example for my students to study. I have made games ...