SPhysics 0.2.0

dotnet add package SPhysics --version 0.2.0
                    
NuGet\Install-Package SPhysics -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SPhysics" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SPhysics" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SPhysics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SPhysics --version 0.2.0
                    
#r "nuget: SPhysics, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SPhysics@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SPhysics&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SPhysics&version=0.2.0
                    
Install as a Cake Tool

<p align="center"> <img src="src/code/SPhysics/icon.png" alt="SPhysics" width="50"/> </p>

SPhysics

GitHub repo size GitHub code size Nuget
Build Code Analysis Code Lint

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 44 8/5/2026
0.1.0 282 3/8/2025