Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    ‘Less pitching, more listening’: What Amazon is really doing at CES

    The definitive Digiday guide to what’s in and out for advertising in 2026

    Omnicom Media kicks off CES with a Google search partner that drills deeper into intent

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      A new pope, political shake-ups and celebs in space: The 2025-in-review news quiz

      December 31, 2025

      AI has become the norm for students. Teachers are playing catch-up.

      December 23, 2025

      Trump signs executive order seeking to ban states from regulating AI companies

      December 13, 2025

      Apple’s AI chief abruptly steps down

      December 3, 2025

      The issue that’s scrambling both parties: From the Politics Desk

      December 3, 2025
    • Business

      Top 10 cloud computing stories of 2025

      December 22, 2025

      Saudia Arabia’s STC commits to five-year network upgrade programme with Ericsson

      December 18, 2025

      Zeroday Cloud hacking event awards $320,0000 for 11 zero days

      December 18, 2025

      Amazon: Ongoing cryptomining campaign uses hacked AWS accounts

      December 18, 2025

      Want to back up your iPhone securely without paying the Apple tax? There’s a hack for that, but it isn’t for everyone… yet

      December 16, 2025
    • Crypto

      Aave Price Jumps Amid Revenue Sharing Plans With Token Holders

      January 3, 2026

      Grayscale Predicts Bitcoin Will Reach New All-Time High by March 2026

      January 3, 2026

      Tom Lee Pushes for Big Share Increase as BitMine Closely Tracks Ethereum Price

      January 3, 2026

      Bitfinex Hacker Out of Prison After a Year Due to President Trump’s First Step Act

      January 3, 2026

      Will 2026 Deliver an Extreme Crypto Bear Market? Experts Weigh In

      January 3, 2026
    • Technology

      ‘Less pitching, more listening’: What Amazon is really doing at CES

      January 5, 2026

      The definitive Digiday guide to what’s in and out for advertising in 2026

      January 5, 2026

      Omnicom Media kicks off CES with a Google search partner that drills deeper into intent

      January 5, 2026

      The accidental guardian: How Cloudflare’s Matthew Prince became publishing’s unexpected defender

      January 5, 2026

      The AI hype cycle is rewriting ad tech’s M&A math

      January 5, 2026
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Particle Based Physics Engine in Golang
    Technology

    Particle Based Physics Engine in Golang

    TechAiVerseBy TechAiVerseMarch 20, 2025No Comments2 Mins Read14 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Particle Based Physics Engine in Golang
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Particle Based Physics Engine in Golang

    Physix.go

    A Simple Physics Engine in GoLang ☻

    Introduction

    Physix.go is a simple, easy-to-use, and fast physics engine written in GoLang. It provides functions to perform physics calculations efficiently, including particle-based physics simulations.

    Features

    • Vector Calculations
    • Physics Calculations
    • Spring Dynamics
    • Easy to use with Ebiten.go

    Getting Started

    Prerequisites

    • GoLang must be installed.
    • Ebiten must be installed.

    Installation

    To start, clone this project:

    git clone https://github.com/rudransh61/Physix.go

    Or install it using go get:

    go get github.com/rudransh61/Physix.go

    Then run the example files from the ./examples folder. For example:

    go run ./examples/ex4.go # which is a simple circular motion

    Documentation

    Vectors

    Vectors are a datatype to store vectors. Import the following file to use vectors:

    package main 
    
    import (
      //...other imports
      "github.com/rudransh61/Physix-go/pkg/vector"
    )

    To make a vector

    var MyVector = vector.Vector{X: 30, Y: 20}
    // X is the x component and Y is the y component of the Vector

    Using Function

    var NewVec = vector.NewVector(x, y)

    Add Vector

    var NewVector = Vec1.Add(Vec2)

    Subtract Vector

    var NewVector = Vec1.Sub(Vec2)

    Inner Product of 2 Vectors

    var DotProduct = Vec1.InnerProduct(Vec2)

    Scale a Vector by a scalar

    var ScaledVector = Vec1.Scale(num)

    Magnitude of a Vector

    var Magnitude = Vec1.Magnitude()

    Normalize a Vector

    var NormalizeVector = Vec1.Normalize()

    Distance between Heads of 2 Vectors

    var distance = vector.Distance(Vec1, Vec2)

    Perpendicular Vector of a given Vector

    var Orthogonal_Vector = vector.Orthogonal(Vec1)

    RigidBody

    To create an instance of RigidBody, you need to provide all the required fields. First, import these files:

    import (
      "github.com/rudransh61/Physix-go/dynamics/physics"
      "github.com/rudransh61/Physix-go/pkg/rigidbody"
    )

    Example:

    ball = &rigidbody.RigidBody{
    	Position:  vector.Vector{X: 400, Y: 100},
    	Velocity:  vector.Vector{X: 0, Y: 2},
    	Mass:      1,
    	Force:     vector.Vector{X: 0, Y: 5},
    	IsMovable: true,
    	Shape:     "Circle", // Example shape
    	Radius:    10,       // Required for Circle
    }

    To update the position of a RigidBody, use ApplyForce in a loop:

    for i := 0; i < 100; i++ {
        physix.ApplyForce(ball, vector.Vector{X: 10, Y: 0}, dt) // Apply force
        // .. other code
    }

    To access or change the Force, Velocity, Position:

    ball.Velocity // Get the velocity of the ball as a vector.Vector
    ball.Position.X += 5 // Increase the position of the ball in X direction by 5

    Collision Detection

    There are two types of collision systems for different shapes:

    • Rectangle-Rectangle collision
    • Circle-Circle collision

    Rectangle Collision

    For example, you have two Rectangles:

    rect1 = &rigidbody.RigidBody{
    	Position: vector.Vector{X: 100, Y: 200},
    	Velocity: vector.Vector{X: 50, Y: -50},
    	Mass:     1.0,
    	Shape:    "Rectangle",
    	Width:    100,
    	Height:   90,
    	IsMovable: true,
    }
    rect2 = &rigidbody.RigidBody{
    	Position: vector.Vector{X: 400, Y: 300},
    	Velocity: vector.Vector{X: 60, Y: 50},
    	Mass:     2.0,
    	Shape:    "Rectangle",
    	Width:    70,
    	Height:   70,
    	IsMovable: true,
    }

    Now you want to detect collision between them:

    if collision.RectangleCollided(rect1, rect2) {
    	fmt.Println("Collided!")
    }

    And if you want to add a bounce effect in this collision according to the Momentum Conservation and Energy Conservation:

    if collision.RectangleCollided(rect1, rect2) {
    	float64 e = 0.9999999999; // e is the coefficient of restitution in collision
    	collision.BounceOnCollision(rect1, rect2, e) // NOTE: e<1 is a bit glitchy and goes wild, use it at your own risk :)
    }

    Circle Collision

    Now if you want to detect collisions between a circle and a circle:

    if collision.CircleCollided(rect1, rect2) {
    	fmt.Println("Collided!")
    }

    And use the same BounceOnCollision function for bouncing.

    Springs

    Springs can be used to simulate elastic connections between rigid bodies. To create a spring, you need to define two rigid bodies and specify the spring’s stiffness and damping properties.

    Example:

    spring := spring.NewSpring(ballA, ballB, stiffness, damping)

    To apply the spring force in your simulation loop:

    This will apply the forces based on Hooke’s Law and damping to the connected rigid bodies.

    Examples

    Check examples in the ./examples folder.

    Some Dynamics

    Physics

    To update our entity, we have two functions: ApplyForce and ApplyForcePolygon, as the name suggests, one is for RigidBody and one for polygons.

    This function will move one frame forward or ‘dt’ time forward (which is the time between two frames).

    NOTE: Define dt (0.1 mostly) at the top globally for good code.

    ball = &rigidbody.RigidBody{
    	Position: vector.Vector{X: 400, Y: 100},
    	Velocity: vector.Vector{X: 0, Y: 2},
    	Mass:     1,
    	Force:    vector.Vector{X: 0, Y: 5},
    	IsMovable: true,
    }
    
    physix.ApplyForce(ball, vector.Vector{X: 10, Y: 0}, dt) // To apply force on the rigid body

    To get both utilities in the code, import this file:

    import (
    	...
    	"github.com/rudransh61/Physix-go/dynamics/physics"
    	...
    )

    Contributing

    New contributors are welcome! If you have any doubts related to its working, you can ask us by opening an issue.

    License

    See LICENSE.md file.

    Acknowledgments

    Inspired by Coding Train – Daniel Shiffman

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleThe Last Drops of Mexico City
    Next Article Grease: An Open-Source Tool for Uncovering Hidden Vulnerabilities in Binary Code
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    ‘Less pitching, more listening’: What Amazon is really doing at CES

    January 5, 2026

    The definitive Digiday guide to what’s in and out for advertising in 2026

    January 5, 2026

    Omnicom Media kicks off CES with a Google search partner that drills deeper into intent

    January 5, 2026
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025578 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025220 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 2025121 Views

    6 Best MagSafe Phone Grips (2025), Tested and Reviewed

    April 6, 2025107 Views
    Don't Miss
    Technology January 5, 2026

    ‘Less pitching, more listening’: What Amazon is really doing at CES

    ‘Less pitching, more listening’: What Amazon is really doing at CES By Seb Joseph  • …

    The definitive Digiday guide to what’s in and out for advertising in 2026

    Omnicom Media kicks off CES with a Google search partner that drills deeper into intent

    The accidental guardian: How Cloudflare’s Matthew Prince became publishing’s unexpected defender

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    ‘Less pitching, more listening’: What Amazon is really doing at CES

    January 5, 20262 Views

    The definitive Digiday guide to what’s in and out for advertising in 2026

    January 5, 20260 Views

    Omnicom Media kicks off CES with a Google search partner that drills deeper into intent

    January 5, 20262 Views
    Most Popular

    What to Know and Where to Find Apple Intelligence Summaries on iPhone

    March 12, 20250 Views

    A Team of Female Founders Is Launching Cloud Security Tech That Could Overhaul AI Protection

    March 12, 20250 Views

    Senua’s Saga: Hellblade 2 leads BAFTA Game Awards 2025 nominations

    March 12, 20250 Views
    © 2026 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.