Close Menu

    Subscribe to Updates

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

    What's Hot

    Infinix launches NOTE 60 Series in Malaysia

    Razer’s laptop sleeve comes with MagSafe wireless charging for US$130

    Apple’s Rumoured Budget MacBook Could Arrive With Notable Feature Trade-Offs

    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

      What the polls say about how Americans are using AI

      February 27, 2026

      Tensions between the Pentagon and AI giant Anthropic reach a boiling point

      February 21, 2026

      Read the extended transcript: President Donald Trump interviewed by ‘NBC Nightly News’ anchor Tom Llamas

      February 6, 2026

      Stocks and bitcoin sink as investors dump software company shares

      February 4, 2026

      AI, crypto and Trump super PACs stash millions to spend on the midterms

      February 2, 2026
    • Business

      FCC approves the merger of cable giants Cox and Charter

      February 28, 2026

      Finding value with AI and Industry 5.0 transformation

      February 28, 2026

      How Smarsh built an AI front door for regulated industries — and drove 59% self-service adoption

      February 24, 2026

      Where MENA CIOs draw the line on AI sovereignty

      February 24, 2026

      Ex-President’s shift away from Xbox consoles to cloud gaming reportedly caused friction

      February 24, 2026
    • Crypto

      Palladium Price Approaches a Critical Turning Point

      February 28, 2026

      Trump to Takeover Cuba, Iran War Tensions Rise, Bitcoin Crashes Again

      February 28, 2026

      A 40% XRP Crash Couldn’t Shake Its Strongest Holders — Is $1.70 Still Possible?

      February 28, 2026

      Why Is the US Stock Market Down Today?

      February 28, 2026

      SoFi Becomes First US Chartered Bank to Support Solana Deposits

      February 28, 2026
    • Technology

      The compact smartphone I actually want: Xiaomi 17 in a Galaxy S26 world

      February 28, 2026

      Exciting laptop concept turns palm rest into an E ink notepad

      February 28, 2026

      AYN Thor and Odin 3 new pricing revealed, to take effect in March

      February 28, 2026

      External desktop graphics card on a mini PC, laptop or tablet? The Minisforum DEG2 makes it possible

      February 28, 2026

      Linux-based Orange Pi Neo gaming handheld delayed due to rising RAM and storage costs

      February 28, 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 Read22 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

    The compact smartphone I actually want: Xiaomi 17 in a Galaxy S26 world

    February 28, 2026

    Exciting laptop concept turns palm rest into an E ink notepad

    February 28, 2026

    AYN Thor and Odin 3 new pricing revealed, to take effect in March

    February 28, 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, 2025699 Views

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

    July 31, 2025280 Views

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

    April 14, 2025162 Views

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

    April 6, 2025124 Views
    Don't Miss
    Gadgets March 1, 2026

    Infinix launches NOTE 60 Series in Malaysia

    Infinix launches NOTE 60 Series in Malaysia Infinix has unveiled the new Infinix NOTE 60…

    Razer’s laptop sleeve comes with MagSafe wireless charging for US$130

    Apple’s Rumoured Budget MacBook Could Arrive With Notable Feature Trade-Offs

    The compact smartphone I actually want: Xiaomi 17 in a Galaxy S26 world

    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

    Infinix launches NOTE 60 Series in Malaysia

    March 1, 20262 Views

    Razer’s laptop sleeve comes with MagSafe wireless charging for US$130

    March 1, 20262 Views

    Apple’s Rumoured Budget MacBook Could Arrive With Notable Feature Trade-Offs

    March 1, 20262 Views
    Most Popular

    7 Best Kids Bikes (2025): Mountain, Balance, Pedal, Coaster

    March 13, 20250 Views

    VTOMAN FlashSpeed 1500: Plenty Of Power For All Your Gear

    March 13, 20250 Views

    Best TV Antenna of 2025

    March 13, 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.