physics

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundAttachedParticle = errors.New("not found attache particle")
)

All kind of errors

Functions

This section is empty.

Types

type Composite

type Composite struct {
	Particles   []*Particle
	Constraints []*Constraint
}

Composite describe complex object with multiple particles and constraints

func NewComposite

func NewComposite() *Composite

NewComposite create new composite

func (*Composite) AddConstraints

func (c *Composite) AddConstraints(i1, i2 int, springConstant float64) error

AddConstraints create constraint between two particles

func (*Composite) AddParticle

func (c *Composite) AddParticle(p *Particle)

AddParticle add particle

func (*Composite) GetParticle

func (c *Composite) GetParticle(i int) (*Particle, error)

GetParticle get particle by index

func (*Composite) SetMaterial

func (c *Composite) SetMaterial(material Material)

SetMaterial set material to all particles

type Constraint

type Constraint struct {
	Particle1 *Particle
	Particle2 *Particle
	Target    float64
	Stiff     float64
	Damp      float64
}

Constraint describe relation between two particles

func NewConstraint

func NewConstraint(p1, p2 *Particle, springConstant, distanceConstraint float64) *Constraint

NewConstraint return new constraint

func (*Constraint) Relax

func (c *Constraint) Relax()

Relax add relax forces

type Material

type Material struct {
	Mass float64
}

Material describe material

func NewMaterial

func NewMaterial(mass float64) Material

NewMaterial return new material

type Particle

type Particle struct {
	Material Material

	Position     shapes.Point
	Previous     shapes.Point
	Velocity     shapes.Point
	Acceleration shapes.Point
}

Particle describe particle

func NewParticle

func NewParticle(position shapes.Point, material Material) *Particle

NewParticle create new particle

func (*Particle) Accelerate

func (p *Particle) Accelerate(rate shapes.Point)

Accelerate apply acceleration

func (*Particle) ApplyForce

func (p *Particle) ApplyForce(force shapes.Point)

ApplyForce apply force

func (*Particle) ApplyImpulse

func (p *Particle) ApplyImpulse(impulse shapes.Point)

ApplyImpulse immediately change position

func (*Particle) ResetForces

func (p *Particle) ResetForces()

ResetForces reset acceleration

func (*Particle) Restrain

func (p *Particle) Restrain(border shapes.Border, dimensions int)

Restrain return particle into border on collision

func (*Particle) SetMaterial

func (p *Particle) SetMaterial(material Material)

SetMaterial set material

func (*Particle) Simulate

func (p *Particle) Simulate(worldDelta float64)

Simulate simulate world

type World

type World struct {
	shapes.Border
	Gravity    shapes.Point
	Composites []*Composite
	Step       float64
	Delta      float64 // Delta time (1.0 / time Step)
}

World describe particle world

func NewWorld

func NewWorld(border shapes.Border, gravity shapes.Point, step float64) *World

NewWorld return new world with gravity

func (*World) AddComposites

func (w *World) AddComposites(c ...*Composite)

AddComposites add composite

func (*World) Simulate

func (w *World) Simulate(steps, dimensions int)

Simulate simulate physics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL