Aller au contenu principal

Particle & Point

The Particle class is the fundamental building block of any simulation. The <Point> component is its declarative React counterpart.

A Particle represents a single point in space with mass.

Constructor

new Particle(pos, [mass])

  • pos (Vec2): The initial position.
  • mass (number, optional): The mass of the particle. Defaults to 1.

Example

import { Particle, Vec2 } from 'verlet-engine';

// A particle with default mass of 1
const p1 = new Particle(new Vec2(100, 100));

// A heavier particle
const p2 = new Particle(new Vec2(200, 100), 5.0);

Properties

  • pos (Vec2): The current position vector.
  • lastPos (Vec2): The position vector in the previous frame.
  • acc (Vec2): The acceleration vector, where forces are accumulated.
  • mass (number): The mass of the particle.
  • style (ParticleStyle, optional): An object for rendering style ({ radius, color, hidden }).