SMath 0.9.0

dotnet add package SMath --version 0.9.0
                    
NuGet\Install-Package SMath -Version 0.9.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="SMath" Version="0.9.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SMath" Version="0.9.0" />
                    
Directory.Packages.props
<PackageReference Include="SMath" />
                    
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 SMath --version 0.9.0
                    
#r "nuget: SMath, 0.9.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.
#addin nuget:?package=SMath&version=0.9.0
                    
Install SMath as a Cake Addin
#tool nuget:?package=SMath&version=0.9.0
                    
Install SMath as a Cake Tool

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

SMath

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

Overview

SMath is a math library built on .NET 7 generic math, offering a comprehensive set of static types for working with 2D geometry and statistics.

Features

Generic Math Capabilities

Leverages .NET 7�s new generic math features, allowing type-safe mathematical operations on various numeric types.

Geometry (2D)

Handle 2D geometric computations with ease. Available types and operations include:

  • Point
    • Euclidean distance, Manhattan distance, Chebyshev distance, Minkowski distance
  • Line
    • Ray, Line Segment
    • Operations: Projection, Intersection, Inclusion
  • Circle
    • Arc, Chord, Sector, Segment
    • Operations: Perimeter, Region, Tangent Points, Inclusion
  • Rectangles
    • Vertices
    • Operations: Perimeter

Statistical Analysis

Perform basic statistical calculations:

  • Correlation
  • Variance
  • Covariance
  • Standard Deviation
  • Histograms

Setup

Add nuget package to project.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="SMath" Version="X.X.X" />
  </ItemGroup>
</Project>

Replace 'X.X.X' with the appropriate version from NuGet.

Usage

Here are some basic usage examples to get started with SMath:

Geometry: Working with Circles and Lines

// Using double precision
var line1 = Circle.TangentLine.FromAngle(radius: 5d, angle: Math.PI / 4d);

// Using float precision
var line2 = Circle.TangentLine.FromAngle(radius: 5f, angle: MathF.PI / 4f);

// Find tangent points from a circle
var tangentPoints = Circle.TangentPoint.FromPoint(radius: 2d, (4, 4));
var secantLine = Line.FromTwoPoints(tangentPoints.Value.Point1, tangentPoints.Value.Point2);

Statistical Calculations

// Example of calculating variance
var values = new double[] { 1, 2, 3, 4, 5 };
double variance = Statistics.Variance(values);
Console.WriteLine($"Variance: {variance}");

Contributing

Any ideas, contributions and bug reports are welcome!

For new idea create an issue.
For bug report create an issue.
For contribution create a pull request.

License

Project is under MIT license.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SMath:

Package Downloads
SPhysics

Alternative physics library based on .Net 7 generic math.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.9.0 154 4/3/2025
0.8.0 281 3/3/2025
0.7.0 340 9/26/2023
0.6.0 186 8/22/2023
0.5.0 192 6/5/2023
0.4.0 185 6/4/2023
0.3.0 192 6/2/2023
0.2.0 188 6/1/2023
0.1.0 183 5/31/2023