daily update on 20230227 by nitload youmu
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public struct Array2x2
|
||||
{
|
||||
public Vec2D row0;
|
||||
public Vec2D row1;
|
||||
|
||||
public Vec2D colum0;
|
||||
public Vec2D colum1;
|
||||
|
||||
public Array2x2(Vec2D c0, Vec2D c1)
|
||||
{
|
||||
row0 = c0;
|
||||
row1 = c1;
|
||||
colum0 = new Vec2D(c0.X,c1.X);
|
||||
colum1 = new Vec2D(c0.Y,c1.Y);
|
||||
}
|
||||
|
||||
public Array2x2(
|
||||
float a11,
|
||||
float a12,
|
||||
float a21,
|
||||
float a22
|
||||
)
|
||||
{
|
||||
row0 = new Vec2D(a11, a12);
|
||||
row1 = new Vec2D(a21, a22);
|
||||
|
||||
colum0 = new Vec2D(a11, a21);
|
||||
colum1 = new Vec2D(a21, a22);
|
||||
}
|
||||
|
||||
public static Array2x2 operator *(Array2x2 array1, Array2x2 array2)
|
||||
{
|
||||
return new Array2x2(
|
||||
array1.colum0 * array2.row0,
|
||||
array1.colum1 * array2.row0,
|
||||
array1.colum0 * array2.row1,
|
||||
array1.colum1 * array2.row1
|
||||
);
|
||||
}
|
||||
|
||||
public static Array2x2 operator +(Array2x2 array1, Array2x2 array2)
|
||||
{
|
||||
return new Array2x2(
|
||||
array1.row0 + array2.row0,
|
||||
array1.row1 + array2.row1
|
||||
);
|
||||
}
|
||||
|
||||
public static Array2x2 operator -(Array2x2 array1, Array2x2 array2)
|
||||
{
|
||||
return new Array2x2(
|
||||
array1.row0 - array2.row0,
|
||||
array1.row1 - array2.row1
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public struct Array3x3
|
||||
{
|
||||
public Vec3D row0;
|
||||
public Vec3D row1;
|
||||
public Vec3D row2;
|
||||
|
||||
public Vec3D colum0;
|
||||
public Vec3D colum1;
|
||||
public Vec3D colum2;
|
||||
|
||||
public Array3x3(Vec3D r0,Vec3D r1,Vec3D r2)
|
||||
{
|
||||
row0 = r0;
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
|
||||
colum0 = new Vec3D(r0.X, r1.X, r2.X);
|
||||
colum1 = new Vec3D(r0.Y, r1.Y, r2.Y);
|
||||
colum2 = new Vec3D(r0.Z, r1.Z, r2.Z);
|
||||
}
|
||||
|
||||
public Array3x3(
|
||||
float a11,float a12,float a13,
|
||||
float a21,float a22,float a23,
|
||||
float a31,float a32,float a33
|
||||
)
|
||||
{
|
||||
row0 = new Vec3D(a11, a12, a13);
|
||||
row1 = new Vec3D(a21, a22, a23);
|
||||
row2 = new Vec3D(a31, a32, a33);
|
||||
|
||||
colum0 = new Vec3D(a11,a21,a31);
|
||||
colum1 = new Vec3D(a12,a22,a32);
|
||||
colum2 = new Vec3D(a13,a23,a33);
|
||||
}
|
||||
|
||||
public static Array3x3 operator +(Array3x3 array1, Array3x3 array2)
|
||||
{
|
||||
return new Array3x3(
|
||||
array1.row0.X + array2.row0.X,
|
||||
array1.row0.Y + array2.row0.Y,
|
||||
array1.row0.Z + array2.row0.Z,
|
||||
|
||||
array1.row1.X + array2.row1.X,
|
||||
array1.row1.Y + array2.row1.Y,
|
||||
array1.row1.Z + array2.row1.Z,
|
||||
|
||||
array1.row2.X + array2.row2.X,
|
||||
array1.row2.Y + array2.row2.Y,
|
||||
array1.row2.Z + array2.row2.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static Array3x3 operator -(Array3x3 array1, Array3x3 array2)
|
||||
{
|
||||
return new Array3x3(
|
||||
array1.row0.X - array2.row0.X,
|
||||
array1.row0.Y - array2.row0.Y,
|
||||
array1.row0.Z - array2.row0.Z,
|
||||
|
||||
array1.row1.X - array2.row1.X,
|
||||
array1.row1.Y - array2.row1.Y,
|
||||
array1.row1.Z - array2.row1.Z,
|
||||
|
||||
array1.row2.X - array2.row2.X,
|
||||
array1.row2.Y - array2.row2.Y,
|
||||
array1.row2.Z - array2.row2.Z
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class VectorCalc
|
||||
{
|
||||
|
||||
public static float Cross(Vec2D vec1, Vec2D vec2)
|
||||
{
|
||||
return vec1.X * vec2.Y - vec1.Y * vec2.X;
|
||||
}
|
||||
|
||||
public static Vec3D Cross(Vec3D vec1, Vec3D vec2)
|
||||
{
|
||||
return new Vec3D(
|
||||
vec1.Y * vec2.Z - vec1.Z * vec2.Y,
|
||||
vec1.X * vec2.Z - vec1.Z * vec2.X,
|
||||
vec1.X * vec2.Y - vec1.Y * vec2.X
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class VectorCalc
|
||||
{
|
||||
|
||||
public static float Det(Array2x2 array)
|
||||
{
|
||||
return Cross(array.row0,array.row1);
|
||||
}
|
||||
|
||||
public static float Det(Array3x3 array)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class VectorCalc
|
||||
{
|
||||
public static float GetAngle(Vec2D vec1, Vec2D vec2)
|
||||
{
|
||||
return Calc.ACos(
|
||||
vec1 * vec2
|
||||
/ (vec1.GetLength() * vec2.GetLength())
|
||||
);
|
||||
}
|
||||
|
||||
public static float GetAngle(Vec3D vec1, Vec3D vec2)
|
||||
{
|
||||
return Calc.ACos(
|
||||
vec1 * vec2
|
||||
/ (vec1.GetLength() * vec2.GetLength())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class VectorCalc
|
||||
{
|
||||
public static float GetLength(this Vec3D vec)
|
||||
{
|
||||
return Calc.Sqrt(
|
||||
vec.X * vec.X +
|
||||
vec.Y * vec.Y +
|
||||
vec.Z * vec.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static float GetLength(this Vec2D vec)
|
||||
{
|
||||
return Calc.Sqrt(
|
||||
vec.X * vec.X +
|
||||
vec.Y * vec.Y
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static unsafe partial class VectorCalc
|
||||
{
|
||||
public static Array2x2
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
@@ -9,15 +10,11 @@ namespace StgSharp.Math
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Direction;
|
||||
public float Length;
|
||||
|
||||
public Vec2D(float x,float y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Direction = Calc.ATan(X,Y);
|
||||
Length = Calc.Sqrt(X * X + Y * Y);
|
||||
}
|
||||
|
||||
public bool Equals(Vec2D other)
|
||||
@@ -93,10 +90,9 @@ namespace StgSharp.Math
|
||||
return new Vec2D(vec.X/x, vec.Y/x);
|
||||
}
|
||||
|
||||
public float x(Vec2D others)
|
||||
public Vec3D to3D()
|
||||
{
|
||||
return this.X * others.Y - this.Y * others.X;
|
||||
return new Vec3D(this.X, this.Y, 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,14 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
public static float operator *(Vec3D vec1, Vec3D vec2)
|
||||
{
|
||||
return
|
||||
vec1.X * vec2.X
|
||||
+ vec1.Y + vec2.Y
|
||||
+ vec1.Z + vec2.Z;
|
||||
}
|
||||
|
||||
public static Vec3D operator *(Vec3D vec, float x)
|
||||
{
|
||||
return new Vec3D(
|
||||
@@ -107,6 +115,5 @@ namespace StgSharp.Math
|
||||
vec.Z / x
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user