/r/PhysicsEngine

Photograph via snooOG

A physics engines are computer software that provides an approximate simulation of certain physical systems, such as rigid body dynamics (including collision detection), soft body dynamics, and fluid dynamics, which are used in the computer graphics, video games and movies.

we are here to show you those amazing simulations

A physics engine is computer software that provides an approximate simulation of certain physical systems, such as rigid body dynamics (including collision detection), soft body dynamics, and fluid dynamics, of use in the domains of computer graphics, video games and film.



Post all the Physics Simulations you like!



HOW TO MAKE THESE SIMULATIONS ?

There are many physics engines available on the internet, and ultimately you might decide to use something else, but a good place to start is by using Blender.

Blender is a free and open source 3D creation suite which can do physics. Blender is highly capable (in fact a lot of the videos on this subreddit are made in blender), and there are many tutorials avalible for it (both for blender in general and physics specifically).

/r/PhysicsEngine

3,446 Subscribers

1

ET down

I am a highschooler working on an astrophysics project and I think Einstein Toolkit would be a great asset to my project as it would help me make useful simulations. Unfortunately, Einstein Toolkit is temporarily down. Does anybody know how long it'll take for ET to be usable again? Also, is it still possible to download Einstein toolkit on my pc without actually having to go to the website?

0 Comments
2024/11/30
14:30 UTC

5

Accurate multibody simulation methods?

Hi there. I want to develop a physics engine for an artificial life system, similar to the seminal work by Karl Sims. I have a master's degree in artificial life, so that aspect is no problem, it's the physics engine I am concerned most about.

Of course I want it to be as fast as possible, but since it is for an offline process, it doesn't need to be realtime. That is, speed and efficiency are much less important than precision and portability/determinism, specifically with regards to energy conservation.

Sims' system used Featherstone's reduced coordinate algorithm, with Runge-Kutta-Fehlberg (fourth order) integration. But that was 30 years ago. Is it still a good way to go? Are there better approaches? Position based systems are newer, but as far as I understand, they eschew precision for speed, for realtime systems like games, right?

My question is, which approach would you take? Which papers, open source projects, videos, or articles do you think I should look at? What are the issues that will become important?

Also, please don't say "just use an existing engine." This is a hobby project for me to learn more about implementing physics engines. I am not new to physics engine development, but I am no expert either. I have created a variety of engines in the past (rigid and soft), but that was a while ago, and my programming ability is much better than my maths skills.

Thanks!

2 Comments
2024/11/09
01:19 UTC

3

Where to start with a basic physics engine?

Hi all, I was recently looking into how to add basic physics to a small 3D graphics engine I have so I can start making a small game in it. I was wondering if anybody has any tips on where to start with this. More specifically, I am kind of looking at making it on my own to learn about how a basic physics engine might work. I'm not opposed to using a library, I just want to learn how it works under the hood first.

Over the past few days I've been looking into space partitioning (BSPs, Octrees). Is this a good place to start or should I be looking at something else? I don't plan on making anything too complex, but I would like to have a player that walks around and can collide with other game objects.

If space partitioning is the way to go, where do I go from there? I get the ideas of how to code them, but the actual practical use of how this helps with collisions is still a bit lost on me. I understand that you want to only check things that are close to each other but I still don't know how to do the actual collision check. Is AABB good enough for stuff like this or is there a better way to check for collisions when objects aren't necessarily aligned with an axis? Not to mention, what happens when an object covers the entire map (like a plane)?

I don't necessarily need answers for each of these questions, just a general idea of where to go to learn about and figure them out myself (Although if you do want to give an answer to one of the specific questions please feel free).

Any advice would be very helpful, thanks.

1 Comment
2024/09/25
02:39 UTC

5

How to actually go about making an engine

So, I'm in the process of understanding how a 2d physics engine works. I understand how axis-aligned bounding boxes work and the separating axis theorem, as well as impulse resolution. As of now, the math seems not too complicated (although i'm sure it will be in the future). However, what I don't get is how do I actually make a simulation. Like a visible window on my computer with the AABBs and all that? Can somebody link some tutorials on how to actually program one?

