Dimension 1.0.2
See the version list below for details.
dotnet add package Dimension --version 1.0.2
NuGet\Install-Package Dimension -Version 1.0.2
<PackageReference Include="Dimension" Version="1.0.2" />
<PackageVersion Include="Dimension" Version="1.0.2" />
<PackageReference Include="Dimension" />
paket add Dimension --version 1.0.2
#r "nuget: Dimension, 1.0.2"
#:package Dimension@1.0.2
#addin nuget:?package=Dimension&version=1.0.2
#tool nuget:?package=Dimension&version=1.0.2
Dimension Library
Content :
- Manual
IVector
Start from the interface IVector for Vector2 (2D) & Vector3 (3D)
public interface IVector<T> where T : IVector<T>
{
public float X { get; set; }
public float Y { get; set; }
public static abstract T operator /(T v, T v2);
public static abstract T operator /(T v, float val);
public static abstract T operator *(T v, T v2);
public static abstract T operator *(T v, float val);
public static abstract T operator +(T v, T v2);
public static abstract T operator +(T v, float val);
public static abstract T operator -(T v, T v2);
public static abstract T operator -(T v, float val);
public float GetSum();
public float GetAbsoluteSum();
public float GetMagnitude();
public T GetSquared();
public T GetAbsolute();
public T GetNormalized();
public T GetSqrt();
public T GetCubed();
public bool HasZero();
public bool HasNegative();
}
IVector GetSum method
Returns the total sum of Vector's values
Implementation for Vector2
public readonly float GetSum() => X + Y;
Basic usage
Console.WriteLine(new Vector2(25,-16).GetSum());// we get 9
Implementation for Vector3
public readonly float GetSum() => X + Y + Z;
Basic usage
Console.WriteLine(new Vector3(25,-16, 5).GetSum());// we get 14
IVector GetAbsoluteSum method
Returns the total absolute sum of Vector's values
Implementation for Vector2
public readonly float GetAbsoluteSum() => GetAbsolute().GetSum();
Basic usage
Console.WriteLine(new Vector2(25,-16).GetAbsoluteSum());// we get 41
This method also used in IVector.GetNormilized()
Implementation for Vector3
public readonly float GetAbsoluteSum() => GetAbsolute().GetSum();
Basic usage
Console.WriteLine(new Vector3(25,-16, 5).GetAbsoluteSum());// we get 46
IVector GetMagnitude method
Returns the magnitude of Vector
Implementation for Vector2
public readonly float GetMagnitude() => GetSquared().GetSum();
Basic usage
Console.WriteLine(new Vector2(8,-6).GetAbsoluteSum());// we get 10
This method also used in Vectors.GetMagnitude()
Implementation for Vector3
public readonly float GetMagnitude() => GetSquared().GetSum();
Basic usage
Console.WriteLine(new Vector3(2,4,4).GetAbsoluteSum());// we get 6
IVector GetSquared method
Returns new Vector with squared values
Implementation for Vector2
public readonly Vector2 GetSquared() => this*this;
Basic usage
Console.WriteLine(new Vector2(25,-10).GetSquared());// we get Vector2{625,100}
This method also used in Vectors.GetMagnitude()
Implementation for Vector3
public readonly Vector3 GetSquared() => this*this;
Basic usage
Console.WriteLine(new Vector3(4,-9, 2).GetSquared());// we get Vector3{16,81,4}
IVector GetCubed method
Returns new Vector with cubed values
Implementation for Vector2
public readonly Vector2 GetCubed() => this*this*this;
Basic usage
Console.WriteLine(new Vector2(10,-10).GetCubed());// we get Vector2{1000,1000}
Implementation for Vector3
public readonly Vector3 GetCubed() => this*this*this;
Basic usage
Console.WriteLine(new Vector3(4,-1, 2).GetCubed());// we get Vector3{64,1,8}
IVector GetAbsolute method
Returns new Vector with absolute values
Implementation for Vector2
public readonly Vector2 GetAbsolute() => new(Math.Abs(X),Math.Abs(Y));
Basic usage
Console.WriteLine(new Vector2(25,-10).GetAbsolute());// we get Vector2{25,10}
Implementation for Vector3
public readonly Vector3 GetAbsolute() => new(Math.Abs(X),Math.Abs(Y),Math.Abs(Z));
Basic usage
Console.WriteLine(new Vector3(4,-9, -2).GetAbsolute());// we get Vector3{4,9,2}
IVector GetNormalized method
Returns vector with normalized values
Implementation for Vector2
public readonly Vector2 GetNormalized()
{
float sum = GetAbsoluteSum();
if (sum == 0)
throw new DivideByZeroException();
return this / sum;
}
Basic usage
Console.WriteLine(new Vector2(20,-40).GetNormalized());// we get Vector2{0.(3),-0.(6)}
Implementation for Vector3
public readonly Vector3 GetNormalized()
{
float sum = GetAbsoluteSum();
if (sum == 0)
throw new DivideByZeroException();
return this / sum;
}
Basic usage
Console.WriteLine(new Vector3(4,-9, -2).GetNormalized());// we get Vector3{0.1(3),-0.6,-0.2(6)}
IVector GetSqrt method
Returns vector with sqrt values
Implementation for Vector2
public readonly Vector2 GetSqrt()
{
if (HasNegative())
throw new ArgumentException("Cannot calculate from negative number");
return new((float)Math.Sqrt(X), (float)Math.Sqrt(Y));
}
Basic usage
Console.WriteLine(new Vector2(121,40).GetSqrt());// we get Vector2{11,√40}
Implementation for Vector3
public readonly Vector3 GetSqrt()
{
if (HasNegative())
throw new ArgumentException("Cannot calculate sqrt from negative number");
return new((float)Math.Sqrt(X), (float)Math.Sqrt(Y), (float)Math.Sqrt(Z));
}
Basic usage
Console.WriteLine(new Vector3(25,9, 100).GetSqrt());// we get Vector3{5,3,10}
IVector HasZero method
Returns true if Vector has zero among it's values
Implementation for Vector2
public readonly bool HasZero() => X == 0 || Y == 0;
Basic usage
Console.WriteLine(new Vector2(11,40).HasZero());// we get false
Implementation for Vector3
public readonly bool HasZero() => X == 0 || Y == 0 || Z == 0;
Basic usage
Console.WriteLine(new Vector3(44,0, 1).HasZero());// we get true
IVector HasNegative method
Returns true if Vector has negative number among it's values
Implementation for Vector2
public readonly bool HasNegative() => X < 0 || Y < 0 || Z < 0;
Basic usage
Console.WriteLine(new Vector2(104.4f,0).HasNegative());// we get false
Implementation for Vector3
public readonly bool HasNegative() => X < 0 || Y < 0 || Z < 0;
Basic usage
Console.WriteLine(new Vector3(52,0, -100).HasNegative());// we get false
Vectors
static class to comfortablier use Vectors, has very useful Methods
public static class Vectors
{
public static float GetMagnitude<T>(T origin, T target) where T : IVector<T> => (origin-target).GetMagnitude();
public static IVector<T> GetDirection<T>(T origin, T target) where T : IVector<T> => (target-origin).GetNormalized();
public static T GetCenter<T>(IEnumerable<T> vectors) where T : IVector<T> , new()
{
if (!vectors.Any())
throw new ArgumentException();
int count = 0;
T total_sum = new();
foreach(var vector in vectors)
{
total_sum = (total_sum + vector);
count++;
}
return total_sum / count;
}
}
Vectors GetMagnitude method
return : magnitude of given vectors
parameters : Vector origin , Vector target
usages :
Console.WriteLine(Vectors.GetMagnitude(new Vector3(1, 2, 4), new Vector3(2, 2, 2)));//we get √5
Console.WriteLine(Vectors.GetMagnitude(new Vector2(3,15), new Vector2(6,5)));//we get √109
Vectors GetDirection method
return : normalized direction of two Vectors parameters : Vector origin , Vector target
usages :
Console.WriteLine(Vectors.GetDirection(new Vector3(1, 2, 4), new Vector3(2, 2, 2)));//we get {0.(3),0,0.(6)}
Console.WriteLine(Vectors.GetDirection(new Vector2(3,15), new Vector2(6,5)));//we get {0.23,0.77}
Vectors GetCenter method
return : normalized direction of two Vectors parameters : IEnumberable of Vectors
usages :
Console.WriteLine(Vectors.GetCenter(new List<Vector2>() { new Vector2(11, 1), new Vector2(33, 3) }));//we get {22,2}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Dimension:
Package | Downloads |
---|---|
GraphFunctions
.Net Packege for creating and building Graphical Functions |
GitHub repositories
This package is not used by any popular GitHub repositories.
Rewrote:IVector.GetNormalized() , IVector.GetSqrt(), IVector.GetSquared(), Vectors.GetMagnitude(), Vectors.GetDirection();
New: IVector.HasNegative(), IVector.GetAbsoluteSum(), IVector.GetMagnitude();Fixed : GetAbsolute();