Questions tagged [physics]

Refers to real-world physics. For simulation of physics in games use the [game-physics] tag instead, for questions using an existing physics engine use [physics-engine]. Physics is a science that studies the interactions of energy and matter. Questions with this tag concern the simulation or implementation of real-world physics concepts in programming.

The physics tag should be used for questions about how physics can be simulated or implemented in programming. Please ask questions about physics in a non-programming context on the Physics site. Also consider that questions specific to a simplified or approximate physics engine for use in games might receive better answers if asked on Game Development.

3476 questions
28
votes
10 answers

Broad-phase collision detection methods?

I'm building a 2D physics engine and I want to add broad-phase collision detection, though I only know of 2 or 3 types: Check everything against everything else (O(n^2) complexity) Sweep and Prune (sort and sweep) something about Binary Space…
RCIX
  • 38,647
  • 50
  • 150
  • 207
25
votes
5 answers

2D Spaceship movement math

I'm trying to make a top-down spaceship game and I want the movement to somewhat realistic. 360 degrees with inertia, gravity, etc. My problem is I can make the ship move 360° with inertia with no problem, but what I need to do is impose a limit for…
YAS
  • 363
  • 2
  • 6
  • 9
25
votes
3 answers

Why is Verlet integration better than Euler integration?

Can someone explain to me why Verlet integration is better than Euler integration? And why RK4 is better than Verlet? I don't understand why it is a better method.
22
votes
4 answers

Prevent force-dragging bodies through other bodies with MatterJS

I'm using MatterJs for a physics based game and have not found a solution for the problem of preventing bodies being force-dragged by the mouse through other bodies. If you drag a body into another body, the body being dragged can force itself into…
d13
  • 9,817
  • 12
  • 36
  • 44
21
votes
14 answers

Can my loop be optimized any more?

Below is my innermost loop that's run several thousand times, with input sizes of 20 - 1000 or more. This piece of code takes up 99 - 99.5% of execution time. Is there anything I can do to help squeeze any more performance out of this? I'm not…
Mike Bailey
  • 12,479
  • 14
  • 66
  • 123
21
votes
7 answers

iOS 7 Sprite Kit freeing up memory

I am building an iOS game aimed for the new iOS 7 and Sprite Kit, using emitter nodes and physics to enhance gameplay. While developing the app, I ran into a serious problem: you create your scenes, nodes, effects, but when you are done and need to…
Lehel Medves
  • 527
  • 1
  • 5
  • 15
21
votes
5 answers

Meaning of "LSB/Unit" and "Unit/LSB"

At the moment I'm playing with the LSM303DLHC accelerometer/magnetometer/thermometer. This is its datasheet: http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00027543.pdf Everything is working quite well, but I…
Genesis Rock
  • 707
  • 2
  • 5
  • 16
21
votes
5 answers

Calculate the position of an accelerating body after a certain time

How do I calculate the position of an accelerating body (e.g. a car) after a certain time (e.g. 1 second)? For a moving body that it not accelerating, it is a linear relationship, so I presume for an accelerating body it involves a square…
Iain
  • 9,432
  • 11
  • 47
  • 64
21
votes
4 answers

Is there a standard pythonic way to treat physical units / quantities in python?

Is there a standard pythonic way to treat physical units / quantities in python? I saw different module-specific solutions from different fields like physics or neuroscience. But I would rather like to use a standard method than "island"-solutions…
Philipp der Rautenberg
  • 2,212
  • 3
  • 25
  • 39
21
votes
3 answers

Javascript physics engine and simulated infinite curve

I'm trying to do a Tiny Wings like in javascript. I first saw a technique using Box2D, I'm using the closure-web version (because of the memory leaks fix). In short, I explode the curve into polygons so it looks like that: I also tried with…
SuperSkunk
  • 1,268
  • 12
  • 24
20
votes
6 answers

Bullet vs Newton Game Dynamics vs ODE physics engines

I am trying to pick a physics engine for a simple software application. It would be to simulate a rather small number of objects so performance isn't a huge concern. I am mostly concerned with the accuracy of the motion involved. I would also…
Anon
  • 5,103
  • 11
  • 45
  • 58
20
votes
2 answers

How can I get the direction of movement using an accelerometer?

I'm developing a Android application and I would like to know if is possible detect the direction of movement with one axis fixed. For example, I want put my phone on the table and detect the direction when I move it (left, right, up and down). The…
Marcos Passos
  • 400
  • 1
  • 3
  • 15
19
votes
2 answers

Bullet Physics - Apply Torque Impulse in Body's Local Space

I'm currently evaluating the Bullet Physics Library for a 3D space game I'm writing using C++ and Ogre3D. I've gotten Ogre3D and Bullet integrated nicely by deriving from btMotionState and plugging in my SceneNodes, but now I'm having a lot of…
Lusid
  • 4,518
  • 1
  • 24
  • 24
18
votes
2 answers

Is catastrophic cancellation an issue when calculating dot products of floating point vectors? And if so, how is it typically addressed?

I am writing a physics simulator in C++ and am concerned about robustness. I've read that catastrophic cancellation can occur in floating point arithmetic when the difference of two numbers of almost equal magnitude is calculated. It occurred to me…
Nick Kovac
  • 487
  • 3
  • 10
18
votes
5 answers

Pong physics problem

I have problem but I don't know how to describe it so I have drawn it. As you can see ball bounces when collision is detected. Nevermind the angle - I have just drawn it that way. But sometimes ball goes through the paddle leaving it other way. Why…
zarcel
  • 1,211
  • 2
  • 16
  • 35