1 Comment
2024/09/09
12:56 UTC

3

How does a 2D physics engine work?

Hi I was wondering how a physics engine works and found Box2D but no good explanation how this works. So I decided to delve deeper into the topic and create a tutorial for this:

https://github.com/XMAMan/SmallSI

Can you please give me feedback on whether the explanation is understandable?

0 Comments
2024/08/27
04:22 UTC

1

An Introduction to collision detection

2 Comments
2024/08/21
09:07 UTC

1

Research

Can engineers get into space research? Or is a physics degree a more beneficial option?

0 Comments
2024/07/10
18:49 UTC

4

Time

Is there a timing involved between spin and when TORQUE initiates or not? Is torque instantaneous to spin?

2 Comments
2024/07/06
20:33 UTC

3

Rigidbody sliding off when distance between other rigidbody is greater than zero

Hey! I'm trying to make a physics engine in C++ and I have a rigidbody script and a function for resolving collisions. But when the distance between one rigidbody and another becomes slightly larger, the rigidbody with less mass just slides off. I do not want this ofcourse. Please help me. This is my function for resolving collisions:
void ResolveCollisionsIgnoreFirst(Rigidbody& boxRigidbody, Rigidbody& rigidbody)

void ResolveCollisions(Rigidbody& rigidbody, Rigidbody& boxRigidbody)
{
    float distance = glm::distance(rigidbody.getPosition(), boxRigidbody.getPosition());
    std::cout << distance;

    // Calculate minimum penetration depth based on combined radius/bounding box half size
    float minimumPenetrationDepth = rigidbody.getMass() + boxRigidbody.getMass();

    if (distance - minimumPenetrationDepth <= 0.01f)
    {
        glm::vec3 collisionNormal = glm::normalize(rigidbody.getPosition() - boxRigidbody.getPosition());

        // Calculate relative velocity
        glm::vec3 relativeVelocity = rigidbody.getVelocity() - boxRigidbody.getVelocity();
        float relativeVelocityNormal = glm::dot(relativeVelocity, collisionNormal);

        float restitution = 0.1f; // Adjust the coefficient as needed

        // Calculate impulse magnitude for normal direction
        float j = -(1 + restitution) * relativeVelocityNormal;
        j /= 1 / rigidbody.getMass() + 1 / boxRigidbody.getMass();

        // Apply impulse for normal direction
        glm::vec3 impulse = j * collisionNormal;

        // Update velocities for normal direction
        rigidbody.setVelocity(rigidbody.getVelocity() + impulse / rigidbody.getMass());

        // Resolve penetration
        (rigidbody.getMass() + boxRigidbody.getMass()); // Use combined mass for center of mass calculation
        const float percent = 0.2f; // Penetration percentage to correct
        const float slop = 0.1f; // Allowance to prevent jittering
        float penetrationDepth = calculatePenetrationDepth(rigidbody, boxRigidbody);
        glm::vec3 desiredDistance =
            0.5f * (rigidbody.getBoundingBoxMax() - rigidbody.getBoundingBoxMin()) +
            0.5f * (boxRigidbody.getBoundingBoxMax() - boxRigidbody.getBoundingBoxMin());; // Calculate desired non-penetration distance (e.g., sum of bounding box half sizes)
        float desiredDistanceMagnitude = glm::length(desiredDistance);
        float penetrationDepthBruh = desiredDistanceMagnitude - distance;

        if (penetrationDepthBruh > slop) {
            glm::vec3 correction = penetrationDepth * collisionNormal;
            rigidbody.setPosition(rigidbody.getPosition() + correction);
        }

        // Calculate relative velocity in the direction of the tangent (friction)
        glm::vec3 relativeVelocityTangent = relativeVelocity - (glm::dot(relativeVelocity, collisionNormal) * collisionNormal);
        float relativeVelocityTangentMagnitude = glm::length(relativeVelocityTangent);

        // Calculate friction coefficient
        float staticFrictionThreshold = 0.001f;
        float frictionCoefficient = 0.1f;

        // Apply friction impulse if there's relative tangential velocity
        if (relativeVelocityTangentMagnitude < staticFrictionThreshold) {
            // If relative tangential velocity is low, apply static friction to prevent sliding
            // Calculate static friction impulse
            glm::vec3 staticFrictionImpulseA = -relativeVelocityTangent * rigidbody.getMass(); // Opposes motion
            glm::vec3 staticFrictionImpulseB = -relativeVelocityTangent * boxRigidbody.getMass(); // Opposes motion

            // Apply static friction impulse
            rigidbody.setVelocity(rigidbody.getVelocity() + staticFrictionImpulseA / rigidbody.getMass());
        }
        else {
            // If relative tangential velocity is high, apply dynamic friction
            // Calculate friction coefficient
            float frictionCoefficient = 0.1f; // Adjust as needed

            // Apply friction impulse if there's relative tangential velocity
            // Calculate impulse magnitude for friction
            float frictionImpulseMagnitude = frictionCoefficient * j;

            // Clamp friction impulse magnitude to prevent reversal of relative motion
            frictionImpulseMagnitude = std::min(frictionImpulseMagnitude, relativeVelocityTangentMagnitude);

            // Calculate friction impulse vector
            glm::vec3 frictionImpulse = glm::normalize(relativeVelocityTangent) * frictionImpulseMagnitude;

            // Apply friction impulse
            rigidbody.setVelocity(rigidbody.getVelocity() - frictionImpulse / rigidbody.getMass());
        }

        // Calculate angular velocity change due to collision
        glm::vec3 rA = rigidbody.getPosition() - boxRigidbody.getPosition();
        glm::vec3 rB = boxRigidbody.getPosition() - rigidbody.getPosition();
        glm::vec3 angularVelocityChangeA = glm::cross(rA, impulse) / rigidbody.getMass();
        glm::vec3 angularVelocityChangeB = glm::cross(rB, -impulse) / boxRigidbody.getMass();

        // Apply angular velocity change
        rigidbody.setRotation(rigidbody.getRotation() + angularVelocityChangeA);
    }
}

