Close Menu

    Subscribe to Updates

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

    What's Hot

    OpenAI debuts GPT‑5.1-Codex-Max coding model and it already completed a 24-hour task internally

    The Google Search of AI agents? Fetch launches ASI:One and Business tier for new era of non-human web

    OpenCV founders launch AI video startup to take on OpenAI and Google

    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

      Insurance companies are trying to avoid big payouts by making AI safer

      November 19, 2025

      State and local opposition to new data centers is gaining steam, study shows

      November 15, 2025

      Amazon to lay off 14,000 corporate employees

      October 29, 2025

      Elon Musk launches Grokipedia as an alternative to ‘woke’ Wikipedia

      October 29, 2025

      Fears of an AI bubble are growing, but some on Wall Street aren’t worried just yet

      October 18, 2025
    • Business

      Windows 11 gets new Cloud Rebuild, Point-in-Time Restore tools

      November 18, 2025

      Government faces questions about why US AWS outage disrupted UK tax office and banking firms

      October 23, 2025

      Amazon’s AWS outage knocked services like Alexa, Snapchat, Fortnite, Venmo and more offline

      October 21, 2025

      SAP ECC customers bet on composable ERP to avoid upgrading

      October 18, 2025

      Revenue generated by neoclouds expected to exceed $23bn in 2025, predicts Synergy

      October 15, 2025
    • Crypto

      Nvidia Posts $57B Record Revenue with Bitcoin Rebounding Above $91K

      November 20, 2025

      3 Reasons Why A Cardano Price Rebound Looks Likely

      November 20, 2025

      BitMine (BMNR) Stock Bounces As Q4 Results Near — Is the Price Preparing Another Early Move?

      November 20, 2025

      Fed Minutes Reveal December Rate Cut on a Knife’s Edge, Bitcoin Slips Below $89,000

      November 20, 2025

      TRUMP Price Holds Above $7, Even As Epstein Files Release Approved

      November 20, 2025
    • Technology

      OpenAI debuts GPT‑5.1-Codex-Max coding model and it already completed a 24-hour task internally

      November 20, 2025

      The Google Search of AI agents? Fetch launches ASI:One and Business tier for new era of non-human web

      November 20, 2025

      OpenCV founders launch AI video startup to take on OpenAI and Google

      November 20, 2025

      VentureBeat launches “Beyond the Pilot” — a new podcast series exploring how enterprise AI gets real

      November 20, 2025

      Meta’s DreamGym framework trains AI agents in a simulated world to cut reinforcement learning costs

      November 20, 2025
    • 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 Read10 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

    OpenAI debuts GPT‑5.1-Codex-Max coding model and it already completed a 24-hour task internally

    November 20, 2025

    The Google Search of AI agents? Fetch launches ASI:One and Business tier for new era of non-human web

    November 20, 2025

    OpenCV founders launch AI video startup to take on OpenAI and Google

    November 20, 2025
    Leave A Reply Cancel Reply

    Top Posts

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

    April 22, 2025410 Views

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

    July 31, 2025109 Views

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

    April 14, 202575 Views

    Is Libby Compatible With Kobo E-Readers?

    March 31, 202555 Views
    Don't Miss
    Technology November 20, 2025

    OpenAI debuts GPT‑5.1-Codex-Max coding model and it already completed a 24-hour task internally

    OpenAI debuts GPT‑5.1-Codex-Max coding model and it already completed a 24-hour task internally Vercel Security…

    The Google Search of AI agents? Fetch launches ASI:One and Business tier for new era of non-human web

    OpenCV founders launch AI video startup to take on OpenAI and Google

    VentureBeat launches “Beyond the Pilot” — a new podcast series exploring how enterprise AI gets real

    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

    OpenAI debuts GPT‑5.1-Codex-Max coding model and it already completed a 24-hour task internally

    November 20, 20251 Views

    The Google Search of AI agents? Fetch launches ASI:One and Business tier for new era of non-human web

    November 20, 20251 Views

    OpenCV founders launch AI video startup to take on OpenAI and Google

    November 20, 20250 Views
    Most Popular

    Xiaomi 15 Ultra Officially Launched in China, Malaysia launch to follow after global event

    March 12, 20250 Views

    Apple thinks people won’t use MagSafe on iPhone 16e

    March 12, 20250 Views

    French Apex Legends voice cast refuses contracts over “unacceptable” AI clause

    March 12, 20250 Views
    © 2025 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.