System.DoubleNumerics by weingartner machinen bau

<PackageReference Include="System.DoubleNumerics" Version="3.1.0" />

 Plane

public struct Plane : IEquatable<Plane>
using System.Globalization; using System.Runtime.CompilerServices; namespace System.DoubleNumerics { public struct Plane : IEquatable<Plane> { public Vector3 Normal; public double D; public Plane(double x, double y, double z, double d) { Normal = new Vector3(x, y, z); D = d; } public Plane(Vector3 normal, double d) { Normal = normal; D = d; } public Plane(Vector4 value) { Normal = new Vector3(value.X, value.Y, value.Z); D = value.W; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane CreateFromVertices(Vector3 point1, Vector3 point2, Vector3 point3) { double num = point2.X - point1.X; double num2 = point2.Y - point1.Y; double num3 = point2.Z - point1.Z; double num4 = point3.X - point1.X; double num5 = point3.Y - point1.Y; double num6 = point3.Z - point1.Z; double num7 = num2 * num6 - num3 * num5; double num8 = num3 * num4 - num * num6; double num9 = num * num5 - num2 * num4; double num10 = num7 * num7 + num8 * num8 + num9 * num9; double num11 = 1 / Math.Sqrt(num10); Vector3 vector = new Vector3(num7 * num11, num8 * num11, num9 * num11); return new Plane(vector, 0 - (vector.X * point1.X + vector.Y * point1.Y + vector.Z * point1.Z)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane Normalize(Plane value) { double num = value.Normal.X * value.Normal.X + value.Normal.Y * value.Normal.Y + value.Normal.Z * value.Normal.Z; if (!(Math.Abs(num - 1) < 1.192092896E-07)) { double num2 = 1 / Math.Sqrt(num); return new Plane(value.Normal.X * num2, value.Normal.Y * num2, value.Normal.Z * num2, value.D * num2); } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane Transform(Plane plane, Matrix4x4 matrix) { Matrix4x4.Invert(matrix, out Matrix4x4 result); double x = plane.Normal.X; double y = plane.Normal.Y; double z = plane.Normal.Z; double d = plane.D; return new Plane(x * result.M11 + y * result.M12 + z * result.M13 + d * result.M14, x * result.M21 + y * result.M22 + z * result.M23 + d * result.M24, x * result.M31 + y * result.M32 + z * result.M33 + d * result.M34, x * result.M41 + y * result.M42 + z * result.M43 + d * result.M44); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Plane Transform(Plane plane, Quaternion rotation) { double num = rotation.X + rotation.X; double num2 = rotation.Y + rotation.Y; double num3 = rotation.Z + rotation.Z; double num4 = rotation.W * num; double num5 = rotation.W * num2; double num6 = rotation.W * num3; double num7 = rotation.X * num; double num8 = rotation.X * num2; double num9 = rotation.X * num3; double num10 = rotation.Y * num2; double num11 = rotation.Y * num3; double num12 = rotation.Z * num3; double num13 = 1 - num10 - num12; double num14 = num8 - num6; double num15 = num9 + num5; double num16 = num8 + num6; double num17 = 1 - num7 - num12; double num18 = num11 - num4; double num19 = num9 - num5; double num20 = num11 + num4; double num21 = 1 - num7 - num10; double x = plane.Normal.X; double y = plane.Normal.Y; double z = plane.Normal.Z; return new Plane(x * num13 + y * num14 + z * num15, x * num16 + y * num17 + z * num18, x * num19 + y * num20 + z * num21, plane.D); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Dot(Plane plane, Vector4 value) { return plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D * value.W; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double DotCoordinate(Plane plane, Vector3 value) { return plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z + plane.D; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double DotNormal(Plane plane, Vector3 value) { return plane.Normal.X * value.X + plane.Normal.Y * value.Y + plane.Normal.Z * value.Z; } public static bool operator ==(Plane value1, Plane value2) { return value1.Normal.X == value2.Normal.X && value1.Normal.Y == value2.Normal.Y && value1.Normal.Z == value2.Normal.Z && value1.D == value2.D; } public static bool operator !=(Plane value1, Plane value2) { return value1.Normal.X != value2.Normal.X || value1.Normal.Y != value2.Normal.Y || value1.Normal.Z != value2.Normal.Z || value1.D != value2.D; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Plane other) { return Normal.X == other.Normal.X && Normal.Y == other.Normal.Y && Normal.Z == other.Normal.Z && D == other.D; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) { if (!(obj is Plane)) return false; return Equals((Plane)obj); } public override string ToString() { CultureInfo currentCulture = CultureInfo.CurrentCulture; return string.Format(currentCulture, "{{Normal:{0} D:{1}}}", Normal.ToString(), D.ToString(currentCulture)); } public override int GetHashCode() { return Normal.GetHashCode() + D.GetHashCode(); } } }