And if you were wondering, this is my rigidbody script: https://pastebin.com/uayq9zE5

2 Comments
2024/05/17
20:26 UTC

3

Looking for a (Master's?) thesis from over 20 years ago regarding the physical simulation of a frog

0 Comments
2024/05/13
08:39 UTC

1

What would happen realistically if a planet like Jupiter, Saturn, Uranus, and/or Neptune where to be shrunken in a similar manner to how Hank Pym shrinks things in Marvel

What would happen if Jupiter, Saturn, Uranus, and/or Neptune were to be condensed to the volume of earth or our moon, while maintaining its mass, gravitational field, and internal and external rotation, in exchange for amplifying its density & magnetic field?

(Bonus question Ie: What would happen if nothing but the volume of earth plus those and that within where to be be shrunken?)

2 Comments
2024/05/12
13:28 UTC

4

4-bit ALU made with mechanical switches in physics sandbox

0 Comments
2024/04/10
00:58 UTC

5

Fill volumes

I am trying to figure out how to determine the fill level of an arbitrarily oriented container (a fairly arbitrary shape) . I could use Unity's physics engine if I need to (though I wouldn't know how for this particular problem), but I was really hoping to do so directly in code. I don't need a full example, pointers would be great though.

4 Comments
2024/02/21
10:36 UTC

3

4 bit mechanical adder circuit

0 Comments
2024/01/28
16:28 UTC

4

Robotics physics engines

Hi, i am wondering what are the differences/ pros and cons of different simulators that are often used to simulate articulated bodies . The main ones that come to mind are Pybullet, Raisim, mujoco and Isaac.

1 Comment
2023/11/02
01:46 UTC

8

Ryukyu Robots - simulating Karate and Kobudo

