Building A Physics Simulation: Particle Collision

Поделиться
HTML-код
  • Опубликовано: 20 дек 2024

Комментарии • 15

  • @kinsondigital
    @kinsondigital 5 месяцев назад +3

    This is the first time that I have seen anyone use the go programming language for something like this. Great work!

  • @music.4215
    @music.4215 4 месяца назад +1

    Amazing content do not stop at all keep going bro

  • @jackyzheng55
    @jackyzheng55 5 месяцев назад

    Underrated channel.

  • @seandougherty3022
    @seandougherty3022 5 месяцев назад

    i appreciate your channel and videos. looking forward to all you bring to youtube for go :)

    • @mr_mux408
      @mr_mux408  5 месяцев назад

      I appreciate that!

  • @NaveenSiddareddy
    @NaveenSiddareddy 5 месяцев назад +1

    beautiful physics to art

    • @mr_mux408
      @mr_mux408  5 месяцев назад

      Thank you! Cheers!

  • @AndresFirte
    @AndresFirte 5 месяцев назад

    Nice video! New sub

  • @kotzblitz7716
    @kotzblitz7716 5 месяцев назад +1

    I don't need it but this is great

    • @mr_mux408
      @mr_mux408  5 месяцев назад +1

      Thanks for watching!

  • @OxyniteCasual
    @OxyniteCasual 5 месяцев назад

    tnx, really good and educating, appreciate it a lot

    • @mr_mux408
      @mr_mux408  5 месяцев назад +1

      Thank You!!!

  • @Zoro-fl2mn
    @Zoro-fl2mn 5 месяцев назад

    Is this doable in C++ or python?

    • @mr_mux408
      @mr_mux408  5 месяцев назад +1

      Certainly, why not?

  • @kvelez
    @kvelez 4 дня назад

    package main
    import "math"
    type Vector struct {
    X float64
    Y float64
    }
    // Vector operations
    func (v Vector) add(other Vector) Vector {
    return Vector{X: v.X + other.X, Y: v.Y + other.Y}
    }
    func (v Vector) subtract(other Vector) Vector {
    return Vector{X: v.X - other.X, Y: v.Y - other.Y}
    }
    func (v Vector) multiply(scalar float64) Vector {
    return Vector{X: v.X * scalar, Y: v.Y * scalar}
    }
    func (v Vector) distance(other Vector) float64 {
    dx := v.X - other.X
    dy := v.Y - other.Y
    return math.Sqrt(dx*dx + dy*dy)
    }
    func (v Vector) projection(other Vector) Vector {
    dotProduct := v.X*other.X + v.Y*other.Y
    magSquared := other.X*other.X + other.Y*other.Y
    if magSquared == 0 {
    return Vector{}
    }
    scale := dotProduct / magSquared
    return other.multiply(scale)
    }
    type Ball struct {
    r Vector
    v Vector
    mass float64
    radius float64
    }
    func (b *Ball) addGravity(level float64) {
    const pxPerM = 50
    const fps = 60
    b.v.Y += level * 9.8 / (fps * fps) * pxPerM
    }
    func (b *Ball) handleWallCollision(Cr, screenWidth, screenHeight float64) {
    if b.r.X-b.radius = screenWidth {
    b.v.X = -Cr * b.v.X
    b.r.X = screenWidth - b.radius
    }
    if b.r.Y-b.radius = screenHeight {
    b.v.Y = -Cr * b.v.Y
    b.r.Y = screenHeight - b.radius
    }
    }
    func (b *Ball) ballHitVelocity(b2 *Ball, Cr float64) Vector {
    mRatio := (Cr + 1) * b2.mass / (b.mass + b2.mass)
    vDiff := b.v.subtract(b2.v)
    rDiff := b.r.subtract(b2.r)
    proj := vDiff.projection(rDiff)
    return b.v.subtract(proj.multiply(mRatio))
    }
    func (b *Ball) isHit(b2 *Ball) bool {
    dist := b.r.distance(b2.r)
    return dist