initial commit of particle cloud classes

This commit is contained in:
2026-04-29 19:17:22 -05:00
parent eef18c8734
commit 818a403bf9
3 changed files with 49 additions and 0 deletions

13
pyproject.toml Normal file
View File

@@ -0,0 +1,13 @@
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[project]
name = "particle-cloud"
version = "0.0.1"
description = "particle cloud computations"
requires-python = ">=3.10"
dependencies = []
[tool.setuptools.packages.find]
where = ["src"]

View File

@@ -0,0 +1,3 @@
from .stuff import Particle, cloud
__all__ = ["Particle", "cloud"]

View File

@@ -0,0 +1,33 @@
class Particle:
def __init__(self, mass=1.0, velocity=None, position=None):
self.mass = mass
self.velocity = list(velocity if velocity is not None else [0.0, 0.0, 0.0])
self.position = list(position if position is not None else [0.0, 0.0, 0.0])
def __repr__(self):
return f"Particle(mass={self.mass}, velocity={self.velocity}, position={self.position})"
class cloud:
def __init__(self, particles=None):
self.particles = list(particles or [])
def add(self, p):
self.particles.append(p)
def step(self, dt=1.0):
for p in self.particles:
p.position = [x + v * dt for x, v in zip(p.position, p.velocity)]
return self
def center(self):
total = sum(p.mass for p in self.particles)
if total == 0:
return [0.0, 0.0, 0.0]
answer = [0.0, 0.0, 0.0]
for p in self.particles:
answer = [a + p.mass * x for a, x in zip(answer, p.position)]
return [x / total for x in answer]
def __repr__(self):
return f"cloud({self.particles})"