I have been a Karate and Kobudo practitioner for 25 years and my wish to simulate fighting got me into programming and physics engines. I have been working on my project, Ryukyu Robots, for three years by now. As I am taking a break from unarmed combat, I have redirected my interest to staff fighting, bojutsu. It's still in its infancy. But I wanted to show my current progress - with its flaws. I am using pyBullet and mostly love it.

0 Comments
2023/10/17
21:10 UTC

3

What are the Pros and Cons of Unreal's Physics Engine and Gazebo's Physics engine ?

I know that Unreal uses PhyX physics engine and Gazebo used by Default ODF or Bullet. I would like to know the pros and cons of both of them.

0 Comments
2023/10/17
09:57 UTC

3

Lennard-Jones Particle Engine

0 Comments
2023/10/13
00:19 UTC

6

Help, I just can't understand constraints

I have been trying to learn how to write a simple physics engine, and have a few rigid bodies moving around under the control of forces. I understand the basics of integrating accelerations and velocities, and applying forces and impulses to rigid bodies.

But I just don't get constraints. I can't find resources for implementing simple constraints. I've glanced at some open source engines but they are well beyond me. When I try to search of information about constraints, it's either simplistic tutorials for bouncing rotationless particles off walls or each other, or people talking about how to use constraints in an existing physics engine, or extremely abstract mathematical concepts that I can't relate to the application.

Currently I am trying to make a simple position constraint between two 2D rigid bodies. That's all. Like a hinge on a ragdoll. I understand what 'satisfy the constraint' means in terms of the desired behaviour, but I can't picture it with regards to what the actual code needs to do. Do I have to work out impulses that nullify the separating velocity AND pull the joint together in the next time step? I just can't seem to grasp or visualise what's needed.

I used equations from Chris Hecker's brilliant 4-part tutorial to get rigid body collision response working, but I don't understand how to go from there to a hinge. I suspect it's simple, but it's beyond my understanding.

Sorry, I know this is a fairly basic question, but I'd really appreciate it if someone could explain the concept of solving constraints in English, without immediately diving into energy functions and Jacobians and Lagrange multipliers. My mathematics is much weaker than my programming skills. I'd love to learn more mathematics related to this topic, but I need to know what it is I'm trying to achieve.

Is there someone out there who'd be willing to field a few basic(ish) questions about solving physics systems?

6 Comments
2023/10/02
06:57 UTC

5

idea for an overlap-based physics engine see this simple 2D example with rigid obj. section of border that's within another shape will act as thruster(exert force perpendicularly) can go thru each other if enter with such fierce momentum as to convert into enough potential energy to stack beer mats

19 Comments
2023/09/15
11:30 UTC

14

Dynamic particle based destruction

3 Comments
2023/08/27
12:48 UTC

16

Snow simulation for a game I'm working on

4 Comments
2023/08/17
15:04 UTC

3

Hello everybody we are back in action! Who all's still here?

3 Comments
2023/08/07
23:19 UTC

4

We were working on this a long time so I thought I would share -- see comment.

4 Comments
2022/09/12
13:55 UTC

6

Just sharing something I am working on in Unity

1 Comment
2022/08/22
19:32 UTC

0

Tech assist

Panther Robotics is a middle school club here in Maryland. The students had an idea similar to reaction wheels. I have no ability to simulate it in a physics engine. If anyone would be interested in modeling it for them, we would be grateful.

0 Comments
2022/04/18
21:21 UTC

8

What program do I use for a physics engine?

Hello everyone, I am interested in coding a physics engine in either C or C++ I haven't decided yet. I want to code everything from the ground up not just use Unreal or Unity. What I don't understand is how do I go from typing code in VS Code to watching my code bounce a ball off the wall? What program would I use to turn that code into a visual simulation? Sorry if this is a dumb question.

3 Comments
2022/03/29
05:01 UTC

0

hello I was wondering if anyone could help me with an essay I have to write. I have chosen the question:To what extent can the efficiency of a cable be manipulated through optimum temperature for metals like copper, iron and aluminum based on resistance. Does anyone have any idea on how to approach

5 Comments
2022/01/14
09:48 UTC

Back To Top