Dimension 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Dimension --version 1.0.2
                    
NuGet\Install-Package Dimension -Version 1.0.2
                    
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="Dimension" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dimension" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Dimension" />
                    
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 Dimension --version 1.0.2
                    
#r "nuget: Dimension, 1.0.2"
                    
#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 Dimension@1.0.2
                    
#: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=Dimension&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Dimension&version=1.0.2
                    
Install as a Cake Tool

Dimension Library

Content :



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

Version Downloads Last Updated
1.1.3 168 5/16/2025
1.1.2 140 5/8/2025
1.1.1 147 5/8/2025
1.1.0 131 4/19/2025
1.0.5.1 204 4/15/2025
1.0.5 196 4/15/2025
1.0.4 182 4/13/2025
1.0.3 176 4/7/2025
1.0.2 161 4/6/2025
1.0.1 155 4/6/2025
1.0.0 148 4/6/2025

Rewrote:IVector.GetNormalized() , IVector.GetSqrt(), IVector.GetSquared(), Vectors.GetMagnitude(), Vectors.GetDirection();
New: IVector.HasNegative(), IVector.GetAbsoluteSum(), IVector.GetMagnitude();Fixed : GetAbsolute();