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.
Leverages .NET 7’s new generic math features, allowing type-safe mathematical operations on various numeric types.
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.
Perform basic statistical calculations:
- Correlation
- Variance
- Covariance
- Standard Deviation
- Histograms
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.
Here are some basic usage examples to get started with SMath:
// 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);
// Example of calculating variance
var values = new double[] { 1, 2, 3, 4, 5 };
double variance = Statistics.Variance(values);
Console.WriteLine($"Variance: {variance}");
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.
Project is under MIT license.