SPhysics 0.2.0
dotnet add package SPhysics --version 0.2.0
NuGet\Install-Package SPhysics -Version 0.2.0
<PackageReference Include="SPhysics" Version="0.2.0" />
<PackageVersion Include="SPhysics" Version="0.2.0" />
<PackageReference Include="SPhysics" />
paket add SPhysics --version 0.2.0
#r "nuget: SPhysics, 0.2.0"
#:package SPhysics@0.2.0
#addin nuget:?package=SPhysics&version=0.2.0
#tool nuget:?package=SPhysics&version=0.2.0
<p align="center"> <img src="src/code/SPhysics/icon.png" alt="SPhysics" width="50"/> </p>
SPhysics
Physics for .NET, written against
generic math.
Every formula is generic over the numeric type, so the same call site works for double,
float, decimal or Half without overloads or casting. Builds on top of
SMath.
Design
Generic over the number type. Constraints express the physics rather than a concrete
type: a formula needing a square root asks for IRootFunctions<N>, one needing only
addition asks for INumberBase<N>. Passing a type that cannot support the operation is a
compile error.
Static and allocation free. There are no wrapper structs for quantities or vectors. Values are plain scalars and tuples, so they stay on the stack and interoperate with any other library. All entry points are static.
Names that read as the formula. Types are named after the quantity being computed,
giving call sites like GravitationalForce.Outside(m1, m2, r) or
KineticEnergy.Linear(m, v).
Contents
| Area | Types |
|---|---|
| Base quantities | Length, Mass, Time, ElectricCurrent, Temperature, AmountOfSubstance, LuminousIntensity |
| Mechanics | Velocity, Acceleration, Momentum, AngularMomentum, AngularVelocity, Impulse, Force, FrictionForce, DragForce, MomentOfInertia, CenterOfMass, CenterOfGravity |
| Energy & Power | Energy, KineticEnergy, PotencialEnergy, GravitationalEnergy, Power |
| Gravitation | Gravity, GravitationalForce, GravitationalIntensity, GravitationalPotential |
| Celestial mechanics | Barycenter, EscapeVelocity, MeanAnomaly, MeanMotion, OrbitalEccentricity, OrbitalPeriod, TrueAnomaly |
| Other | Density, Distance, Frequency, Pressure, AbsorbedDose |
Setup
<PackageReference Include="SPhysics" Version="X.X.X" />
Replace X.X.X with the current version from NuGet.
The package targets net7.0 and runs on any newer runtime.
Usage
Gravitation, with the numeric type inferred from the arguments:
using SPhysics;
using SPhysics.CelestialMechanics;
const double G = 6.67430e-11;
// Newton's law of universal gravitation between two point bodies
var force = GravitationalForce.Outside(mass1: 5.972e24, mass2: 7.342e22, distance: 3.844e8);
// Escape velocity from a spherically symmetric body of given mass and radius
var vEsc = EscapeVelocity.Eval(mass: 5.972e24, distance: 6.371e6, gravitationalConstant: G);
Energy and motion:
using SPhysics;
// Linear kinetic energy
var keLinear = KineticEnergy.Linear(mass: 1.5, velocity: 12.0);
// Spinning kinetic energy
var keSpin = KineticEnergy.Spinning(momentOfInertia: 0.4, angularVelocity: 3.0);
// Gravitational potential energy between two bodies
var epg = GravitationalEnergy.Eval(mass1: 5.972e24, mass2: 1.5, distance: 6.371e6);
N-body force accumulation into a stack allocated span:
using SPhysics;
const double G = 6.67430e-11;
Span<(double X, double Y, double Mass)> bodies = stackalloc (double, double, double)[]
{
(0, 0, 5.972e24),
(3.844e8, 0, 7.342e22),
(1.496e11, 0, 1.989e30),
};
var (fx, fy) = GravitationalForce.Eval<double>(bodies, index: 0, gravitationConst: G);
Contributing
Ideas, bug reports and pull requests are welcome. Open an issue to propose a change, or send a pull request directly.
License
Project is under MIT license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- SMath (>= 0.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.