Большое переименование и рефакторинг углов / Big renaming and refactoring of angles
This commit is contained in:
parent
1afbf8c1d6
commit
72d06a23b2
38 changed files with 3819 additions and 3757 deletions
|
|
@ -1,37 +1,37 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.0.31903.59
|
VisualStudioVersion = 17.0.31903.59
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Geometry", "Geometry\Geometry.csproj", "{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BGC", "BGC\BGC.csproj", "{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeometryDev", "GeometryDev\GeometryDev.csproj", "{3D09FF57-02E6-449D-9DE7-0843633FCBA0}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BGCDev", "BGCDev\BGCDev.csproj", "{3D09FF57-02E6-449D-9DE7-0843633FCBA0}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeometryTest", "GeometryTest\GeometryTest.csproj", "{51A07B27-43FF-4A12-AEC1-50D32EDA3815}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BGCTest", "BGCTest\BGCTest.csproj", "{51A07B27-43FF-4A12-AEC1-50D32EDA3815}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D1869DF0-7B61-4B6F-8C66-6EEF3916FE0A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{3D09FF57-02E6-449D-9DE7-0843633FCBA0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Release|Any CPU.Build.0 = Release|Any CPU
|
{51A07B27-43FF-4A12-AEC1-50D32EDA3815}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {040DE977-0DDC-4EEA-8EBC-CBCA41289BBE}
|
SolutionGuid = {040DE977-0DDC-4EEA-8EBC-CBCA41289BBE}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
@ -1,48 +1,48 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 1 Feb 2019
|
* Date: 1 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public enum AngleUnit
|
public enum AngleUnit
|
||||||
{
|
{
|
||||||
RADIANS = 1,
|
RADIANS = 1,
|
||||||
DEGREES = 2,
|
DEGREES = 2,
|
||||||
TURNS = 3,
|
TURNS = 3,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum AngleRange
|
public enum AngleRange
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The measure of an angle with a range of:
|
/// The measure of an angle with a range of:
|
||||||
/// [0, 360) degrees, [0, 2xPI) radians, [0, 1) turns, [0, 400) gradians
|
/// [0, 360) degrees, [0, 2xPI) radians, [0, 1) turns, [0, 400) gradians
|
||||||
/// </summary>
|
/// </summary>
|
||||||
UNSIGNED_RANGE = 1,
|
UNSIGNED_RANGE = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The measure of an angle with a range of:
|
/// The measure of an angle with a range of:
|
||||||
/// (-180, 180] degrees, (-PI, PI] radians, (-0.5, 0.5] turns, (-200, 200] gradians
|
/// (-180, 180] degrees, (-PI, PI] radians, (-0.5, 0.5] turns, (-200, 200] gradians
|
||||||
/// </summary>
|
/// </summary>
|
||||||
SIGNED_RANGE = 2
|
SIGNED_RANGE = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,16 +1,10 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Remove="DPMatrix4x4.cs" />
|
</Project>
|
||||||
<Compile Remove="DPVector4.cs" />
|
|
||||||
<Compile Remove="SPMatrix4x4.cs" />
|
|
||||||
<Compile Remove="SPVector4.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
133
BGC/F32Angle.cs
Normal file
133
BGC/F32Angle.cs
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 1 Feb 2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public static class F32Angle
|
||||||
|
{
|
||||||
|
public static float ToRadians(float angle, AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return angle * F32Degrees.RADIANS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return angle * F32Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToDegrees(float angle, AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return angle * F32Radians.DEGREES_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return angle * 360.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToTurns(float angle, AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return angle * F32Radians.TURNS_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return angle * F32Degrees.TURNS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float GetFullCircle(AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return 360.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return F32Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float GetHalfCircle(AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return 180.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return F32Radians.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float GetQuarterCircle(AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return 90.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return 0.25f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return F32Radians.HALF_OF_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float Normalize(float angle, AngleUnit unit, AngleRange range)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return F32Degrees.Normalize(angle, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return F32Turns.Normalize(angle, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
return F32Radians.Normalize(angle, range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
68
BGC/F32Degrees.cs
Normal file
68
BGC/F32Degrees.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 18 Nov 2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public class F32Degrees
|
||||||
|
{
|
||||||
|
public const float RADIANS_IN_DEGREE = 1.745329252E-2f;
|
||||||
|
public const float TURNS_IN_DEGREE = 2.7777777778E-3f;
|
||||||
|
|
||||||
|
public static float ToRadians(float degrees)
|
||||||
|
{
|
||||||
|
return degrees * RADIANS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToTurns(float degrees)
|
||||||
|
{
|
||||||
|
return degrees * TURNS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToUnits(float degrees, AngleUnit toUnit)
|
||||||
|
{
|
||||||
|
if (toUnit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return degrees * RADIANS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUnit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return degrees * TURNS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float Normalize(float radians, AngleRange range)
|
||||||
|
{
|
||||||
|
if (range == AngleRange.UNSIGNED_RANGE)
|
||||||
|
{
|
||||||
|
if (0.0f <= radians && radians < 360.0f)
|
||||||
|
{
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (-180.0f < radians && radians <= 180.0f)
|
||||||
|
{
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float turns = radians * TURNS_IN_DEGREE;
|
||||||
|
|
||||||
|
turns -= MathF.Floor(turns);
|
||||||
|
|
||||||
|
if (range == AngleRange.SIGNED_RANGE && turns > 0.5f)
|
||||||
|
{
|
||||||
|
turns -= 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return turns * 360.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,352 +1,352 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 10 Feb 2019
|
* Date: 10 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPMatrix2x2
|
public struct F32Matrix2x2
|
||||||
{
|
{
|
||||||
public float r1c1, r1c2;
|
public float r1c1, r1c2;
|
||||||
|
|
||||||
public float r2c1, r2c2;
|
public float r2c1, r2c2;
|
||||||
|
|
||||||
public SPMatrix2x2()
|
public F32Matrix2x2()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0f;
|
this.r1c1 = 0.0f;
|
||||||
this.r1c2 = 0.0f;
|
this.r1c2 = 0.0f;
|
||||||
|
|
||||||
this.r2c1 = 0.0f;
|
this.r2c1 = 0.0f;
|
||||||
this.r2c2 = 0.0f;
|
this.r2c2 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix2x2(float d1, float d2)
|
public F32Matrix2x2(float d1, float d2)
|
||||||
{
|
{
|
||||||
this.r1c1 = d1;
|
this.r1c1 = d1;
|
||||||
this.r1c2 = 0.0f;
|
this.r1c2 = 0.0f;
|
||||||
|
|
||||||
this.r2c1 = 0.0f;
|
this.r2c1 = 0.0f;
|
||||||
this.r2c2 = d2;
|
this.r2c2 = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix2x2(in SPMatrix2x2 matrix)
|
public F32Matrix2x2(in F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = matrix.r2c1;
|
this.r2c1 = matrix.r2c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix2x2(in DPMatrix2x2 matrix)
|
public F32Matrix2x2(in F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float)matrix.r1c1;
|
this.r1c1 = (float)matrix.r1c1;
|
||||||
this.r1c2 = (float)matrix.r1c2;
|
this.r1c2 = (float)matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = (float)matrix.r2c1;
|
this.r2c1 = (float)matrix.r2c1;
|
||||||
this.r2c2 = (float)matrix.r2c2;
|
this.r2c2 = (float)matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly float GetDeterminant()
|
public readonly float GetDeterminant()
|
||||||
{
|
{
|
||||||
return this.r1c1 * this.r2c2 - this.r1c2 * this.r2c1;
|
return this.r1c1 * this.r2c2 - this.r1c2 * this.r2c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsSingular()
|
public readonly bool IsSingular()
|
||||||
{
|
{
|
||||||
float determinant = this.GetDeterminant();
|
float determinant = this.GetDeterminant();
|
||||||
return -SPUtility.EPSYLON <= determinant && determinant <= SPUtility.EPSYLON;
|
return -F32Utility.EPSYLON <= determinant && determinant <= F32Utility.EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Transpose()
|
public void Transpose()
|
||||||
{
|
{
|
||||||
(this.r1c2, this.r2c1) = (this.r2c1, this.r1c2);
|
(this.r1c2, this.r2c1) = (this.r2c1, this.r1c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Invert()
|
public bool Invert()
|
||||||
{
|
{
|
||||||
float determinant = this.GetDeterminant();
|
float determinant = this.GetDeterminant();
|
||||||
|
|
||||||
if (-SPUtility.EPSYLON <= determinant && determinant <= SPUtility.EPSYLON)
|
if (-F32Utility.EPSYLON <= determinant && determinant <= F32Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float r1c1 = this.r2c2;
|
float r1c1 = this.r2c2;
|
||||||
float r1c2 = -this.r1c2;
|
float r1c2 = -this.r1c2;
|
||||||
|
|
||||||
float r2c1 = -this.r2c1;
|
float r2c1 = -this.r2c1;
|
||||||
float r2c2 = this.r1c1;
|
float r2c2 = this.r1c1;
|
||||||
|
|
||||||
this.r1c1 = r1c1 / determinant;
|
this.r1c1 = r1c1 / determinant;
|
||||||
this.r1c2 = r1c2 / determinant;
|
this.r1c2 = r1c2 / determinant;
|
||||||
|
|
||||||
this.r2c1 = r2c1 / determinant;
|
this.r2c1 = r2c1 / determinant;
|
||||||
this.r2c2 = r2c2 / determinant;
|
this.r2c2 = r2c2 / determinant;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0f;
|
this.r1c1 = 0.0f;
|
||||||
this.r1c2 = 0.0f;
|
this.r1c2 = 0.0f;
|
||||||
|
|
||||||
this.r2c1 = 0.0f;
|
this.r2c1 = 0.0f;
|
||||||
this.r2c2 = 0.0f;
|
this.r2c2 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetToIdentity()
|
public void SetToIdentity()
|
||||||
{
|
{
|
||||||
this.r1c1 = 1.0f;
|
this.r1c1 = 1.0f;
|
||||||
this.r1c2 = 0.0f;
|
this.r1c2 = 0.0f;
|
||||||
|
|
||||||
this.r2c1 = 0.0f;
|
this.r2c1 = 0.0f;
|
||||||
this.r2c2 = 1.0f;
|
this.r2c2 = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetToDiagonal(float d1, float d2)
|
public void SetToDiagonal(float d1, float d2)
|
||||||
{
|
{
|
||||||
this.r1c1 = d1;
|
this.r1c1 = d1;
|
||||||
this.r1c2 = 0.0f;
|
this.r1c2 = 0.0f;
|
||||||
|
|
||||||
this.r2c1 = 0.0f;
|
this.r2c1 = 0.0f;
|
||||||
this.r2c2 = d2;
|
this.r2c2 = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPMatrix2x2 matrix)
|
public void SetValues(in F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = matrix.r2c1;
|
this.r2c1 = matrix.r2c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPMatrix2x2 matrix)
|
public void SetValues(in F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float)matrix.r1c1;
|
this.r1c1 = (float)matrix.r1c1;
|
||||||
this.r1c2 = (float)matrix.r1c2;
|
this.r1c2 = (float)matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = (float)matrix.r2c1;
|
this.r2c1 = (float)matrix.r2c1;
|
||||||
this.r2c2 = (float)matrix.r2c2;
|
this.r2c2 = (float)matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposedOf(in SPMatrix2x2 matrix)
|
public void SetTransposedOf(in F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
(this.r1c2, this.r2c1) = (matrix.r2c1, matrix.r1c2);
|
(this.r1c2, this.r2c1) = (matrix.r2c1, matrix.r1c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposedOf(in DPMatrix2x2 matrix)
|
public void SetTransposedOf(in F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float)matrix.r1c1;
|
this.r1c1 = (float)matrix.r1c1;
|
||||||
this.r1c2 = (float)matrix.r2c1;
|
this.r1c2 = (float)matrix.r2c1;
|
||||||
|
|
||||||
this.r2c1 = (float)matrix.r1c2;
|
this.r2c1 = (float)matrix.r1c2;
|
||||||
this.r2c2 = (float)matrix.r2c2;
|
this.r2c2 = (float)matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SetInvertedOf(in SPMatrix2x2 matrix)
|
public bool SetInvertedOf(in F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
float determinant = matrix.GetDeterminant();
|
float determinant = matrix.GetDeterminant();
|
||||||
|
|
||||||
if (-SPUtility.EPSYLON <= determinant && determinant <= SPUtility.EPSYLON)
|
if (-F32Utility.EPSYLON <= determinant && determinant <= F32Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float r1c1 = matrix.r2c2;
|
float r1c1 = matrix.r2c2;
|
||||||
float r1c2 = -matrix.r1c2;
|
float r1c2 = -matrix.r1c2;
|
||||||
|
|
||||||
float r2c1 = -matrix.r2c1;
|
float r2c1 = -matrix.r2c1;
|
||||||
float r2c2 = matrix.r1c1;
|
float r2c2 = matrix.r1c1;
|
||||||
|
|
||||||
this.r1c1 = r1c1 / determinant;
|
this.r1c1 = r1c1 / determinant;
|
||||||
this.r1c2 = r1c2 / determinant;
|
this.r1c2 = r1c2 / determinant;
|
||||||
|
|
||||||
this.r2c1 = r2c1 / determinant;
|
this.r2c1 = r2c1 / determinant;
|
||||||
this.r2c2 = r2c2 / determinant;
|
this.r2c2 = r2c2 / determinant;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRow1(float c1, float c2)
|
public void SetRow1(float c1, float c2)
|
||||||
{
|
{
|
||||||
this.r1c1 = c1;
|
this.r1c1 = c1;
|
||||||
this.r1c2 = c2;
|
this.r1c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRow2(float c1, float c2)
|
public void SetRow2(float c1, float c2)
|
||||||
{
|
{
|
||||||
this.r2c1 = c1;
|
this.r2c1 = c1;
|
||||||
this.r2c2 = c2;
|
this.r2c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetColumn1(float r1, float r2)
|
public void SetColumn1(float r1, float r2)
|
||||||
{
|
{
|
||||||
this.r1c1 = r1;
|
this.r1c1 = r1;
|
||||||
this.r2c1 = r2;
|
this.r2c1 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetColumn2(float r1, float r2)
|
public void SetColumn2(float r1, float r2)
|
||||||
{
|
{
|
||||||
this.r1c2 = r1;
|
this.r1c2 = r1;
|
||||||
this.r2c2 = r2;
|
this.r2c2 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in SPMatrix2x2 matrix1, in SPMatrix2x2 matrix2, out SPMatrix2x2 result)
|
public static void Add(in F32Matrix2x2 matrix1, in F32Matrix2x2 matrix2, out F32Matrix2x2 result)
|
||||||
{
|
{
|
||||||
result.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
result.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
||||||
result.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
result.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
||||||
|
|
||||||
result.r2c1 = matrix1.r2c1 + matrix2.r2c1;
|
result.r2c1 = matrix1.r2c1 + matrix2.r2c1;
|
||||||
result.r2c2 = matrix1.r2c2 + matrix2.r2c2;
|
result.r2c2 = matrix1.r2c2 + matrix2.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in SPMatrix2x2 minuend, in SPMatrix2x2 subtrahend, out SPMatrix2x2 difference)
|
public static void Subtract(in F32Matrix2x2 minuend, in F32Matrix2x2 subtrahend, out F32Matrix2x2 difference)
|
||||||
{
|
{
|
||||||
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
||||||
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
||||||
|
|
||||||
difference.r2c1 = minuend.r2c1 - subtrahend.r2c1;
|
difference.r2c1 = minuend.r2c1 - subtrahend.r2c1;
|
||||||
difference.r2c2 = minuend.r2c2 - subtrahend.r2c2;
|
difference.r2c2 = minuend.r2c2 - subtrahend.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in SPMatrix2x2 multiplicand, float multiplier, out SPMatrix2x2 product)
|
public static void Multiply(in F32Matrix2x2 multiplicand, float multiplier, out F32Matrix2x2 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = multiplicand.r1c1 * multiplier;
|
product.r1c1 = multiplicand.r1c1 * multiplier;
|
||||||
product.r1c2 = multiplicand.r1c2 * multiplier;
|
product.r1c2 = multiplicand.r1c2 * multiplier;
|
||||||
|
|
||||||
product.r2c1 = multiplicand.r2c1 * multiplier;
|
product.r2c1 = multiplicand.r2c1 * multiplier;
|
||||||
product.r2c2 = multiplicand.r2c2 * multiplier;
|
product.r2c2 = multiplicand.r2c2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in SPMatrix2x2 dividend, float divisor, out SPMatrix2x2 quotient)
|
public static void Divide(in F32Matrix2x2 dividend, float divisor, out F32Matrix2x2 quotient)
|
||||||
{
|
{
|
||||||
quotient.r1c1 = dividend.r1c1 / divisor;
|
quotient.r1c1 = dividend.r1c1 / divisor;
|
||||||
quotient.r1c2 = dividend.r1c2 / divisor;
|
quotient.r1c2 = dividend.r1c2 / divisor;
|
||||||
|
|
||||||
quotient.r2c1 = dividend.r2c1 / divisor;
|
quotient.r2c1 = dividend.r2c1 / divisor;
|
||||||
quotient.r2c2 = dividend.r2c2 / divisor;
|
quotient.r2c2 = dividend.r2c2 / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
float weight1, in SPMatrix2x2 matrix1,
|
float weight1, in F32Matrix2x2 matrix1,
|
||||||
float weight2, in SPMatrix2x2 matrix2,
|
float weight2, in F32Matrix2x2 matrix2,
|
||||||
out SPMatrix2x2 sum)
|
out F32Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
||||||
|
|
||||||
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2;
|
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2;
|
||||||
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2;
|
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
float weight1, in SPMatrix2x2 matrix1,
|
float weight1, in F32Matrix2x2 matrix1,
|
||||||
float weight2, in SPMatrix2x2 matrix2,
|
float weight2, in F32Matrix2x2 matrix2,
|
||||||
float weight3, in SPMatrix2x2 matrix3,
|
float weight3, in F32Matrix2x2 matrix3,
|
||||||
out SPMatrix2x2 sum)
|
out F32Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
||||||
|
|
||||||
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2 + matrix3.r2c1 * weight3;
|
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2 + matrix3.r2c1 * weight3;
|
||||||
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2 + matrix3.r2c2 * weight3;
|
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2 + matrix3.r2c2 * weight3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
float weight1, in SPMatrix2x2 matrix1,
|
float weight1, in F32Matrix2x2 matrix1,
|
||||||
float weight2, in SPMatrix2x2 matrix2,
|
float weight2, in F32Matrix2x2 matrix2,
|
||||||
float weight3, in SPMatrix2x2 matrix3,
|
float weight3, in F32Matrix2x2 matrix3,
|
||||||
float weight4, in SPMatrix2x2 matrix4,
|
float weight4, in F32Matrix2x2 matrix4,
|
||||||
out SPMatrix2x2 sum)
|
out F32Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
||||||
|
|
||||||
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4);
|
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4);
|
||||||
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4);
|
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
float weight1, in SPMatrix2x2 matrix1,
|
float weight1, in F32Matrix2x2 matrix1,
|
||||||
float weight2, in SPMatrix2x2 matrix2,
|
float weight2, in F32Matrix2x2 matrix2,
|
||||||
float weight3, in SPMatrix2x2 matrix3,
|
float weight3, in F32Matrix2x2 matrix3,
|
||||||
float weight4, in SPMatrix2x2 matrix4,
|
float weight4, in F32Matrix2x2 matrix4,
|
||||||
float weight5, in SPMatrix2x2 matrix5,
|
float weight5, in F32Matrix2x2 matrix5,
|
||||||
out SPMatrix2x2 sum)
|
out F32Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
||||||
|
|
||||||
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4) + matrix5.r2c1 * weight5;
|
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4) + matrix5.r2c1 * weight5;
|
||||||
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4) + matrix5.r2c2 * weight5;
|
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4) + matrix5.r2c2 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetRightProduct(in SPMatrix2x2 matrix, in SPVector2 vector, out SPVector2 result)
|
public static void GetRightProduct(in F32Matrix2x2 matrix, in F32Vector2 vector, out F32Vector2 result)
|
||||||
{
|
{
|
||||||
float x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
float x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
||||||
float x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
float x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
||||||
|
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetLeftProduct(in SPVector2 vector, in SPMatrix2x2 matrix, out SPVector2 result)
|
public static void GetLeftProduct(in F32Vector2 vector, in F32Matrix2x2 matrix, out F32Vector2 result)
|
||||||
{
|
{
|
||||||
float x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
float x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
||||||
float x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
float x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
||||||
|
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadZero(out SPMatrix2x2 matrix)
|
public static void LoadZero(out F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = 0.0f;
|
matrix.r1c1 = 0.0f;
|
||||||
matrix.r1c2 = 0.0f;
|
matrix.r1c2 = 0.0f;
|
||||||
|
|
||||||
matrix.r2c1 = 0.0f;
|
matrix.r2c1 = 0.0f;
|
||||||
matrix.r2c2 = 0.0f;
|
matrix.r2c2 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadIdentity(out SPMatrix2x2 matrix)
|
public static void LoadIdentity(out F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = 1.0f;
|
matrix.r1c1 = 1.0f;
|
||||||
matrix.r1c2 = 0.0f;
|
matrix.r1c2 = 0.0f;
|
||||||
|
|
||||||
matrix.r2c1 = 0.0f;
|
matrix.r2c1 = 0.0f;
|
||||||
matrix.r2c2 = 1.0f;
|
matrix.r2c2 = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadDiagonal(float d1, float d2, out SPMatrix2x2 matrix)
|
public static void LoadDiagonal(float d1, float d2, out F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = d1;
|
matrix.r1c1 = d1;
|
||||||
matrix.r1c2 = 0.0f;
|
matrix.r1c2 = 0.0f;
|
||||||
|
|
||||||
matrix.r2c1 = 0.0f;
|
matrix.r2c1 = 0.0f;
|
||||||
matrix.r2c2 = d2;
|
matrix.r2c2 = d2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,15 +20,15 @@ using System;
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 11 Nov 2024
|
* Date: 11 Nov 2024
|
||||||
*/
|
*/
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPMatrix2x3
|
public struct F32Matrix2x3
|
||||||
{
|
{
|
||||||
public float r1c1, r1c2;
|
public float r1c1, r1c2;
|
||||||
public float r2c1, r2c2;
|
public float r2c1, r2c2;
|
||||||
public float r3c1, r3c2;
|
public float r3c1, r3c2;
|
||||||
|
|
||||||
public SPMatrix2x3()
|
public F32Matrix2x3()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0f;
|
this.r1c1 = 0.0f;
|
||||||
this.r1c2 = 0.0f;
|
this.r1c2 = 0.0f;
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Geometry
|
||||||
this.r3c2 = 0.0f;
|
this.r3c2 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix2x3(in SPMatrix2x3 matrix)
|
public F32Matrix2x3(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r3c2;
|
this.r3c2 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix2x3(in DPMatrix2x3 matrix)
|
public F32Matrix2x3(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r1c2;
|
this.r1c2 = (float) matrix.r1c2;
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Geometry
|
||||||
this.r3c2 = (float) matrix.r3c2;
|
this.r3c2 = (float) matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix2x3(in SPMatrix3x2 matrix)
|
public F32Matrix2x3(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -76,7 +76,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r2c3;
|
this.r3c2 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix2x3(in DPMatrix3x2 matrix)
|
public F32Matrix2x3(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r2c1;
|
this.r1c2 = (float) matrix.r2c1;
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Geometry
|
||||||
this.r3c2 = 0.0f;
|
this.r3c2 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPMatrix2x3 matrix)
|
public void SetValues(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -112,7 +112,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r3c2;
|
this.r3c2 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPMatrix2x3 matrix)
|
public void SetValues(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r1c2;
|
this.r1c2 = (float) matrix.r1c2;
|
||||||
|
|
@ -124,7 +124,7 @@ namespace Geometry
|
||||||
this.r3c2 = (float) matrix.r3c2;
|
this.r3c2 = (float) matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in SPMatrix3x2 matrix)
|
public void SetTransposed(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r2c3;
|
this.r3c2 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in DPMatrix3x2 matrix)
|
public void SetTransposed(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r2c1;
|
this.r1c2 = (float) matrix.r2c1;
|
||||||
|
|
@ -180,7 +180,7 @@ namespace Geometry
|
||||||
this.r3c2 = r3;
|
this.r3c2 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in SPMatrix2x3 matrix1, in SPMatrix2x3 matrix2, out SPMatrix2x3 sum)
|
public static void Add(in F32Matrix2x3 matrix1, in F32Matrix2x3 matrix2, out F32Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
||||||
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Geometry
|
||||||
sum.r3c2 = matrix1.r3c2 + matrix2.r3c2;
|
sum.r3c2 = matrix1.r3c2 + matrix2.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in SPMatrix2x3 minuend, in SPMatrix2x3 subtrahend, out SPMatrix2x3 difference)
|
public static void Subtract(in F32Matrix2x3 minuend, in F32Matrix2x3 subtrahend, out F32Matrix2x3 difference)
|
||||||
{
|
{
|
||||||
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
||||||
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
||||||
|
|
@ -204,7 +204,7 @@ namespace Geometry
|
||||||
difference.r3c2 = minuend.r3c2 - subtrahend.r3c2;
|
difference.r3c2 = minuend.r3c2 - subtrahend.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in SPMatrix2x3 multiplicand, float multiplier, out SPMatrix2x3 product)
|
public static void Multiply(in F32Matrix2x3 multiplicand, float multiplier, out F32Matrix2x3 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = multiplicand.r1c1 * multiplier;
|
product.r1c1 = multiplicand.r1c1 * multiplier;
|
||||||
product.r1c2 = multiplicand.r1c2 * multiplier;
|
product.r1c2 = multiplicand.r1c2 * multiplier;
|
||||||
|
|
@ -216,7 +216,7 @@ namespace Geometry
|
||||||
product.r3c2 = multiplicand.r3c2 * multiplier;
|
product.r3c2 = multiplicand.r3c2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in SPMatrix2x3 dividend, float divisor, out SPMatrix2x3 quotient)
|
public static void Divide(in F32Matrix2x3 dividend, float divisor, out F32Matrix2x3 quotient)
|
||||||
{
|
{
|
||||||
quotient.r1c1 = dividend.r1c1 / divisor;
|
quotient.r1c1 = dividend.r1c1 / divisor;
|
||||||
quotient.r1c2 = dividend.r1c2 / divisor;
|
quotient.r1c2 = dividend.r1c2 / divisor;
|
||||||
|
|
@ -229,9 +229,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
float weight1, in SPMatrix2x3 matrix1,
|
float weight1, in F32Matrix2x3 matrix1,
|
||||||
float weight2, in SPMatrix2x3 matrix2,
|
float weight2, in F32Matrix2x3 matrix2,
|
||||||
out SPMatrix2x3 sum)
|
out F32Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
||||||
|
|
@ -244,10 +244,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
float weight1, in SPMatrix2x3 matrix1,
|
float weight1, in F32Matrix2x3 matrix1,
|
||||||
float weight2, in SPMatrix2x3 matrix2,
|
float weight2, in F32Matrix2x3 matrix2,
|
||||||
float weight3, in SPMatrix2x3 matrix3,
|
float weight3, in F32Matrix2x3 matrix3,
|
||||||
out SPMatrix2x3 sum)
|
out F32Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
||||||
|
|
@ -260,11 +260,11 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
float weight1, in SPMatrix2x3 matrix1,
|
float weight1, in F32Matrix2x3 matrix1,
|
||||||
float weight2, in SPMatrix2x3 matrix2,
|
float weight2, in F32Matrix2x3 matrix2,
|
||||||
float weight3, in SPMatrix2x3 matrix3,
|
float weight3, in F32Matrix2x3 matrix3,
|
||||||
float weight4, in SPMatrix2x3 matrix4,
|
float weight4, in F32Matrix2x3 matrix4,
|
||||||
out SPMatrix2x3 sum)
|
out F32Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
||||||
|
|
@ -277,12 +277,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
float weight1, in SPMatrix2x3 matrix1,
|
float weight1, in F32Matrix2x3 matrix1,
|
||||||
float weight2, in SPMatrix2x3 matrix2,
|
float weight2, in F32Matrix2x3 matrix2,
|
||||||
float weight3, in SPMatrix2x3 matrix3,
|
float weight3, in F32Matrix2x3 matrix3,
|
||||||
float weight4, in SPMatrix2x3 matrix4,
|
float weight4, in F32Matrix2x3 matrix4,
|
||||||
float weight5, in SPMatrix2x3 matrix5,
|
float weight5, in F32Matrix2x3 matrix5,
|
||||||
out SPMatrix2x3 sum)
|
out F32Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
||||||
|
|
@ -294,14 +294,14 @@ namespace Geometry
|
||||||
sum.r3c2 = (matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2) + (matrix3.r3c2 * weight3 + matrix4.r3c2 * weight4) + matrix5.r3c2 * weight5;
|
sum.r3c2 = (matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2) + (matrix3.r3c2 * weight3 + matrix4.r3c2 * weight4) + matrix5.r3c2 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetRightProduct(in SPMatrix2x3 matrix, in SPVector2 vector, out SPVector3 result)
|
public static void GetRightProduct(in F32Matrix2x3 matrix, in F32Vector2 vector, out F32Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
||||||
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
||||||
result.x3 = matrix.r3c1 * vector.x1 + matrix.r3c2 * vector.x2;
|
result.x3 = matrix.r3c1 * vector.x1 + matrix.r3c2 * vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetLeftProduct(in SPVector3 vector, in SPMatrix2x3 matrix, out SPVector2 result)
|
public static void GetLeftProduct(in F32Vector3 vector, in F32Matrix2x3 matrix, out F32Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1 + vector.x3 * matrix.r3c1;
|
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1 + vector.x3 * matrix.r3c1;
|
||||||
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2 + vector.x3 * matrix.r3c2;
|
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2 + vector.x3 * matrix.r3c2;
|
||||||
|
|
@ -18,14 +18,14 @@
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 11 Nov 2024
|
* Date: 11 Nov 2024
|
||||||
*/
|
*/
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPMatrix3x2
|
public struct F32Matrix3x2
|
||||||
{
|
{
|
||||||
public float r1c1, r1c2, r1c3;
|
public float r1c1, r1c2, r1c3;
|
||||||
public float r2c1, r2c2, r2c3;
|
public float r2c1, r2c2, r2c3;
|
||||||
|
|
||||||
public SPMatrix3x2()
|
public F32Matrix3x2()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0f;
|
this.r1c1 = 0.0f;
|
||||||
this.r1c2 = 0.0f;
|
this.r1c2 = 0.0f;
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Geometry
|
||||||
this.r2c3 = 0.0f;
|
this.r2c3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix3x2(in SPMatrix3x2 matrix)
|
public F32Matrix3x2(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -47,7 +47,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c3;
|
this.r2c3 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix3x2(in DPMatrix3x2 matrix)
|
public F32Matrix3x2(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r1c2;
|
this.r1c2 = (float) matrix.r1c2;
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Geometry
|
||||||
this.r2c3 = (float) matrix.r2c3;
|
this.r2c3 = (float) matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix3x2(in SPMatrix2x3 matrix)
|
public F32Matrix3x2(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -69,7 +69,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r3c2;
|
this.r2c3 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPMatrix3x2(in DPMatrix2x3 matrix)
|
public F32Matrix3x2(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r2c1;
|
this.r1c2 = (float) matrix.r2c1;
|
||||||
|
|
@ -91,7 +91,7 @@ namespace Geometry
|
||||||
this.r2c3 = 0.0f;
|
this.r2c3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPMatrix3x2 matrix)
|
public void SetValues(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -102,7 +102,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c3;
|
this.r2c3 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPMatrix3x2 matrix)
|
public void SetValues(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r1c2;
|
this.r1c2 = (float) matrix.r1c2;
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Geometry
|
||||||
this.r2c3 = (float) matrix.r2c3;
|
this.r2c3 = (float) matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in SPMatrix2x3 matrix)
|
public void SetTransposed(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -124,7 +124,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r3c2;
|
this.r2c3 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in DPMatrix2x3 matrix)
|
public void SetTransposed(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = (float) matrix.r1c1;
|
this.r1c1 = (float) matrix.r1c1;
|
||||||
this.r1c2 = (float) matrix.r2c1;
|
this.r1c2 = (float) matrix.r2c1;
|
||||||
|
|
@ -167,7 +167,7 @@ namespace Geometry
|
||||||
this.r2c3 = r2;
|
this.r2c3 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in SPMatrix3x2 matrix1, in SPMatrix3x2 matrix2, out SPMatrix3x2 sum)
|
public static void Add(in F32Matrix3x2 matrix1, in F32Matrix3x2 matrix2, out F32Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
||||||
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
||||||
|
|
@ -178,7 +178,7 @@ namespace Geometry
|
||||||
sum.r2c3 = matrix1.r2c3 + matrix2.r2c3;
|
sum.r2c3 = matrix1.r2c3 + matrix2.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in SPMatrix3x2 minuend, in SPMatrix3x2 subtrahend, out SPMatrix3x2 difference)
|
public static void Subtract(in F32Matrix3x2 minuend, in F32Matrix3x2 subtrahend, out F32Matrix3x2 difference)
|
||||||
{
|
{
|
||||||
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
||||||
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
||||||
|
|
@ -189,7 +189,7 @@ namespace Geometry
|
||||||
difference.r2c3 = minuend.r2c3 - subtrahend.r2c3;
|
difference.r2c3 = minuend.r2c3 - subtrahend.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in SPMatrix3x2 multiplicand, float multiplier, out SPMatrix3x2 product)
|
public static void Multiply(in F32Matrix3x2 multiplicand, float multiplier, out F32Matrix3x2 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = multiplicand.r1c1 * multiplier;
|
product.r1c1 = multiplicand.r1c1 * multiplier;
|
||||||
product.r1c2 = multiplicand.r1c2 * multiplier;
|
product.r1c2 = multiplicand.r1c2 * multiplier;
|
||||||
|
|
@ -200,7 +200,7 @@ namespace Geometry
|
||||||
product.r2c3 = multiplicand.r2c3 * multiplier;
|
product.r2c3 = multiplicand.r2c3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in SPMatrix3x2 dividend, float divisor, out SPMatrix3x2 quotient)
|
public static void Divide(in F32Matrix3x2 dividend, float divisor, out F32Matrix3x2 quotient)
|
||||||
{
|
{
|
||||||
quotient.r1c1 = dividend.r1c1 / divisor;
|
quotient.r1c1 = dividend.r1c1 / divisor;
|
||||||
quotient.r1c2 = dividend.r1c2 / divisor;
|
quotient.r1c2 = dividend.r1c2 / divisor;
|
||||||
|
|
@ -212,9 +212,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
float weight1, in SPMatrix3x2 matrix1,
|
float weight1, in F32Matrix3x2 matrix1,
|
||||||
float weight2, in SPMatrix3x2 matrix2,
|
float weight2, in F32Matrix3x2 matrix2,
|
||||||
out SPMatrix3x2 sum)
|
out F32Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
||||||
|
|
@ -226,10 +226,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
float weight1, in SPMatrix3x2 matrix1,
|
float weight1, in F32Matrix3x2 matrix1,
|
||||||
float weight2, in SPMatrix3x2 matrix2,
|
float weight2, in F32Matrix3x2 matrix2,
|
||||||
float weight3, in SPMatrix3x2 matrix3,
|
float weight3, in F32Matrix3x2 matrix3,
|
||||||
out SPMatrix3x2 sum)
|
out F32Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
||||||
|
|
@ -241,11 +241,11 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
float weight1, in SPMatrix3x2 matrix1,
|
float weight1, in F32Matrix3x2 matrix1,
|
||||||
float weight2, in SPMatrix3x2 matrix2,
|
float weight2, in F32Matrix3x2 matrix2,
|
||||||
float weight3, in SPMatrix3x2 matrix3,
|
float weight3, in F32Matrix3x2 matrix3,
|
||||||
float weight4, in SPMatrix3x2 matrix4,
|
float weight4, in F32Matrix3x2 matrix4,
|
||||||
out SPMatrix3x2 sum)
|
out F32Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
||||||
|
|
@ -257,12 +257,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
float weight1, in SPMatrix3x2 matrix1,
|
float weight1, in F32Matrix3x2 matrix1,
|
||||||
float weight2, in SPMatrix3x2 matrix2,
|
float weight2, in F32Matrix3x2 matrix2,
|
||||||
float weight3, in SPMatrix3x2 matrix3,
|
float weight3, in F32Matrix3x2 matrix3,
|
||||||
float weight4, in SPMatrix3x2 matrix4,
|
float weight4, in F32Matrix3x2 matrix4,
|
||||||
float weight5, in SPMatrix3x2 matrix5,
|
float weight5, in F32Matrix3x2 matrix5,
|
||||||
out SPMatrix3x2 sum)
|
out F32Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
||||||
|
|
@ -273,13 +273,13 @@ namespace Geometry
|
||||||
sum.r2c3 = (matrix1.r2c3 * weight1 + matrix2.r2c3 * weight2) + (matrix3.r2c3 * weight3 + matrix4.r2c3 * weight4) + matrix5.r2c3 * weight5;
|
sum.r2c3 = (matrix1.r2c3 * weight1 + matrix2.r2c3 * weight2) + (matrix3.r2c3 * weight3 + matrix4.r2c3 * weight4) + matrix5.r2c3 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetRightProduct(in SPMatrix3x2 matrix, in SPVector3 vector, out SPVector2 result)
|
public static void GetRightProduct(in F32Matrix3x2 matrix, in F32Vector3 vector, out F32Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2 + matrix.r1c3 * vector.x3;
|
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2 + matrix.r1c3 * vector.x3;
|
||||||
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2 + matrix.r2c3 * vector.x3;
|
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2 + matrix.r2c3 * vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetLeftProduct(in SPVector2 vector, in SPMatrix3x2 matrix, out SPVector3 result)
|
public static void GetLeftProduct(in F32Vector2 vector, in F32Matrix3x2 matrix, out F32Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
||||||
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -20,11 +20,11 @@ using System;
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 11 Nov 2024
|
* Date: 11 Nov 2024
|
||||||
*/
|
*/
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public class SPMatrixProduct
|
public class F32MatrixProduct
|
||||||
{
|
{
|
||||||
public static void Get2x2At2x2(in SPMatrix2x2 left, in SPMatrix2x2 right, out SPMatrix2x2 product)
|
public static void Get2x2At2x2(in F32Matrix2x2 left, in F32Matrix2x2 right, out F32Matrix2x2 product)
|
||||||
{
|
{
|
||||||
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Geometry
|
||||||
product.r2c2 = r2c2;
|
product.r2c2 = r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get2x2At3x2(in SPMatrix2x2 left, in SPMatrix3x2 right, out SPMatrix3x2 product)
|
public static void Get2x2At3x2(in F32Matrix2x2 left, in F32Matrix3x2 right, out F32Matrix3x2 product)
|
||||||
{
|
{
|
||||||
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Geometry
|
||||||
product.r2c3 = r2c3;
|
product.r2c3 = r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get2x3At2x2(in SPMatrix2x3 left, in SPMatrix2x2 right, out SPMatrix2x3 product)
|
public static void Get2x3At2x2(in F32Matrix2x3 left, in F32Matrix2x2 right, out F32Matrix2x3 product)
|
||||||
{
|
{
|
||||||
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -79,7 +79,7 @@ namespace Geometry
|
||||||
product.r3c2 = r3c2;
|
product.r3c2 = r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get2x3At3x2(in SPMatrix2x3 left, in SPMatrix3x2 right, out SPMatrix3x3 product)
|
public static void Get2x3At3x2(in F32Matrix2x3 left, in F32Matrix3x2 right, out F32Matrix3x3 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Geometry
|
||||||
product.r3c3 = left.r3c1 * right.r1c2 + left.r3c2 * right.r2c3;
|
product.r3c3 = left.r3c1 * right.r1c2 + left.r3c2 * right.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x2At3x3(in SPMatrix3x2 left, in SPMatrix3x3 right, out SPMatrix3x2 product)
|
public static void Get3x2At3x3(in F32Matrix3x2 left, in F32Matrix3x3 right, out F32Matrix3x2 product)
|
||||||
{
|
{
|
||||||
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Geometry
|
||||||
product.r2c3 = r2c3;
|
product.r2c3 = r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x2At2x3(in SPMatrix3x2 left, in SPMatrix2x3 right, out SPMatrix2x2 product)
|
public static void Get3x2At2x3(in F32Matrix3x2 left, in F32Matrix2x3 right, out F32Matrix2x2 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -122,7 +122,7 @@ namespace Geometry
|
||||||
product.r2c2 = left.r2c1 * right.r1c2 + left.r2c2 * right.r2c2 + left.r2c3 * right.r3c2;
|
product.r2c2 = left.r2c1 * right.r1c2 + left.r2c2 * right.r2c2 + left.r2c3 * right.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x3At2x3(in SPMatrix3x3 left, in SPMatrix2x3 right, out SPMatrix2x3 product)
|
public static void Get3x3At2x3(in F32Matrix3x3 left, in F32Matrix2x3 right, out F32Matrix2x3 product)
|
||||||
{
|
{
|
||||||
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -143,7 +143,7 @@ namespace Geometry
|
||||||
product.r3c2 = r3c2;
|
product.r3c2 = r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x3At3x3(in SPMatrix3x3 left, in SPMatrix3x3 right, out SPMatrix3x3 product)
|
public static void Get3x3At3x3(in F32Matrix3x3 left, in F32Matrix3x3 right, out F32Matrix3x3 product)
|
||||||
{
|
{
|
||||||
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
float r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
float r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -1,203 +1,203 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPQuaternion
|
public struct F32Quaternion
|
||||||
{
|
{
|
||||||
public float s0, x1, x2, x3;
|
public float s0, x1, x2, x3;
|
||||||
|
|
||||||
public SPQuaternion(float s0, float x1, float x2, float x3)
|
public F32Quaternion(float s0, float x1, float x2, float x3)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPQuaternion(in SPQuaternion quaternion)
|
public F32Quaternion(in F32Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = quaternion.x1;
|
this.x1 = quaternion.x1;
|
||||||
this.x2 = quaternion.x2;
|
this.x2 = quaternion.x2;
|
||||||
this.x3 = quaternion.x3;
|
this.x3 = quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPQuaternion(in DPQuaternion quaternion)
|
public F32Quaternion(in F64Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = (float)quaternion.s0;
|
this.s0 = (float)quaternion.s0;
|
||||||
this.x1 = (float)quaternion.x1;
|
this.x1 = (float)quaternion.x1;
|
||||||
this.x2 = (float)quaternion.x2;
|
this.x2 = (float)quaternion.x2;
|
||||||
this.x3 = (float)quaternion.x3;
|
this.x3 = (float)quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
this.s0 = 0.0f;
|
this.s0 = 0.0f;
|
||||||
this.x1 = 0.0f;
|
this.x1 = 0.0f;
|
||||||
this.x2 = 0.0f;
|
this.x2 = 0.0f;
|
||||||
this.x3 = 0.0f;
|
this.x3 = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Conjugate()
|
public void Conjugate()
|
||||||
{
|
{
|
||||||
this.x1 = -this.x1;
|
this.x1 = -this.x1;
|
||||||
this.x2 = -this.x2;
|
this.x2 = -this.x2;
|
||||||
this.x3 = -this.x3;
|
this.x3 = -this.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(float s0, float x1, float x2, float x3)
|
public void SetValues(float s0, float x1, float x2, float x3)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPQuaternion quaternion)
|
public void SetValues(in F32Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = quaternion.x1;
|
this.x1 = quaternion.x1;
|
||||||
this.x2 = quaternion.x2;
|
this.x2 = quaternion.x2;
|
||||||
this.x3 = quaternion.x3;
|
this.x3 = quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPQuaternion quaternion)
|
public void SetValues(in F64Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = (float)quaternion.s0;
|
this.s0 = (float)quaternion.s0;
|
||||||
this.x1 = (float)quaternion.x1;
|
this.x1 = (float)quaternion.x1;
|
||||||
this.x2 = (float)quaternion.x2;
|
this.x2 = (float)quaternion.x2;
|
||||||
this.x3 = (float)quaternion.x3;
|
this.x3 = (float)quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetConjugateOf(in SPQuaternion quaternion)
|
public void SetConjugateOf(in F32Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = -quaternion.x1;
|
this.x1 = -quaternion.x1;
|
||||||
this.x2 = -quaternion.x2;
|
this.x2 = -quaternion.x2;
|
||||||
this.x3 = -quaternion.x3;
|
this.x3 = -quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeRotationMatrix(out SPMatrix3x3 matrix)
|
public readonly void MakeRotationMatrix(out F32Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
float s0s0 = this.s0 * this.s0;
|
float s0s0 = this.s0 * this.s0;
|
||||||
float x1x1 = this.x1 * this.x1;
|
float x1x1 = this.x1 * this.x1;
|
||||||
float x2x2 = this.x2 * this.x2;
|
float x2x2 = this.x2 * this.x2;
|
||||||
float x3x3 = this.x3 * this.x3;
|
float x3x3 = this.x3 * this.x3;
|
||||||
|
|
||||||
float squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
float squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-SPUtility.EPSYLON <= squareModule && squareModule <= SPUtility.EPSYLON)
|
if (-F32Utility.EPSYLON <= squareModule && squareModule <= F32Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
SPMatrix3x3.LoadIdentity(out matrix);
|
F32Matrix3x3.LoadIdentity(out matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float corrector1;
|
float corrector1;
|
||||||
float corrector2;
|
float corrector2;
|
||||||
|
|
||||||
if (1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + SPUtility.TWO_EPSYLON) {
|
if (1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + F32Utility.TWO_EPSYLON) {
|
||||||
corrector1 = 2.0f - squareModule;
|
corrector1 = 2.0f - squareModule;
|
||||||
corrector2 = 2.0f * corrector1;
|
corrector2 = 2.0f * corrector1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
corrector1 = 1.0f / squareModule;
|
corrector1 = 1.0f / squareModule;
|
||||||
corrector2 = 2.0f / squareModule;
|
corrector2 = 2.0f / squareModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
float s0x1 = this.s0 * this.x1;
|
float s0x1 = this.s0 * this.x1;
|
||||||
float s0x2 = this.s0 * this.x2;
|
float s0x2 = this.s0 * this.x2;
|
||||||
float s0x3 = this.s0 * this.x3;
|
float s0x3 = this.s0 * this.x3;
|
||||||
float x1x2 = this.x1 * this.x2;
|
float x1x2 = this.x1 * this.x2;
|
||||||
float x1x3 = this.x1 * this.x3;
|
float x1x3 = this.x1 * this.x3;
|
||||||
float x2x3 = this.x2 * this.x3;
|
float x2x3 = this.x2 * this.x3;
|
||||||
|
|
||||||
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||||
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||||
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||||
|
|
||||||
matrix.r1c2 = corrector2 * (x1x2 - s0x3);
|
matrix.r1c2 = corrector2 * (x1x2 - s0x3);
|
||||||
matrix.r2c3 = corrector2 * (x2x3 - s0x1);
|
matrix.r2c3 = corrector2 * (x2x3 - s0x1);
|
||||||
matrix.r3c1 = corrector2 * (x1x3 - s0x2);
|
matrix.r3c1 = corrector2 * (x1x3 - s0x2);
|
||||||
|
|
||||||
matrix.r2c1 = corrector2 * (x1x2 + s0x3);
|
matrix.r2c1 = corrector2 * (x1x2 + s0x3);
|
||||||
matrix.r3c2 = corrector2 * (x2x3 + s0x1);
|
matrix.r3c2 = corrector2 * (x2x3 + s0x1);
|
||||||
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeReverseMatrix(out SPMatrix3x3 matrix)
|
public readonly void MakeReverseMatrix(out F32Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
float s0s0 = this.s0 * this.s0;
|
float s0s0 = this.s0 * this.s0;
|
||||||
float x1x1 = this.x1 * this.x1;
|
float x1x1 = this.x1 * this.x1;
|
||||||
float x2x2 = this.x2 * this.x2;
|
float x2x2 = this.x2 * this.x2;
|
||||||
float x3x3 = this.x3 * this.x3;
|
float x3x3 = this.x3 * this.x3;
|
||||||
|
|
||||||
float squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
float squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-SPUtility.EPSYLON <= squareModule && squareModule <= SPUtility.EPSYLON)
|
if (-F32Utility.EPSYLON <= squareModule && squareModule <= F32Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
SPMatrix3x3.LoadIdentity(out matrix);
|
F32Matrix3x3.LoadIdentity(out matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float corrector1;
|
float corrector1;
|
||||||
float corrector2;
|
float corrector2;
|
||||||
|
|
||||||
if (1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + SPUtility.TWO_EPSYLON) {
|
if (1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + F32Utility.TWO_EPSYLON) {
|
||||||
corrector1 = 2.0f - squareModule;
|
corrector1 = 2.0f - squareModule;
|
||||||
corrector2 = 2.0f * corrector1;
|
corrector2 = 2.0f * corrector1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
corrector1 = 1.0f / squareModule;
|
corrector1 = 1.0f / squareModule;
|
||||||
corrector2 = 2.0f / squareModule;
|
corrector2 = 2.0f / squareModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
float s0x1 = this.s0 * this.x1;
|
float s0x1 = this.s0 * this.x1;
|
||||||
float s0x2 = this.s0 * this.x2;
|
float s0x2 = this.s0 * this.x2;
|
||||||
float s0x3 = this.s0 * this.x3;
|
float s0x3 = this.s0 * this.x3;
|
||||||
float x1x2 = this.x1 * this.x2;
|
float x1x2 = this.x1 * this.x2;
|
||||||
float x1x3 = this.x1 * this.x3;
|
float x1x3 = this.x1 * this.x3;
|
||||||
float x2x3 = this.x2 * this.x3;
|
float x2x3 = this.x2 * this.x3;
|
||||||
|
|
||||||
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||||
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||||
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||||
|
|
||||||
matrix.r1c2 = corrector2 * (x1x2 + s0x3);
|
matrix.r1c2 = corrector2 * (x1x2 + s0x3);
|
||||||
matrix.r2c3 = corrector2 * (x2x3 + s0x1);
|
matrix.r2c3 = corrector2 * (x2x3 + s0x1);
|
||||||
matrix.r3c1 = corrector2 * (x1x3 + s0x2);
|
matrix.r3c1 = corrector2 * (x1x3 + s0x2);
|
||||||
|
|
||||||
matrix.r2c1 = corrector2 * (x1x2 - s0x3);
|
matrix.r2c1 = corrector2 * (x1x2 - s0x3);
|
||||||
matrix.r3c2 = corrector2 * (x2x3 - s0x1);
|
matrix.r3c2 = corrector2 * (x2x3 - s0x1);
|
||||||
matrix.r1c3 = corrector2 * (x1x3 - s0x2);
|
matrix.r1c3 = corrector2 * (x1x3 - s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in SPQuaternion quaternion1, in SPQuaternion quaternion2, out SPQuaternion sum)
|
public static void Add(in F32Quaternion quaternion1, in F32Quaternion quaternion2, out F32Quaternion sum)
|
||||||
{
|
{
|
||||||
sum.s0 = quaternion1.s0 + quaternion2.s0;
|
sum.s0 = quaternion1.s0 + quaternion2.s0;
|
||||||
sum.x1 = quaternion1.x1 + quaternion2.x1;
|
sum.x1 = quaternion1.x1 + quaternion2.x1;
|
||||||
sum.x2 = quaternion1.x2 + quaternion2.x2;
|
sum.x2 = quaternion1.x2 + quaternion2.x2;
|
||||||
sum.x3 = quaternion1.x3 + quaternion2.x3;
|
sum.x3 = quaternion1.x3 + quaternion2.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in SPQuaternion minuend, in SPQuaternion subtrahend, out SPQuaternion difference)
|
public static void Subtract(in F32Quaternion minuend, in F32Quaternion subtrahend, out F32Quaternion difference)
|
||||||
{
|
{
|
||||||
difference.s0 = minuend.s0 - subtrahend.s0;
|
difference.s0 = minuend.s0 - subtrahend.s0;
|
||||||
difference.x1 = minuend.x1 - subtrahend.x1;
|
difference.x1 = minuend.x1 - subtrahend.x1;
|
||||||
difference.x2 = minuend.x2 - subtrahend.x2;
|
difference.x2 = minuend.x2 - subtrahend.x2;
|
||||||
difference.x3 = minuend.x3 - subtrahend.x3;
|
difference.x3 = minuend.x3 - subtrahend.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in SPQuaternion left, in SPQuaternion right, out SPQuaternion product)
|
public static void Multiply(in F32Quaternion left, in F32Quaternion right, out F32Quaternion product)
|
||||||
{
|
{
|
||||||
float s0 = (left.s0 * right.s0 - left.x1 * right.x1) - (left.x2 * right.x2 + left.x3 * right.x3);
|
float s0 = (left.s0 * right.s0 - left.x1 * right.x1) - (left.x2 * right.x2 + left.x3 * right.x3);
|
||||||
float x1 = (left.x1 * right.s0 + left.s0 * right.x1) - (left.x3 * right.x2 - left.x2 * right.x3);
|
float x1 = (left.x1 * right.s0 + left.s0 * right.x1) - (left.x3 * right.x2 - left.x2 * right.x3);
|
||||||
float x2 = (left.x2 * right.s0 + left.s0 * right.x2) - (left.x1 * right.x3 - left.x3 * right.x1);
|
float x2 = (left.x2 * right.s0 + left.s0 * right.x2) - (left.x1 * right.x3 - left.x3 * right.x1);
|
||||||
float x3 = (left.x3 * right.s0 + left.s0 * right.x3) - (left.x2 * right.x1 - left.x1 * right.x2);
|
float x3 = (left.x3 * right.s0 + left.s0 * right.x3) - (left.x2 * right.x1 - left.x1 * right.x2);
|
||||||
|
|
||||||
product.s0 = s0;
|
product.s0 = s0;
|
||||||
product.x1 = x1;
|
product.x1 = x1;
|
||||||
product.x2 = x2;
|
product.x2 = x2;
|
||||||
product.x3 = x3;
|
product.x3 = x3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
76
BGC/F32Radians.cs
Normal file
76
BGC/F32Radians.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 18 Nov 2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public class F32Radians
|
||||||
|
{
|
||||||
|
public const float PI = 3.1415926536f;
|
||||||
|
public const float TWO_PI = 6.2831853072f;
|
||||||
|
public const float HALF_OF_PI = 1.5707963268f;
|
||||||
|
public const float THIRD_OF_PI = 1.0471975512f;
|
||||||
|
public const float FOURTH_OF_PI = 0.7853981634f;
|
||||||
|
public const float SIXTH_OF_PI = 0.5235987756f;
|
||||||
|
|
||||||
|
public const float DEGREES_IN_RADIAN = 57.295779513f;
|
||||||
|
public const float TURNS_IN_RADIAN = 0.1591549431f;
|
||||||
|
|
||||||
|
public static float ToDegrees(float radians)
|
||||||
|
{
|
||||||
|
return radians * DEGREES_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToTurns(float radians)
|
||||||
|
{
|
||||||
|
return radians * TURNS_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToUnits(float radians, AngleUnit toUnit)
|
||||||
|
{
|
||||||
|
if (toUnit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return radians * DEGREES_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUnit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return radians * TURNS_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float Normalize(float radians, AngleRange range)
|
||||||
|
{
|
||||||
|
if (range == AngleRange.UNSIGNED_RANGE)
|
||||||
|
{
|
||||||
|
if (0.0 <= radians && radians < TWO_PI)
|
||||||
|
{
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (-PI < radians && radians <= PI)
|
||||||
|
{
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float turns = radians * TURNS_IN_RADIAN;
|
||||||
|
|
||||||
|
turns -= MathF.Floor(turns);
|
||||||
|
|
||||||
|
if (range == AngleRange.SIGNED_RANGE && turns > 0.5f)
|
||||||
|
{
|
||||||
|
turns -= 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return turns * TWO_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,15 +21,15 @@ using System;
|
||||||
* Date: 2 Feb 2019
|
* Date: 2 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPRotation3
|
public struct F32Rotation3
|
||||||
{
|
{
|
||||||
private float angle;
|
private float angle;
|
||||||
|
|
||||||
private SPVector3 axis;
|
private F32Vector3 axis;
|
||||||
|
|
||||||
public SPRotation3(SPRotation3 rotation)
|
public F32Rotation3(F32Rotation3 rotation)
|
||||||
{
|
{
|
||||||
this.angle = rotation.angle;
|
this.angle = rotation.angle;
|
||||||
this.axis = rotation.axis;
|
this.axis = rotation.axis;
|
||||||
63
BGC/F32Turns.cs
Normal file
63
BGC/F32Turns.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 18 Nov 2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public class F32Turns
|
||||||
|
{
|
||||||
|
public static float ToRadians(float turns)
|
||||||
|
{
|
||||||
|
return turns * F32Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToDegrees(float turns)
|
||||||
|
{
|
||||||
|
return turns * 360.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ToUnits(float turns, AngleUnit toUnit)
|
||||||
|
{
|
||||||
|
if (toUnit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return turns * F32Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUnit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return turns * 360.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return turns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float Normalize(float turns, AngleRange range)
|
||||||
|
{
|
||||||
|
if (range == AngleRange.UNSIGNED_RANGE)
|
||||||
|
{
|
||||||
|
if (0.0f <= turns && turns < 1.0f)
|
||||||
|
{
|
||||||
|
return turns;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (-0.5f < turns && turns <= 0.5f)
|
||||||
|
{
|
||||||
|
return turns;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float rest = turns - MathF.Floor(turns);
|
||||||
|
|
||||||
|
if (range == AngleRange.SIGNED_RANGE && rest > 0.5f)
|
||||||
|
{
|
||||||
|
rest -= 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public class SPUtility
|
public class F32Utility
|
||||||
{
|
{
|
||||||
public const float EPSYLON = 5E-7f;
|
public const float EPSYLON = 5E-7f;
|
||||||
public const float TWO_EPSYLON = 1E-6f;
|
public const float TWO_EPSYLON = 1E-6f;
|
||||||
public const float SQUARE_EPSYLON = 2.5E-13f;
|
public const float SQUARE_EPSYLON = 2.5E-13f;
|
||||||
|
|
||||||
public const float EPSYLON_EFFECTIVENESS_LIMIT = 1.0f;
|
public const float EPSYLON_EFFECTIVENESS_LIMIT = 1.0f;
|
||||||
|
|
||||||
public const float ONE_THIRD = 0.333333333f;
|
public const float ONE_THIRD = 0.333333333f;
|
||||||
public const float ONE_SIXTH = 0.166666667f;
|
public const float ONE_SIXTH = 0.166666667f;
|
||||||
public const float ONE_NINETH = 0.111111111f;
|
public const float ONE_NINETH = 0.111111111f;
|
||||||
|
|
||||||
public const float GOLDEN_RATIO_HIGH = 1.618034f;
|
public const float GOLDEN_RATIO_HIGH = 1.618034f;
|
||||||
public const float GOLDEN_RATIO_LOW = 0.618034f;
|
public const float GOLDEN_RATIO_LOW = 0.618034f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,28 +21,28 @@ using System;
|
||||||
* Date: 1 Feb 2019
|
* Date: 1 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPVector2
|
public struct F32Vector2
|
||||||
{
|
{
|
||||||
public static readonly SPVector2 ZERO = new SPVector2(0.0f, 0.0f);
|
public static readonly F32Vector2 ZERO = new F32Vector2(0.0f, 0.0f);
|
||||||
|
|
||||||
public float x1;
|
public float x1;
|
||||||
public float x2;
|
public float x2;
|
||||||
|
|
||||||
public SPVector2(float x1, float x2)
|
public F32Vector2(float x1, float x2)
|
||||||
{
|
{
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVector2(in SPVector2 vector)
|
public F32Vector2(in F32Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVector2(in DPVector2 vector)
|
public F32Vector2(in F64Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = (float)vector.x1;
|
this.x1 = (float)vector.x1;
|
||||||
this.x2 = (float)vector.x2;
|
this.x2 = (float)vector.x2;
|
||||||
|
|
@ -62,12 +62,12 @@ namespace Geometry
|
||||||
{
|
{
|
||||||
float squareModule = this.GetSquareModule();
|
float squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + SPUtility.TWO_EPSYLON)
|
if (1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + F32Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -81,23 +81,23 @@ namespace Geometry
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly SPVector2 GetNormalized()
|
public readonly F32Vector2 GetNormalized()
|
||||||
{
|
{
|
||||||
float squareModule = this.GetSquareModule();
|
float squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + SPUtility.TWO_EPSYLON)
|
if (1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + F32Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
float module = MathF.Sqrt(squareModule);
|
float module = MathF.Sqrt(squareModule);
|
||||||
|
|
||||||
return new SPVector2(
|
return new F32Vector2(
|
||||||
this.x1 / module,
|
this.x1 / module,
|
||||||
this.x2 / module
|
this.x2 / module
|
||||||
);
|
);
|
||||||
|
|
@ -111,13 +111,13 @@ namespace Geometry
|
||||||
|
|
||||||
public readonly bool IsZero()
|
public readonly bool IsZero()
|
||||||
{
|
{
|
||||||
return this.GetSquareModule() <= SPUtility.SQUARE_EPSYLON;
|
return this.GetSquareModule() <= F32Utility.SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsUnit()
|
public readonly bool IsUnit()
|
||||||
{
|
{
|
||||||
float squareModule = this.GetSquareModule();
|
float squareModule = this.GetSquareModule();
|
||||||
return 1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= SPUtility.EPSYLON;
|
return 1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= F32Utility.EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
|
|
@ -132,25 +132,25 @@ namespace Geometry
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPVector2 vector)
|
public void SetValues(in F32Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPVector2 vector)
|
public void SetValues(in F64Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = (float)vector.x1;
|
this.x1 = (float)vector.x1;
|
||||||
this.x2 = (float)vector.x2;
|
this.x2 = (float)vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in SPVector2 vector)
|
public void SetReverseOf(in F32Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -vector.x1;
|
this.x1 = -vector.x1;
|
||||||
this.x2 = -vector.x2;
|
this.x2 = -vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in DPVector2 vector)
|
public void SetReverseOf(in F64Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -(float)vector.x1;
|
this.x1 = -(float)vector.x1;
|
||||||
this.x2 = -(float)vector.x2;
|
this.x2 = -(float)vector.x2;
|
||||||
|
|
@ -160,34 +160,34 @@ namespace Geometry
|
||||||
return String.Format("SPVector2({0}, {1})", this.x1, this.x2);
|
return String.Format("SPVector2({0}, {1})", this.x1, this.x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in SPVector2 vector1, in SPVector2 vector2, out SPVector2 sum)
|
public static void Add(in F32Vector2 vector1, in F32Vector2 vector2, out F32Vector2 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 + vector2.x1;
|
sum.x1 = vector1.x1 + vector2.x1;
|
||||||
sum.x2 = vector1.x2 + vector2.x2;
|
sum.x2 = vector1.x2 + vector2.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in SPVector2 minuend, in SPVector2 subtrahend, out SPVector2 difference)
|
public static void Subtract(in F32Vector2 minuend, in F32Vector2 subtrahend, out F32Vector2 difference)
|
||||||
{
|
{
|
||||||
difference.x1 = minuend.x1 - subtrahend.x1;
|
difference.x1 = minuend.x1 - subtrahend.x1;
|
||||||
difference.x2 = minuend.x2 - subtrahend.x2;
|
difference.x2 = minuend.x2 - subtrahend.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Muliply(in SPVector2 multiplicand, float multiplier, out SPVector2 product)
|
public static void Muliply(in F32Vector2 multiplicand, float multiplier, out F32Vector2 product)
|
||||||
{
|
{
|
||||||
product.x1 = multiplicand.x1 * multiplier;
|
product.x1 = multiplicand.x1 * multiplier;
|
||||||
product.x2 = multiplicand.x2 * multiplier;
|
product.x2 = multiplicand.x2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in SPVector2 dividend, float divisor, out SPVector2 quotient)
|
public static void Divide(in F32Vector2 dividend, float divisor, out F32Vector2 quotient)
|
||||||
{
|
{
|
||||||
quotient.x1 = dividend.x1 / divisor;
|
quotient.x1 = dividend.x1 / divisor;
|
||||||
quotient.x2 = dividend.x2 / divisor;
|
quotient.x2 = dividend.x2 / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
float weight1, in SPVector2 vector1,
|
float weight1, in F32Vector2 vector1,
|
||||||
float weight2, in SPVector2 vector2,
|
float weight2, in F32Vector2 vector2,
|
||||||
out SPVector2 sum
|
out F32Vector2 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
||||||
|
|
@ -195,10 +195,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
float weight1, in SPVector2 vector1,
|
float weight1, in F32Vector2 vector1,
|
||||||
float weight2, in SPVector2 vector2,
|
float weight2, in F32Vector2 vector2,
|
||||||
float weight3, in SPVector2 vector3,
|
float weight3, in F32Vector2 vector3,
|
||||||
out SPVector2 sum
|
out F32Vector2 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
||||||
|
|
@ -206,11 +206,11 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
float weight1, in SPVector2 vector1,
|
float weight1, in F32Vector2 vector1,
|
||||||
float weight2, in SPVector2 vector2,
|
float weight2, in F32Vector2 vector2,
|
||||||
float weight3, in SPVector2 vector3,
|
float weight3, in F32Vector2 vector3,
|
||||||
float weight4, in SPVector2 vector4,
|
float weight4, in F32Vector2 vector4,
|
||||||
out SPVector2 sum
|
out F32Vector2 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
||||||
|
|
@ -218,12 +218,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
float weight1, in SPVector2 vector1,
|
float weight1, in F32Vector2 vector1,
|
||||||
float weight2, in SPVector2 vector2,
|
float weight2, in F32Vector2 vector2,
|
||||||
float weight3, in SPVector2 vector3,
|
float weight3, in F32Vector2 vector3,
|
||||||
float weight4, in SPVector2 vector4,
|
float weight4, in F32Vector2 vector4,
|
||||||
float weight5, in SPVector2 vector5,
|
float weight5, in F32Vector2 vector5,
|
||||||
out SPVector2 sum
|
out F32Vector2 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
||||||
|
|
@ -231,9 +231,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean2(
|
public static void GetMean2(
|
||||||
in SPVector2 vector1,
|
in F32Vector2 vector1,
|
||||||
in SPVector2 vector2,
|
in F32Vector2 vector2,
|
||||||
out SPVector2 result
|
out F32Vector2 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1) * 0.5f;
|
result.x1 = (vector1.x1 + vector2.x1) * 0.5f;
|
||||||
|
|
@ -241,22 +241,22 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean3(
|
public static void GetMean3(
|
||||||
in SPVector2 vector1,
|
in F32Vector2 vector1,
|
||||||
in SPVector2 vector2,
|
in F32Vector2 vector2,
|
||||||
in SPVector2 vector3,
|
in F32Vector2 vector3,
|
||||||
out SPVector2 result
|
out F32Vector2 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * SPUtility.ONE_THIRD;
|
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * F32Utility.ONE_THIRD;
|
||||||
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * SPUtility.ONE_THIRD;
|
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * F32Utility.ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean4(
|
public static void GetMean4(
|
||||||
in SPVector2 vector1,
|
in F32Vector2 vector1,
|
||||||
in SPVector2 vector2,
|
in F32Vector2 vector2,
|
||||||
in SPVector2 vector3,
|
in F32Vector2 vector3,
|
||||||
in SPVector2 vector4,
|
in F32Vector2 vector4,
|
||||||
out SPVector2 result
|
out F32Vector2 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25f;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25f;
|
||||||
|
|
@ -264,60 +264,60 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean5(
|
public static void GetMean5(
|
||||||
in SPVector2 vector1,
|
in F32Vector2 vector1,
|
||||||
in SPVector2 vector2,
|
in F32Vector2 vector2,
|
||||||
in SPVector2 vector3,
|
in F32Vector2 vector3,
|
||||||
in SPVector2 vector4,
|
in F32Vector2 vector4,
|
||||||
in SPVector2 vector5,
|
in F32Vector2 vector5,
|
||||||
out SPVector2 result
|
out F32Vector2 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2f;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2f;
|
||||||
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2) + vector5.x2) * 0.2f;
|
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2) + vector5.x2) * 0.2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetScalarProduct(in SPVector2 vector1, in SPVector2 vector2)
|
public static float GetScalarProduct(in F32Vector2 vector1, in F32Vector2 vector2)
|
||||||
{
|
{
|
||||||
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2;
|
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetCrossProduct(in SPVector2 vector1, in SPVector2 vector2)
|
public static float GetCrossProduct(in F32Vector2 vector1, in F32Vector2 vector2)
|
||||||
{
|
{
|
||||||
return vector1.x1 * vector2.x2 - vector1.x2 * vector2.x1;
|
return vector1.x1 * vector2.x2 - vector1.x2 * vector2.x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetAngle(in SPVector2 vector1, in SPVector2 vector2, AngleUnit unit)
|
public static float GetAngle(in F32Vector2 vector1, in F32Vector2 vector2, AngleUnit unit)
|
||||||
{
|
{
|
||||||
float squareModule1 = vector1.GetSquareModule();
|
float squareModule1 = vector1.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule1 <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule1 <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float squareModule2 = vector2.GetSquareModule();
|
float squareModule2 = vector2.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule2 <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule2 <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float cosine = SPVector2.GetScalarProduct(vector1, vector2) / MathF.Sqrt(squareModule1 * squareModule2);
|
float cosine = F32Vector2.GetScalarProduct(vector1, vector2) / MathF.Sqrt(squareModule1 * squareModule2);
|
||||||
|
|
||||||
if (1.0f - SPUtility.EPSYLON <= cosine)
|
if (1.0f - F32Utility.EPSYLON <= cosine)
|
||||||
{
|
{
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -(1.0f - SPUtility.EPSYLON))
|
if (cosine <= -(1.0f - F32Utility.EPSYLON))
|
||||||
{
|
{
|
||||||
return SPAngle.GetHalfCircle(unit);
|
return F32Angle.GetHalfCircle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SPAngle.ConvertFromRadians(MathF.Acos(cosine), unit);
|
return F32Radians.ToUnits(MathF.Acos(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetSquareDistance(in SPVector2 vector1, in SPVector2 vector2)
|
public static float GetSquareDistance(in F32Vector2 vector1, in F32Vector2 vector2)
|
||||||
{
|
{
|
||||||
float dx1 = vector1.x1 - vector2.x1;
|
float dx1 = vector1.x1 - vector2.x1;
|
||||||
float dx2 = vector1.x2 - vector2.x2;
|
float dx2 = vector1.x2 - vector2.x2;
|
||||||
|
|
@ -325,29 +325,29 @@ namespace Geometry
|
||||||
return dx1 * dx1 + dx2 * dx2;
|
return dx1 * dx1 + dx2 * dx2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetDistance(in SPVector2 vector1, in SPVector2 vector2)
|
public static float GetDistance(in F32Vector2 vector1, in F32Vector2 vector2)
|
||||||
{
|
{
|
||||||
return MathF.Sqrt(GetSquareDistance(vector1, vector2));
|
return MathF.Sqrt(GetSquareDistance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AreEqual(in SPVector2 vector1, in SPVector2 vector2)
|
public static bool AreEqual(in F32Vector2 vector1, in F32Vector2 vector2)
|
||||||
{
|
{
|
||||||
float squareModule1 = vector1.GetSquareModule();
|
float squareModule1 = vector1.GetSquareModule();
|
||||||
float squareModule2 = vector2.GetSquareModule();
|
float squareModule2 = vector2.GetSquareModule();
|
||||||
float squareModule3 = GetSquareDistance(vector1, vector2);
|
float squareModule3 = GetSquareDistance(vector1, vector2);
|
||||||
|
|
||||||
// 2.0f means dimension amount
|
// 2.0f means dimension amount
|
||||||
if (squareModule1 < SPUtility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < SPUtility.EPSYLON_EFFECTIVENESS_LIMIT)
|
if (squareModule1 < F32Utility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < F32Utility.EPSYLON_EFFECTIVENESS_LIMIT)
|
||||||
{
|
{
|
||||||
return squareModule3 < (2.0f * SPUtility.SQUARE_EPSYLON);
|
return squareModule3 < (2.0f * F32Utility.SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule1 <= squareModule2)
|
if (squareModule1 <= squareModule2)
|
||||||
{
|
{
|
||||||
return squareModule3 <= (2.0f * SPUtility.SQUARE_EPSYLON) * squareModule2;
|
return squareModule3 <= (2.0f * F32Utility.SQUARE_EPSYLON) * squareModule2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return squareModule3 <= (2.0f * SPUtility.SQUARE_EPSYLON) * squareModule1;
|
return squareModule3 <= (2.0f * F32Utility.SQUARE_EPSYLON) * squareModule1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,31 +21,31 @@ using System;
|
||||||
* Date: 1 Feb 2019
|
* Date: 1 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPVector3
|
public struct F32Vector3
|
||||||
{
|
{
|
||||||
public static readonly SPVector3 ZERO = new SPVector3(0.0f, 0.0f, 0.0f);
|
public static readonly F32Vector3 ZERO = new F32Vector3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
public float x1;
|
public float x1;
|
||||||
public float x2;
|
public float x2;
|
||||||
public float x3;
|
public float x3;
|
||||||
|
|
||||||
public SPVector3(float x1, float x2, float x3)
|
public F32Vector3(float x1, float x2, float x3)
|
||||||
{
|
{
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVector3(in SPVector3 vector)
|
public F32Vector3(in F32Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
this.x3 = vector.x3;
|
this.x3 = vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVector3(in DPVector3 vector)
|
public F32Vector3(in F64Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = (float)vector.x1;
|
this.x1 = (float)vector.x1;
|
||||||
this.x2 = (float)vector.x2;
|
this.x2 = (float)vector.x2;
|
||||||
|
|
@ -66,12 +66,12 @@ namespace Geometry
|
||||||
{
|
{
|
||||||
float squareModule = this.GetSquareModule();
|
float squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + SPUtility.TWO_EPSYLON)
|
if (1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + F32Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -86,23 +86,23 @@ namespace Geometry
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly SPVector3 GetNormalized()
|
public readonly F32Vector3 GetNormalized()
|
||||||
{
|
{
|
||||||
float squareModule = this.GetSquareModule();
|
float squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + SPUtility.TWO_EPSYLON)
|
if (1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0f + F32Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
float module = MathF.Sqrt(squareModule);
|
float module = MathF.Sqrt(squareModule);
|
||||||
|
|
||||||
return new SPVector3(
|
return new F32Vector3(
|
||||||
this.x1 / module,
|
this.x1 / module,
|
||||||
this.x2 / module,
|
this.x2 / module,
|
||||||
this.x3 / module
|
this.x3 / module
|
||||||
|
|
@ -118,13 +118,13 @@ namespace Geometry
|
||||||
|
|
||||||
public readonly bool IsZero()
|
public readonly bool IsZero()
|
||||||
{
|
{
|
||||||
return this.GetSquareModule() <= SPUtility.SQUARE_EPSYLON;
|
return this.GetSquareModule() <= F32Utility.SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsUnit()
|
public readonly bool IsUnit()
|
||||||
{
|
{
|
||||||
float squareModule = this.GetSquareModule();
|
float squareModule = this.GetSquareModule();
|
||||||
return 1.0f - SPUtility.TWO_EPSYLON <= squareModule && squareModule <= SPUtility.EPSYLON;
|
return 1.0f - F32Utility.TWO_EPSYLON <= squareModule && squareModule <= F32Utility.EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
|
|
@ -141,28 +141,28 @@ namespace Geometry
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPVector3 vector)
|
public void SetValues(in F64Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = (float)vector.x1;
|
this.x1 = (float)vector.x1;
|
||||||
this.x2 = (float)vector.x2;
|
this.x2 = (float)vector.x2;
|
||||||
this.x3 = (float)vector.x3;
|
this.x3 = (float)vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPVector3 vector)
|
public void SetValues(in F32Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
this.x3 = vector.x3;
|
this.x3 = vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in SPVector3 vector)
|
public void SetReverseOf(in F32Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -vector.x1;
|
this.x1 = -vector.x1;
|
||||||
this.x2 = -vector.x2;
|
this.x2 = -vector.x2;
|
||||||
this.x3 = -vector.x3;
|
this.x3 = -vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in DPVector3 vector)
|
public void SetReverseOf(in F64Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -(float)vector.x1;
|
this.x1 = -(float)vector.x1;
|
||||||
this.x2 = -(float)vector.x2;
|
this.x2 = -(float)vector.x2;
|
||||||
|
|
@ -174,28 +174,28 @@ namespace Geometry
|
||||||
return String.Format("SPVector3({0}, {1}, {2})", this.x1, this.x2, this.x3);
|
return String.Format("SPVector3({0}, {1}, {2})", this.x1, this.x2, this.x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in SPVector3 vector1, in SPVector3 vector2, out SPVector3 sum)
|
public static void Add(in F32Vector3 vector1, in F32Vector3 vector2, out F32Vector3 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 + vector2.x1;
|
sum.x1 = vector1.x1 + vector2.x1;
|
||||||
sum.x2 = vector1.x2 + vector2.x2;
|
sum.x2 = vector1.x2 + vector2.x2;
|
||||||
sum.x3 = vector1.x3 + vector2.x3;
|
sum.x3 = vector1.x3 + vector2.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in SPVector3 minuend, in SPVector3 subtrahend, out SPVector3 difference)
|
public static void Subtract(in F32Vector3 minuend, in F32Vector3 subtrahend, out F32Vector3 difference)
|
||||||
{
|
{
|
||||||
difference.x1 = minuend.x1 - subtrahend.x1;
|
difference.x1 = minuend.x1 - subtrahend.x1;
|
||||||
difference.x2 = minuend.x2 - subtrahend.x2;
|
difference.x2 = minuend.x2 - subtrahend.x2;
|
||||||
difference.x3 = minuend.x3 - subtrahend.x3;
|
difference.x3 = minuend.x3 - subtrahend.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Muliply(in SPVector3 multiplicand, float multiplier, out SPVector3 product)
|
public static void Muliply(in F32Vector3 multiplicand, float multiplier, out F32Vector3 product)
|
||||||
{
|
{
|
||||||
product.x1 = multiplicand.x1 * multiplier;
|
product.x1 = multiplicand.x1 * multiplier;
|
||||||
product.x2 = multiplicand.x2 * multiplier;
|
product.x2 = multiplicand.x2 * multiplier;
|
||||||
product.x3 = multiplicand.x3 * multiplier;
|
product.x3 = multiplicand.x3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in SPVector3 dividend, float divisor, out SPVector3 quotient)
|
public static void Divide(in F32Vector3 dividend, float divisor, out F32Vector3 quotient)
|
||||||
{
|
{
|
||||||
quotient.x1 = dividend.x1 / divisor;
|
quotient.x1 = dividend.x1 / divisor;
|
||||||
quotient.x2 = dividend.x2 / divisor;
|
quotient.x2 = dividend.x2 / divisor;
|
||||||
|
|
@ -203,9 +203,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
float weight1, in SPVector3 vector1,
|
float weight1, in F32Vector3 vector1,
|
||||||
float weight2, in SPVector3 vector2,
|
float weight2, in F32Vector3 vector2,
|
||||||
out SPVector3 sum
|
out F32Vector3 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
||||||
|
|
@ -214,10 +214,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
float weight1, in SPVector3 vector1,
|
float weight1, in F32Vector3 vector1,
|
||||||
float weight2, in SPVector3 vector2,
|
float weight2, in F32Vector3 vector2,
|
||||||
float weight3, in SPVector3 vector3,
|
float weight3, in F32Vector3 vector3,
|
||||||
out SPVector3 sum
|
out F32Vector3 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
||||||
|
|
@ -226,11 +226,11 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
float weight1, in SPVector3 vector1,
|
float weight1, in F32Vector3 vector1,
|
||||||
float weight2, in SPVector3 vector2,
|
float weight2, in F32Vector3 vector2,
|
||||||
float weight3, in SPVector3 vector3,
|
float weight3, in F32Vector3 vector3,
|
||||||
float weight4, in SPVector3 vector4,
|
float weight4, in F32Vector3 vector4,
|
||||||
out SPVector3 sum
|
out F32Vector3 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
||||||
|
|
@ -239,12 +239,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
float weight1, in SPVector3 vector1,
|
float weight1, in F32Vector3 vector1,
|
||||||
float weight2, in SPVector3 vector2,
|
float weight2, in F32Vector3 vector2,
|
||||||
float weight3, in SPVector3 vector3,
|
float weight3, in F32Vector3 vector3,
|
||||||
float weight4, in SPVector3 vector4,
|
float weight4, in F32Vector3 vector4,
|
||||||
float weight5, in SPVector3 vector5,
|
float weight5, in F32Vector3 vector5,
|
||||||
out SPVector3 sum
|
out F32Vector3 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4) + vector5.x1 * weight5;
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4) + vector5.x1 * weight5;
|
||||||
|
|
@ -253,9 +253,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean2(
|
public static void GetMean2(
|
||||||
in SPVector3 vector1,
|
in F32Vector3 vector1,
|
||||||
in SPVector3 vector2,
|
in F32Vector3 vector2,
|
||||||
out SPVector3 result
|
out F32Vector3 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1) * 0.5f;
|
result.x1 = (vector1.x1 + vector2.x1) * 0.5f;
|
||||||
|
|
@ -264,23 +264,23 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean3(
|
public static void GetMean3(
|
||||||
in SPVector3 vector1,
|
in F32Vector3 vector1,
|
||||||
in SPVector3 vector2,
|
in F32Vector3 vector2,
|
||||||
in SPVector3 vector3,
|
in F32Vector3 vector3,
|
||||||
out SPVector3 result
|
out F32Vector3 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * SPUtility.ONE_THIRD;
|
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * F32Utility.ONE_THIRD;
|
||||||
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * SPUtility.ONE_THIRD;
|
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * F32Utility.ONE_THIRD;
|
||||||
result.x3 = (vector1.x3 + vector2.x3 + vector3.x3) * SPUtility.ONE_THIRD;
|
result.x3 = (vector1.x3 + vector2.x3 + vector3.x3) * F32Utility.ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean4(
|
public static void GetMean4(
|
||||||
in SPVector3 vector1,
|
in F32Vector3 vector1,
|
||||||
in SPVector3 vector2,
|
in F32Vector3 vector2,
|
||||||
in SPVector3 vector3,
|
in F32Vector3 vector3,
|
||||||
in SPVector3 vector4,
|
in F32Vector3 vector4,
|
||||||
out SPVector3 result
|
out F32Vector3 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25f;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25f;
|
||||||
|
|
@ -289,12 +289,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean5(
|
public static void GetMean5(
|
||||||
in SPVector3 vector1,
|
in F32Vector3 vector1,
|
||||||
in SPVector3 vector2,
|
in F32Vector3 vector2,
|
||||||
in SPVector3 vector3,
|
in F32Vector3 vector3,
|
||||||
in SPVector3 vector4,
|
in F32Vector3 vector4,
|
||||||
in SPVector3 vector5,
|
in F32Vector3 vector5,
|
||||||
out SPVector3 result
|
out F32Vector3 result
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2f;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2f;
|
||||||
|
|
@ -302,12 +302,12 @@ namespace Geometry
|
||||||
result.x3 = ((vector1.x3 + vector2.x3) + (vector3.x3 + vector4.x3) + vector5.x3) * 0.2f;
|
result.x3 = ((vector1.x3 + vector2.x3) + (vector3.x3 + vector4.x3) + vector5.x3) * 0.2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetScalarProduct(in SPVector3 vector1, in SPVector3 vector2)
|
public static float GetScalarProduct(in F32Vector3 vector1, in F32Vector3 vector2)
|
||||||
{
|
{
|
||||||
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2 + vector1.x3 * vector2.x3;
|
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2 + vector1.x3 * vector2.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetCrossProduct(in SPVector3 vector1, in SPVector3 vector2, out SPVector3 result)
|
public static void GetCrossProduct(in F32Vector3 vector1, in F32Vector3 vector2, out F32Vector3 result)
|
||||||
{
|
{
|
||||||
float x1 = vector1.x2 * vector2.x3 - vector1.x3 * vector2.x2;
|
float x1 = vector1.x2 * vector2.x3 - vector1.x3 * vector2.x2;
|
||||||
float x2 = vector1.x3 * vector2.x1 - vector1.x1 * vector2.x3;
|
float x2 = vector1.x3 * vector2.x1 - vector1.x1 * vector2.x3;
|
||||||
|
|
@ -318,14 +318,14 @@ namespace Geometry
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetTripleProduct(in SPVector3 vector1, in SPVector3 vector2, in SPVector3 vector3)
|
public static float GetTripleProduct(in F32Vector3 vector1, in F32Vector3 vector2, in F32Vector3 vector3)
|
||||||
{
|
{
|
||||||
return vector1.x1 * (vector2.x2 * vector3.x3 - vector2.x3 * vector3.x2)
|
return vector1.x1 * (vector2.x2 * vector3.x3 - vector2.x3 * vector3.x2)
|
||||||
+ vector1.x2 * (vector2.x3 * vector3.x1 - vector2.x1 * vector3.x3)
|
+ vector1.x2 * (vector2.x3 * vector3.x1 - vector2.x1 * vector3.x3)
|
||||||
+ vector1.x3 * (vector2.x1 * vector3.x2 - vector2.x2 * vector3.x1);
|
+ vector1.x3 * (vector2.x1 * vector3.x2 - vector2.x2 * vector3.x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetDoubleCrossProduct(in SPVector3 vector1, in SPVector3 vector2, in SPVector3 vector3, out SPVector3 result)
|
public static void GetDoubleCrossProduct(in F32Vector3 vector1, in F32Vector3 vector2, in F32Vector3 vector3, out F32Vector3 result)
|
||||||
{
|
{
|
||||||
// [a x [b x c]] = b * (a, c) - c * (a, b)
|
// [a x [b x c]] = b * (a, c) - c * (a, b)
|
||||||
float ac = GetScalarProduct(vector1, vector3);
|
float ac = GetScalarProduct(vector1, vector3);
|
||||||
|
|
@ -336,38 +336,38 @@ namespace Geometry
|
||||||
result.x3 = ac * vector2.x3 - ab * vector3.x3;
|
result.x3 = ac * vector2.x3 - ab * vector3.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetAngle(in SPVector3 vector1, in SPVector3 vector2, AngleUnit unit)
|
public static float GetAngle(in F32Vector3 vector1, in F32Vector3 vector2, AngleUnit unit)
|
||||||
{
|
{
|
||||||
float squareModule1 = vector1.GetSquareModule();
|
float squareModule1 = vector1.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule1 <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule1 <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float squareModule2 = vector2.GetSquareModule();
|
float squareModule2 = vector2.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule2 <= SPUtility.SQUARE_EPSYLON)
|
if (squareModule2 <= F32Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float cosine = SPVector3.GetScalarProduct(vector1, vector2) / MathF.Sqrt(squareModule1 * squareModule2);
|
float cosine = F32Vector3.GetScalarProduct(vector1, vector2) / MathF.Sqrt(squareModule1 * squareModule2);
|
||||||
|
|
||||||
if (1.0f - SPUtility.EPSYLON <= cosine)
|
if (1.0f - F32Utility.EPSYLON <= cosine)
|
||||||
{
|
{
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -(1.0f - SPUtility.EPSYLON))
|
if (cosine <= -(1.0f - F32Utility.EPSYLON))
|
||||||
{
|
{
|
||||||
return SPAngle.GetHalfCircle(unit);
|
return F32Angle.GetHalfCircle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SPAngle.ConvertFromRadians(MathF.Acos(cosine), unit);
|
return F32Radians.ToUnits(MathF.Acos(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetSquareDistance(in SPVector3 vector1, in SPVector3 vector2)
|
public static float GetSquareDistance(in F32Vector3 vector1, in F32Vector3 vector2)
|
||||||
{
|
{
|
||||||
float dx1 = vector1.x1 - vector2.x1;
|
float dx1 = vector1.x1 - vector2.x1;
|
||||||
float dx2 = vector1.x2 - vector2.x2;
|
float dx2 = vector1.x2 - vector2.x2;
|
||||||
|
|
@ -376,29 +376,29 @@ namespace Geometry
|
||||||
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float GetDistance(in SPVector3 vector1, in SPVector3 vector2)
|
public static float GetDistance(in F32Vector3 vector1, in F32Vector3 vector2)
|
||||||
{
|
{
|
||||||
return MathF.Sqrt(GetSquareDistance(vector1, vector2));
|
return MathF.Sqrt(GetSquareDistance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AreEqual(in SPVector3 vector1, in SPVector3 vector2)
|
public static bool AreEqual(in F32Vector3 vector1, in F32Vector3 vector2)
|
||||||
{
|
{
|
||||||
float squareModule1 = vector1.GetSquareModule();
|
float squareModule1 = vector1.GetSquareModule();
|
||||||
float squareModule2 = vector2.GetSquareModule();
|
float squareModule2 = vector2.GetSquareModule();
|
||||||
float squareModule3 = GetSquareDistance(vector1, vector2);
|
float squareModule3 = GetSquareDistance(vector1, vector2);
|
||||||
|
|
||||||
// 3.0f means dimension amount
|
// 3.0f means dimension amount
|
||||||
if (squareModule1 < SPUtility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < SPUtility.EPSYLON_EFFECTIVENESS_LIMIT)
|
if (squareModule1 < F32Utility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < F32Utility.EPSYLON_EFFECTIVENESS_LIMIT)
|
||||||
{
|
{
|
||||||
return squareModule3 < (3.0f * SPUtility.SQUARE_EPSYLON);
|
return squareModule3 < (3.0f * F32Utility.SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule1 <= squareModule2)
|
if (squareModule1 <= squareModule2)
|
||||||
{
|
{
|
||||||
return squareModule3 <= (3.0f * SPUtility.SQUARE_EPSYLON) * squareModule2;
|
return squareModule3 <= (3.0f * F32Utility.SQUARE_EPSYLON) * squareModule2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return squareModule3 <= (3.0f * SPUtility.SQUARE_EPSYLON) * squareModule1;
|
return squareModule3 <= (3.0f * F32Utility.SQUARE_EPSYLON) * squareModule1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,366 +1,366 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 20 Oct 2024
|
* Date: 20 Oct 2024
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct SPVersor
|
public struct F32Versor
|
||||||
{
|
{
|
||||||
public static readonly SPVersor IDLE = new SPVersor(1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
|
public static readonly F32Versor IDLE = new F32Versor(1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
private float s0;
|
private float s0;
|
||||||
private float x1;
|
private float x1;
|
||||||
private float x2;
|
private float x2;
|
||||||
private float x3;
|
private float x3;
|
||||||
private float corrector;
|
private float corrector;
|
||||||
|
|
||||||
private SPVersor(float s0, float x1, float x2, float x3, float corrector)
|
private F32Versor(float s0, float x1, float x2, float x3, float corrector)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
this.corrector = corrector;
|
this.corrector = corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVersor()
|
public F32Versor()
|
||||||
{
|
{
|
||||||
this.s0 = 1.0f;
|
this.s0 = 1.0f;
|
||||||
this.x1 = 0.0f;
|
this.x1 = 0.0f;
|
||||||
this.x2 = 0.0f;
|
this.x2 = 0.0f;
|
||||||
this.x3 = 0.0f;
|
this.x3 = 0.0f;
|
||||||
this.corrector = 1.0f;
|
this.corrector = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVersor(float s0, float x1, float x2, float x3)
|
public F32Versor(float s0, float x1, float x2, float x3)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
|
|
||||||
float squareModule = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
float squareModule = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||||
|
|
||||||
this.corrector = 2.0f - squareModule;
|
this.corrector = 2.0f - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0f - SPUtility.TWO_EPSYLON || 1.0f + SPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0f - F32Utility.TWO_EPSYLON || 1.0f + F32Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
else if (s0 < -1.0f + SPUtility.EPSYLON || 1.0f - SPUtility.EPSYLON < s0)
|
else if (s0 < -1.0f + F32Utility.EPSYLON || 1.0f - F32Utility.EPSYLON < s0)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVersor(in SPVersor versor)
|
public F32Versor(in F32Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.s0;
|
this.s0 = versor.s0;
|
||||||
this.x1 = versor.x1;
|
this.x1 = versor.x1;
|
||||||
this.x2 = versor.x2;
|
this.x2 = versor.x2;
|
||||||
this.x3 = versor.x3;
|
this.x3 = versor.x3;
|
||||||
this.corrector = versor.corrector;
|
this.corrector = versor.corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SPVersor(in DPVersor versor)
|
public F32Versor(in F64Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = (float)versor.GetScalar();
|
this.s0 = (float)versor.GetScalar();
|
||||||
this.x1 = (float)versor.GetX1();
|
this.x1 = (float)versor.GetX1();
|
||||||
this.x2 = (float)versor.GetX2();
|
this.x2 = (float)versor.GetX2();
|
||||||
this.x3 = (float)versor.GetX3();
|
this.x3 = (float)versor.GetX3();
|
||||||
|
|
||||||
float squareModule = (this.s0 * this.s0 + this.x1 * this.x1) + (this.x2 * this.x2 + this.x3 * this.x3);
|
float squareModule = (this.s0 * this.s0 + this.x1 * this.x1) + (this.x2 * this.x2 + this.x3 * this.x3);
|
||||||
|
|
||||||
this.corrector = 2.0f - squareModule;
|
this.corrector = 2.0f - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0f - SPUtility.TWO_EPSYLON || 1.0f + SPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0f - F32Utility.TWO_EPSYLON || 1.0f + F32Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
else if (s0 < -1.0f + SPUtility.EPSYLON || 1.0f - SPUtility.EPSYLON < s0)
|
else if (s0 < -1.0f + F32Utility.EPSYLON || 1.0f - F32Utility.EPSYLON < s0)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly float GetScalar()
|
public readonly float GetScalar()
|
||||||
{
|
{
|
||||||
return this.s0;
|
return this.s0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly float GetX1()
|
public readonly float GetX1()
|
||||||
{
|
{
|
||||||
return this.x1;
|
return this.x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly float GetX2()
|
public readonly float GetX2()
|
||||||
{
|
{
|
||||||
return this.x2;
|
return this.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly float GetX3()
|
public readonly float GetX3()
|
||||||
{
|
{
|
||||||
return this.x3;
|
return this.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly float GetCorrector()
|
public readonly float GetCorrector()
|
||||||
{
|
{
|
||||||
return this.corrector;
|
return this.corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsIdle()
|
public readonly bool IsIdle()
|
||||||
{
|
{
|
||||||
return this.s0 <= -(1.0f - SPUtility.EPSYLON) || (1.0f - SPUtility.EPSYLON) <= this.s0;
|
return this.s0 <= -(1.0f - F32Utility.EPSYLON) || (1.0f - F32Utility.EPSYLON) <= this.s0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
this.s0 = 1.0f;
|
this.s0 = 1.0f;
|
||||||
this.x1 = 0.0f;
|
this.x1 = 0.0f;
|
||||||
this.x2 = 0.0f;
|
this.x2 = 0.0f;
|
||||||
this.x3 = 0.0f;
|
this.x3 = 0.0f;
|
||||||
this.corrector = 1.0f;
|
this.corrector = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Invert()
|
public void Invert()
|
||||||
{
|
{
|
||||||
this.x1 = -this.x1;
|
this.x1 = -this.x1;
|
||||||
this.x2 = -this.x2;
|
this.x2 = -this.x2;
|
||||||
this.x3 = -this.x3;
|
this.x3 = -this.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly float GetAngle(AngleUnit unit)
|
public readonly float GetAngle(AngleUnit unit)
|
||||||
{
|
{
|
||||||
if (this.s0 <= -(1.0f - SPUtility.TWO_EPSYLON) || 1.0f - SPUtility.TWO_EPSYLON <= this.s0) {
|
if (this.s0 <= -(1.0f - F32Utility.TWO_EPSYLON) || 1.0f - F32Utility.TWO_EPSYLON <= this.s0) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-SPUtility.EPSYLON <= this.s0 && this.s0 <= SPUtility.EPSYLON)
|
if (-F32Utility.EPSYLON <= this.s0 && this.s0 <= F32Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
return SPAngle.GetHalfCircle(unit);
|
return F32Angle.GetHalfCircle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SPAngle.ConvertFromRadians(2.0f * MathF.Acos(s0), unit);
|
return F32Radians.ToUnits(2.0f * MathF.Acos(s0), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeRotationMatrix(out SPMatrix3x3 matrix)
|
public readonly void MakeRotationMatrix(out F32Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
float s0s0 = this.s0 * this.s0;
|
float s0s0 = this.s0 * this.s0;
|
||||||
float x1x1 = this.x1 * this.x1;
|
float x1x1 = this.x1 * this.x1;
|
||||||
float x2x2 = this.x1 * this.x2;
|
float x2x2 = this.x1 * this.x2;
|
||||||
float x3x3 = this.x1 * this.x3;
|
float x3x3 = this.x1 * this.x3;
|
||||||
|
|
||||||
|
|
||||||
float s0x1 = this.s0 * this.x1;
|
float s0x1 = this.s0 * this.x1;
|
||||||
float s0x2 = this.s0 * this.x2;
|
float s0x2 = this.s0 * this.x2;
|
||||||
float s0x3 = this.s0 * this.x3;
|
float s0x3 = this.s0 * this.x3;
|
||||||
|
|
||||||
float x1x2 = this.x1 * this.x2;
|
float x1x2 = this.x1 * this.x2;
|
||||||
float x1x3 = this.x1 * this.x3;
|
float x1x3 = this.x1 * this.x3;
|
||||||
float x2x3 = this.x2 * this.x3;
|
float x2x3 = this.x2 * this.x3;
|
||||||
|
|
||||||
float corrector2 = 2.0f * this.corrector;
|
float corrector2 = 2.0f * this.corrector;
|
||||||
|
|
||||||
matrix.r1c1 = this.corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
matrix.r1c1 = this.corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||||
matrix.r2c2 = this.corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
matrix.r2c2 = this.corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||||
matrix.r3c3 = this.corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
matrix.r3c3 = this.corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||||
|
|
||||||
matrix.r1c2 = corrector2 * (x1x2 - s0x3);
|
matrix.r1c2 = corrector2 * (x1x2 - s0x3);
|
||||||
matrix.r2c3 = corrector2 * (x2x3 - s0x1);
|
matrix.r2c3 = corrector2 * (x2x3 - s0x1);
|
||||||
matrix.r3c1 = corrector2 * (x1x3 - s0x2);
|
matrix.r3c1 = corrector2 * (x1x3 - s0x2);
|
||||||
|
|
||||||
matrix.r2c1 = corrector2 * (x1x2 + s0x3);
|
matrix.r2c1 = corrector2 * (x1x2 + s0x3);
|
||||||
matrix.r3c2 = corrector2 * (x2x3 + s0x1);
|
matrix.r3c2 = corrector2 * (x2x3 + s0x1);
|
||||||
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeReverseMatrix(out SPMatrix3x3 matrix)
|
public readonly void MakeReverseMatrix(out F32Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
float s0s0 = this.s0 * this.s0;
|
float s0s0 = this.s0 * this.s0;
|
||||||
float x1x1 = this.x1 * this.x1;
|
float x1x1 = this.x1 * this.x1;
|
||||||
float x2x2 = this.x1 * this.x2;
|
float x2x2 = this.x1 * this.x2;
|
||||||
float x3x3 = this.x1 * this.x3;
|
float x3x3 = this.x1 * this.x3;
|
||||||
|
|
||||||
|
|
||||||
float s0x1 = this.s0 * this.x1;
|
float s0x1 = this.s0 * this.x1;
|
||||||
float s0x2 = this.s0 * this.x2;
|
float s0x2 = this.s0 * this.x2;
|
||||||
float s0x3 = this.s0 * this.x3;
|
float s0x3 = this.s0 * this.x3;
|
||||||
|
|
||||||
float x1x2 = this.x1 * this.x2;
|
float x1x2 = this.x1 * this.x2;
|
||||||
float x1x3 = this.x1 * this.x3;
|
float x1x3 = this.x1 * this.x3;
|
||||||
float x2x3 = this.x2 * this.x3;
|
float x2x3 = this.x2 * this.x3;
|
||||||
|
|
||||||
float corrector2 = 2.0f * this.corrector;
|
float corrector2 = 2.0f * this.corrector;
|
||||||
|
|
||||||
matrix.r1c1 = this.corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
matrix.r1c1 = this.corrector * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||||
matrix.r2c2 = this.corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
matrix.r2c2 = this.corrector * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||||
matrix.r3c3 = this.corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
matrix.r3c3 = this.corrector * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||||
|
|
||||||
matrix.r1c2 = corrector2 * (x1x2 + s0x3);
|
matrix.r1c2 = corrector2 * (x1x2 + s0x3);
|
||||||
matrix.r2c3 = corrector2 * (x2x3 + s0x1);
|
matrix.r2c3 = corrector2 * (x2x3 + s0x1);
|
||||||
matrix.r3c1 = corrector2 * (x1x3 + s0x2);
|
matrix.r3c1 = corrector2 * (x1x3 + s0x2);
|
||||||
|
|
||||||
matrix.r2c1 = corrector2 * (x1x2 - s0x3);
|
matrix.r2c1 = corrector2 * (x1x2 - s0x3);
|
||||||
matrix.r3c2 = corrector2 * (x2x3 - s0x1);
|
matrix.r3c2 = corrector2 * (x2x3 - s0x1);
|
||||||
matrix.r1c3 = corrector2 * (x1x3 - s0x2);
|
matrix.r1c3 = corrector2 * (x1x3 - s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(float s0, float x1, float x2, float x3)
|
public void SetValues(float s0, float x1, float x2, float x3)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
|
|
||||||
float squareModule = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
float squareModule = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||||
|
|
||||||
if (squareModule < 1.0f - SPUtility.TWO_EPSYLON || 1.0f + SPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0f - F32Utility.TWO_EPSYLON || 1.0f + F32Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s0 < -1.0f + SPUtility.EPSYLON || 1.0f - SPUtility.EPSYLON < s0) {
|
if (s0 < -1.0f + F32Utility.EPSYLON || 1.0f - F32Utility.EPSYLON < s0) {
|
||||||
this.Reset();
|
this.Reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.corrector = 2.0f - squareModule;
|
this.corrector = 2.0f - squareModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPVersor versor)
|
public void SetValues(in F32Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.s0;
|
this.s0 = versor.s0;
|
||||||
this.x1 = versor.x1;
|
this.x1 = versor.x1;
|
||||||
this.x2 = versor.x2;
|
this.x2 = versor.x2;
|
||||||
this.x3 = versor.x3;
|
this.x3 = versor.x3;
|
||||||
this.corrector = versor.corrector;
|
this.corrector = versor.corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPVersor versor)
|
public void SetValues(in F64Versor versor)
|
||||||
{
|
{
|
||||||
this.SetValues(
|
this.SetValues(
|
||||||
(float)versor.GetScalar(),
|
(float)versor.GetScalar(),
|
||||||
(float)versor.GetX1(),
|
(float)versor.GetX1(),
|
||||||
(float)versor.GetX2(),
|
(float)versor.GetX2(),
|
||||||
(float)versor.GetX3()
|
(float)versor.GetX3()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetInverted(in SPVersor versor)
|
public void SetInverted(in F32Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.s0;
|
this.s0 = versor.s0;
|
||||||
this.x1 = -versor.x1;
|
this.x1 = -versor.x1;
|
||||||
this.x2 = -versor.x2;
|
this.x2 = -versor.x2;
|
||||||
this.x3 = -versor.x3;
|
this.x3 = -versor.x3;
|
||||||
this.corrector = versor.corrector;
|
this.corrector = versor.corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetInverted(in DPVersor versor)
|
public void SetInverted(in F64Versor versor)
|
||||||
{
|
{
|
||||||
this.SetValues(
|
this.SetValues(
|
||||||
(float)versor.GetScalar(),
|
(float)versor.GetScalar(),
|
||||||
-(float)versor.GetX1(),
|
-(float)versor.GetX1(),
|
||||||
-(float)versor.GetX2(),
|
-(float)versor.GetX2(),
|
||||||
-(float)versor.GetX3()
|
-(float)versor.GetX3()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void Turn(in SPVector3 vector, out SPVector3 result)
|
public readonly void Turn(in F32Vector3 vector, out F32Vector3 result)
|
||||||
{
|
{
|
||||||
float multiplier = 2.0f * this.corrector;
|
float multiplier = 2.0f * this.corrector;
|
||||||
float tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
float tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
||||||
float tx2 = multiplier * (this.x3 * vector.x1 - this.x1 * vector.x3);
|
float tx2 = multiplier * (this.x3 * vector.x1 - this.x1 * vector.x3);
|
||||||
float tx3 = multiplier * (this.x1 * vector.x2 - this.x2 * vector.x1);
|
float tx3 = multiplier * (this.x1 * vector.x2 - this.x2 * vector.x1);
|
||||||
|
|
||||||
float x1 = (vector.x1 + tx1 * this.s0) + (this.x2 * tx3 - this.x3 * tx2);
|
float x1 = (vector.x1 + tx1 * this.s0) + (this.x2 * tx3 - this.x3 * tx2);
|
||||||
float x2 = (vector.x2 + tx2 * this.s0) + (this.x3 * tx1 - this.x1 * tx3);
|
float x2 = (vector.x2 + tx2 * this.s0) + (this.x3 * tx1 - this.x1 * tx3);
|
||||||
float x3 = (vector.x3 + tx3 * this.s0) + (this.x1 * tx2 - this.x2 * tx1);
|
float x3 = (vector.x3 + tx3 * this.s0) + (this.x1 * tx2 - this.x2 * tx1);
|
||||||
|
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void TurnBack(in SPVector3 vector, out SPVector3 result)
|
public readonly void TurnBack(in F32Vector3 vector, out F32Vector3 result)
|
||||||
{
|
{
|
||||||
float multiplier = 2.0f * this.corrector;
|
float multiplier = 2.0f * this.corrector;
|
||||||
float tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
float tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
||||||
float tx2 = multiplier * (this.x3 * vector.x1 - this.x1 * vector.x3);
|
float tx2 = multiplier * (this.x3 * vector.x1 - this.x1 * vector.x3);
|
||||||
float tx3 = multiplier * (this.x1 * vector.x2 - this.x2 * vector.x1);
|
float tx3 = multiplier * (this.x1 * vector.x2 - this.x2 * vector.x1);
|
||||||
|
|
||||||
float x1 = (vector.x1 - tx1 * this.s0) + (this.x2 * tx3 - this.x3 * tx2);
|
float x1 = (vector.x1 - tx1 * this.s0) + (this.x2 * tx3 - this.x3 * tx2);
|
||||||
float x2 = (vector.x2 - tx2 * this.s0) + (this.x3 * tx1 - this.x1 * tx3);
|
float x2 = (vector.x2 - tx2 * this.s0) + (this.x3 * tx1 - this.x1 * tx3);
|
||||||
float x3 = (vector.x3 - tx3 * this.s0) + (this.x1 * tx2 - this.x2 * tx1);
|
float x3 = (vector.x3 - tx3 * this.s0) + (this.x1 * tx2 - this.x2 * tx1);
|
||||||
|
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Normalize(float squareModule)
|
private void Normalize(float squareModule)
|
||||||
{
|
{
|
||||||
if (squareModule <= SPUtility.SQUARE_EPSYLON || (this.x1 * this.x1 + this.x2 * this.x2 + this.x3 * this.x3) <= SPUtility.SQUARE_EPSYLON * squareModule)
|
if (squareModule <= F32Utility.SQUARE_EPSYLON || (this.x1 * this.x1 + this.x2 * this.x2 + this.x3 * this.x3) <= F32Utility.SQUARE_EPSYLON * squareModule)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float module = MathF.Sqrt(squareModule);
|
float module = MathF.Sqrt(squareModule);
|
||||||
|
|
||||||
this.s0 /= module;
|
this.s0 /= module;
|
||||||
this.x1 /= module;
|
this.x1 /= module;
|
||||||
this.x2 /= module;
|
this.x2 /= module;
|
||||||
this.x3 /= module;
|
this.x3 /= module;
|
||||||
|
|
||||||
this.corrector = (this.s0 * this.s0 + this.x1 * this.x1) + (this.x2 * this.x2 + this.x3 * this.x3);
|
this.corrector = (this.s0 * this.s0 + this.x1 * this.x1) + (this.x2 * this.x2 + this.x3 * this.x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Combine(in SPVersor second, in SPVersor first, out SPVersor result)
|
public static void Combine(in F32Versor second, in F32Versor first, out F32Versor result)
|
||||||
{
|
{
|
||||||
float s0 = (second.s0 * first.s0 - second.x1 * first.x1) - (second.x2 * first.x2 + second.x3 * first.x3);
|
float s0 = (second.s0 * first.s0 - second.x1 * first.x1) - (second.x2 * first.x2 + second.x3 * first.x3);
|
||||||
float x1 = (second.x1 * first.s0 + second.s0 * first.x1) - (second.x3 * first.x2 - second.x2 * first.x3);
|
float x1 = (second.x1 * first.s0 + second.s0 * first.x1) - (second.x3 * first.x2 - second.x2 * first.x3);
|
||||||
float x2 = (second.x2 * first.s0 + second.s0 * first.x2) - (second.x1 * first.x3 - second.x3 * first.x1);
|
float x2 = (second.x2 * first.s0 + second.s0 * first.x2) - (second.x1 * first.x3 - second.x3 * first.x1);
|
||||||
float x3 = (second.x3 * first.s0 + second.s0 * first.x3) - (second.x2 * first.x1 - second.x1 * first.x2);
|
float x3 = (second.x3 * first.s0 + second.s0 * first.x3) - (second.x2 * first.x1 - second.x1 * first.x2);
|
||||||
|
|
||||||
float squareModule = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
float squareModule = (s0 * s0 + x1 * x1) + (x2 * x2 + x3 * x3);
|
||||||
|
|
||||||
result.corrector = 2.0f - squareModule;
|
result.corrector = 2.0f - squareModule;
|
||||||
result.s0 = s0;
|
result.s0 = s0;
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
|
|
||||||
if (squareModule < 1.0f - SPUtility.TWO_EPSYLON || 1.0f + SPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0f - F32Utility.TWO_EPSYLON || 1.0f + F32Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
result.Normalize(squareModule);
|
result.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadIdle(out SPVersor versor)
|
public static void LoadIdle(out F32Versor versor)
|
||||||
{
|
{
|
||||||
versor.corrector = 1.0f;
|
versor.corrector = 1.0f;
|
||||||
versor.s0 = 1.0f;
|
versor.s0 = 1.0f;
|
||||||
versor.x1 = 0.0f;
|
versor.x1 = 0.0f;
|
||||||
versor.x2 = 0.0f;
|
versor.x2 = 0.0f;
|
||||||
versor.x3 = 0.0f;
|
versor.x3 = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
133
BGC/F64Angle.cs
Normal file
133
BGC/F64Angle.cs
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 1 Feb 2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public static class F64Angle
|
||||||
|
{
|
||||||
|
public static double ToRadians(double angle, AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return angle * F64Degrees.RADIANS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return angle * F64Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ToDegrees(double angle, AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return angle * F64Radians.DEGREES_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return angle * 360.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ToTurns(double angle, AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return angle * F64Radians.TURNS_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return angle * F64Degrees.TURNS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double GetFullCircle(AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return 360.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return F64Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double GetHalfCircle(AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
return F64Radians.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double GetQuarterCircle(AngleUnit unit)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return 90.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return 0.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
return F64Radians.HALF_OF_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double Normalize(double angle, AngleUnit unit, AngleRange range)
|
||||||
|
{
|
||||||
|
if (unit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return F64Degrees.Normalize(angle, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return F64Turns.Normalize(angle, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
return F64Radians.Normalize(angle, range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
68
BGC/F64Degrees.cs
Normal file
68
BGC/F64Degrees.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 18 Nov 2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public class F64Degrees
|
||||||
|
{
|
||||||
|
public const double RADIANS_IN_DEGREE = 1.74532925199432958E-2;
|
||||||
|
public const double TURNS_IN_DEGREE = 2.77777777777777778E-3;
|
||||||
|
|
||||||
|
public static double ToRadians(double degrees)
|
||||||
|
{
|
||||||
|
return degrees * RADIANS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ToTurns(double degrees)
|
||||||
|
{
|
||||||
|
return degrees * TURNS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ToUnits(double degrees, AngleUnit toUnit)
|
||||||
|
{
|
||||||
|
if (toUnit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return degrees * RADIANS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUnit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return degrees * TURNS_IN_DEGREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double Normalize(double degrees, AngleRange range)
|
||||||
|
{
|
||||||
|
if (range == AngleRange.UNSIGNED_RANGE)
|
||||||
|
{
|
||||||
|
if (0.0 <= degrees && degrees < 360.0)
|
||||||
|
{
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (-180.0 < degrees && degrees <= 180.0)
|
||||||
|
{
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double turns = degrees * TURNS_IN_DEGREE;
|
||||||
|
|
||||||
|
turns -= Math.Floor(turns);
|
||||||
|
|
||||||
|
if (range == AngleRange.SIGNED_RANGE && turns > 0.5)
|
||||||
|
{
|
||||||
|
turns -= 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return turns * 360.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,352 +1,352 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 10 Feb 2019
|
* Date: 10 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPMatrix2x2
|
public struct F64Matrix2x2
|
||||||
{
|
{
|
||||||
public double r1c1, r1c2;
|
public double r1c1, r1c2;
|
||||||
|
|
||||||
public double r2c1, r2c2;
|
public double r2c1, r2c2;
|
||||||
|
|
||||||
public DPMatrix2x2()
|
public F64Matrix2x2()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0;
|
this.r1c1 = 0.0;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
||||||
this.r2c1 = 0.0;
|
this.r2c1 = 0.0;
|
||||||
this.r2c2 = 0.0;
|
this.r2c2 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix2x2(double d1, double d2)
|
public F64Matrix2x2(double d1, double d2)
|
||||||
{
|
{
|
||||||
this.r1c1 = d1;
|
this.r1c1 = d1;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
||||||
this.r2c1 = 0.0;
|
this.r2c1 = 0.0;
|
||||||
this.r2c2 = d2;
|
this.r2c2 = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix2x2(in DPMatrix2x2 matrix)
|
public F64Matrix2x2(in F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = matrix.r2c1;
|
this.r2c1 = matrix.r2c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix2x2(in SPMatrix2x2 matrix)
|
public F64Matrix2x2(in F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = matrix.r2c1;
|
this.r2c1 = matrix.r2c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly double GetDeterminant()
|
public readonly double GetDeterminant()
|
||||||
{
|
{
|
||||||
return this.r1c1 * this.r2c2 - this.r1c2 * this.r2c1;
|
return this.r1c1 * this.r2c2 - this.r1c2 * this.r2c1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsSingular()
|
public readonly bool IsSingular()
|
||||||
{
|
{
|
||||||
double determinant = this.GetDeterminant();
|
double determinant = this.GetDeterminant();
|
||||||
return -DPUtility.EPSYLON <= determinant && determinant <= DPUtility.EPSYLON;
|
return -F64Utility.EPSYLON <= determinant && determinant <= F64Utility.EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Transpose()
|
public void Transpose()
|
||||||
{
|
{
|
||||||
(this.r1c2, this.r2c1) = (this.r2c1, this.r1c2);
|
(this.r1c2, this.r2c1) = (this.r2c1, this.r1c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Invert()
|
public bool Invert()
|
||||||
{
|
{
|
||||||
double determinant = this.GetDeterminant();
|
double determinant = this.GetDeterminant();
|
||||||
|
|
||||||
if (-DPUtility.EPSYLON <= determinant && determinant <= DPUtility.EPSYLON)
|
if (-F64Utility.EPSYLON <= determinant && determinant <= F64Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double r1c1 = this.r2c2;
|
double r1c1 = this.r2c2;
|
||||||
double r1c2 = -this.r1c2;
|
double r1c2 = -this.r1c2;
|
||||||
|
|
||||||
double r2c1 = -this.r2c1;
|
double r2c1 = -this.r2c1;
|
||||||
double r2c2 = this.r1c1;
|
double r2c2 = this.r1c1;
|
||||||
|
|
||||||
this.r1c1 = r1c1 / determinant;
|
this.r1c1 = r1c1 / determinant;
|
||||||
this.r1c2 = r1c2 / determinant;
|
this.r1c2 = r1c2 / determinant;
|
||||||
|
|
||||||
this.r2c1 = r2c1 / determinant;
|
this.r2c1 = r2c1 / determinant;
|
||||||
this.r2c2 = r2c2 / determinant;
|
this.r2c2 = r2c2 / determinant;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0;
|
this.r1c1 = 0.0;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
||||||
this.r2c1 = 0.0;
|
this.r2c1 = 0.0;
|
||||||
this.r2c2 = 0.0;
|
this.r2c2 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetToIdentity()
|
public void SetToIdentity()
|
||||||
{
|
{
|
||||||
this.r1c1 = 1.0;
|
this.r1c1 = 1.0;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
||||||
this.r2c1 = 0.0;
|
this.r2c1 = 0.0;
|
||||||
this.r2c2 = 1.0;
|
this.r2c2 = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetToDiagonal(double d1, double d2)
|
public void SetToDiagonal(double d1, double d2)
|
||||||
{
|
{
|
||||||
this.r1c1 = d1;
|
this.r1c1 = d1;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
||||||
this.r2c1 = 0.0;
|
this.r2c1 = 0.0;
|
||||||
this.r2c2 = d2;
|
this.r2c2 = d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPMatrix2x2 matrix)
|
public void SetValues(in F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = matrix.r2c1;
|
this.r2c1 = matrix.r2c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPMatrix2x2 matrix)
|
public void SetValues(in F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
||||||
this.r2c1 = matrix.r2c1;
|
this.r2c1 = matrix.r2c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposedOf(in DPMatrix2x2 matrix)
|
public void SetTransposedOf(in F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
(this.r1c2, this.r2c1) = (matrix.r2c1, matrix.r1c2);
|
(this.r1c2, this.r2c1) = (matrix.r2c1, matrix.r1c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposedOf(in SPMatrix2x2 matrix)
|
public void SetTransposedOf(in F32Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
||||||
this.r2c1 = matrix.r1c2;
|
this.r2c1 = matrix.r1c2;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SetInvertedOf(in DPMatrix2x2 matrix)
|
public bool SetInvertedOf(in F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
double determinant = matrix.GetDeterminant();
|
double determinant = matrix.GetDeterminant();
|
||||||
|
|
||||||
if (-DPUtility.EPSYLON <= determinant && determinant <= DPUtility.EPSYLON)
|
if (-F64Utility.EPSYLON <= determinant && determinant <= F64Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double r1c1 = matrix.r2c2;
|
double r1c1 = matrix.r2c2;
|
||||||
double r1c2 = -matrix.r1c2;
|
double r1c2 = -matrix.r1c2;
|
||||||
|
|
||||||
double r2c1 = -matrix.r2c1;
|
double r2c1 = -matrix.r2c1;
|
||||||
double r2c2 = matrix.r1c1;
|
double r2c2 = matrix.r1c1;
|
||||||
|
|
||||||
this.r1c1 = r1c1 / determinant;
|
this.r1c1 = r1c1 / determinant;
|
||||||
this.r1c2 = r1c2 / determinant;
|
this.r1c2 = r1c2 / determinant;
|
||||||
|
|
||||||
this.r2c1 = r2c1 / determinant;
|
this.r2c1 = r2c1 / determinant;
|
||||||
this.r2c2 = r2c2 / determinant;
|
this.r2c2 = r2c2 / determinant;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRow1(double c1, double c2)
|
public void SetRow1(double c1, double c2)
|
||||||
{
|
{
|
||||||
this.r1c1 = c1;
|
this.r1c1 = c1;
|
||||||
this.r1c2 = c2;
|
this.r1c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRow2(double c1, double c2)
|
public void SetRow2(double c1, double c2)
|
||||||
{
|
{
|
||||||
this.r2c1 = c1;
|
this.r2c1 = c1;
|
||||||
this.r2c2 = c2;
|
this.r2c2 = c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetColumn1(double r1, double r2)
|
public void SetColumn1(double r1, double r2)
|
||||||
{
|
{
|
||||||
this.r1c1 = r1;
|
this.r1c1 = r1;
|
||||||
this.r2c1 = r2;
|
this.r2c1 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetColumn2(double r1, double r2)
|
public void SetColumn2(double r1, double r2)
|
||||||
{
|
{
|
||||||
this.r1c2 = r1;
|
this.r1c2 = r1;
|
||||||
this.r2c2 = r2;
|
this.r2c2 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in DPMatrix2x2 matrix1, in DPMatrix2x2 matrix2, out DPMatrix2x2 sum)
|
public static void Add(in F64Matrix2x2 matrix1, in F64Matrix2x2 matrix2, out F64Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
||||||
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
||||||
|
|
||||||
sum.r2c1 = matrix1.r2c1 + matrix2.r2c1;
|
sum.r2c1 = matrix1.r2c1 + matrix2.r2c1;
|
||||||
sum.r2c2 = matrix1.r2c2 + matrix2.r2c2;
|
sum.r2c2 = matrix1.r2c2 + matrix2.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in DPMatrix2x2 minuend, in DPMatrix2x2 subtrahend, out DPMatrix2x2 difference)
|
public static void Subtract(in F64Matrix2x2 minuend, in F64Matrix2x2 subtrahend, out F64Matrix2x2 difference)
|
||||||
{
|
{
|
||||||
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
||||||
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
||||||
|
|
||||||
difference.r2c1 = minuend.r2c1 - subtrahend.r2c1;
|
difference.r2c1 = minuend.r2c1 - subtrahend.r2c1;
|
||||||
difference.r2c2 = minuend.r2c2 - subtrahend.r2c2;
|
difference.r2c2 = minuend.r2c2 - subtrahend.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in DPMatrix2x2 multiplicand, double multiplier, out DPMatrix2x2 product)
|
public static void Multiply(in F64Matrix2x2 multiplicand, double multiplier, out F64Matrix2x2 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = multiplicand.r1c1 * multiplier;
|
product.r1c1 = multiplicand.r1c1 * multiplier;
|
||||||
product.r1c2 = multiplicand.r1c2 * multiplier;
|
product.r1c2 = multiplicand.r1c2 * multiplier;
|
||||||
|
|
||||||
product.r2c1 = multiplicand.r2c1 * multiplier;
|
product.r2c1 = multiplicand.r2c1 * multiplier;
|
||||||
product.r2c2 = multiplicand.r2c2 * multiplier;
|
product.r2c2 = multiplicand.r2c2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in DPMatrix2x2 dividend, double divisor, out DPMatrix2x2 quotient)
|
public static void Divide(in F64Matrix2x2 dividend, double divisor, out F64Matrix2x2 quotient)
|
||||||
{
|
{
|
||||||
quotient.r1c1 = dividend.r1c1 / divisor;
|
quotient.r1c1 = dividend.r1c1 / divisor;
|
||||||
quotient.r1c2 = dividend.r1c2 / divisor;
|
quotient.r1c2 = dividend.r1c2 / divisor;
|
||||||
|
|
||||||
quotient.r2c1 = dividend.r2c1 / divisor;
|
quotient.r2c1 = dividend.r2c1 / divisor;
|
||||||
quotient.r2c2 = dividend.r2c2 / divisor;
|
quotient.r2c2 = dividend.r2c2 / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
double weight1, in DPMatrix2x2 matrix1,
|
double weight1, in F64Matrix2x2 matrix1,
|
||||||
double weight2, in DPMatrix2x2 matrix2,
|
double weight2, in F64Matrix2x2 matrix2,
|
||||||
out DPMatrix2x2 sum)
|
out F64Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
||||||
|
|
||||||
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2;
|
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2;
|
||||||
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2;
|
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
float weight1, in SPMatrix2x2 matrix1,
|
float weight1, in F32Matrix2x2 matrix1,
|
||||||
float weight2, in SPMatrix2x2 matrix2,
|
float weight2, in F32Matrix2x2 matrix2,
|
||||||
float weight3, in SPMatrix2x2 matrix3,
|
float weight3, in F32Matrix2x2 matrix3,
|
||||||
out DPMatrix2x2 sum)
|
out F64Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
||||||
|
|
||||||
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2 + matrix3.r2c1 * weight3;
|
sum.r2c1 = matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2 + matrix3.r2c1 * weight3;
|
||||||
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2 + matrix3.r2c2 * weight3;
|
sum.r2c2 = matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2 + matrix3.r2c2 * weight3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
float weight1, in SPMatrix2x2 matrix1,
|
float weight1, in F32Matrix2x2 matrix1,
|
||||||
float weight2, in SPMatrix2x2 matrix2,
|
float weight2, in F32Matrix2x2 matrix2,
|
||||||
float weight3, in SPMatrix2x2 matrix3,
|
float weight3, in F32Matrix2x2 matrix3,
|
||||||
float weight4, in SPMatrix2x2 matrix4,
|
float weight4, in F32Matrix2x2 matrix4,
|
||||||
out DPMatrix2x2 sum)
|
out F64Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
||||||
|
|
||||||
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4);
|
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4);
|
||||||
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4);
|
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
double weight1, in DPMatrix2x2 matrix1,
|
double weight1, in F64Matrix2x2 matrix1,
|
||||||
double weight2, in DPMatrix2x2 matrix2,
|
double weight2, in F64Matrix2x2 matrix2,
|
||||||
double weight3, in DPMatrix2x2 matrix3,
|
double weight3, in F64Matrix2x2 matrix3,
|
||||||
double weight4, in DPMatrix2x2 matrix4,
|
double weight4, in F64Matrix2x2 matrix4,
|
||||||
double weight5, in DPMatrix2x2 matrix5,
|
double weight5, in F64Matrix2x2 matrix5,
|
||||||
out DPMatrix2x2 sum)
|
out F64Matrix2x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
||||||
|
|
||||||
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4) + matrix5.r2c1 * weight5;
|
sum.r2c1 = (matrix1.r2c1 * weight1 + matrix2.r2c1 * weight2) + (matrix3.r2c1 * weight3 + matrix4.r2c1 * weight4) + matrix5.r2c1 * weight5;
|
||||||
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4) + matrix5.r2c2 * weight5;
|
sum.r2c2 = (matrix1.r2c2 * weight1 + matrix2.r2c2 * weight2) + (matrix3.r2c2 * weight3 + matrix4.r2c2 * weight4) + matrix5.r2c2 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetRightProduct(in DPMatrix2x2 matrix, in DPVector2 vector, out DPVector2 result)
|
public static void GetRightProduct(in F64Matrix2x2 matrix, in F64Vector2 vector, out F64Vector2 result)
|
||||||
{
|
{
|
||||||
double x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
double x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
||||||
double x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
double x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
||||||
|
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetLeftProduct(in DPVector2 vector, in DPMatrix2x2 matrix, out DPVector2 result)
|
public static void GetLeftProduct(in F64Vector2 vector, in F64Matrix2x2 matrix, out F64Vector2 result)
|
||||||
{
|
{
|
||||||
double x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
double x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
||||||
double x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
double x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
||||||
|
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadZero(out DPMatrix2x2 matrix)
|
public static void LoadZero(out F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = 0.0;
|
matrix.r1c1 = 0.0;
|
||||||
matrix.r1c2 = 0.0;
|
matrix.r1c2 = 0.0;
|
||||||
|
|
||||||
matrix.r2c1 = 0.0;
|
matrix.r2c1 = 0.0;
|
||||||
matrix.r2c2 = 0.0;
|
matrix.r2c2 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadIdentity(out DPMatrix2x2 matrix)
|
public static void LoadIdentity(out F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = 1.0;
|
matrix.r1c1 = 1.0;
|
||||||
matrix.r1c2 = 0.0;
|
matrix.r1c2 = 0.0;
|
||||||
|
|
||||||
matrix.r2c1 = 0.0;
|
matrix.r2c1 = 0.0;
|
||||||
matrix.r2c2 = 1.0;
|
matrix.r2c2 = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadDiagonal(double d1, double d2, out DPMatrix2x2 matrix)
|
public static void LoadDiagonal(double d1, double d2, out F64Matrix2x2 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = d1;
|
matrix.r1c1 = d1;
|
||||||
matrix.r1c2 = 0.0;
|
matrix.r1c2 = 0.0;
|
||||||
|
|
||||||
matrix.r2c1 = 0.0;
|
matrix.r2c1 = 0.0;
|
||||||
matrix.r2c2 = d2;
|
matrix.r2c2 = d2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,15 +20,15 @@ using System;
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 11 Nov 2024
|
* Date: 11 Nov 2024
|
||||||
*/
|
*/
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPMatrix2x3
|
public struct F64Matrix2x3
|
||||||
{
|
{
|
||||||
public double r1c1, r1c2;
|
public double r1c1, r1c2;
|
||||||
public double r2c1, r2c2;
|
public double r2c1, r2c2;
|
||||||
public double r3c1, r3c2;
|
public double r3c1, r3c2;
|
||||||
|
|
||||||
public DPMatrix2x3()
|
public F64Matrix2x3()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0;
|
this.r1c1 = 0.0;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Geometry
|
||||||
this.r3c2 = 0.0;
|
this.r3c2 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix2x3(in DPMatrix2x3 matrix)
|
public F64Matrix2x3(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r3c2;
|
this.r3c2 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix2x3(in SPMatrix2x3 matrix)
|
public F64Matrix2x3(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r3c2;
|
this.r3c2 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix2x3(in DPMatrix3x2 matrix)
|
public F64Matrix2x3(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -76,7 +76,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r2c3;
|
this.r3c2 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix2x3(in SPMatrix3x2 matrix)
|
public F64Matrix2x3(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Geometry
|
||||||
this.r3c2 = 0.0;
|
this.r3c2 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPMatrix2x3 matrix)
|
public void SetValues(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -112,7 +112,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r3c2;
|
this.r3c2 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPMatrix2x3 matrix)
|
public void SetValues(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -124,7 +124,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r3c2;
|
this.r3c2 = matrix.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in DPMatrix3x2 matrix)
|
public void SetTransposed(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Geometry
|
||||||
this.r3c2 = matrix.r2c3;
|
this.r3c2 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in SPMatrix3x2 matrix)
|
public void SetTransposed(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -180,7 +180,7 @@ namespace Geometry
|
||||||
this.r3c2 = r3;
|
this.r3c2 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in DPMatrix2x3 matrix1, in DPMatrix2x3 matrix2, out DPMatrix2x3 sum)
|
public static void Add(in F64Matrix2x3 matrix1, in F64Matrix2x3 matrix2, out F64Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
||||||
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Geometry
|
||||||
sum.r3c2 = matrix1.r3c2 + matrix2.r3c2;
|
sum.r3c2 = matrix1.r3c2 + matrix2.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in DPMatrix2x3 minuend, in DPMatrix2x3 subtrahend, out DPMatrix2x3 difference)
|
public static void Subtract(in F64Matrix2x3 minuend, in F64Matrix2x3 subtrahend, out F64Matrix2x3 difference)
|
||||||
{
|
{
|
||||||
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
||||||
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
||||||
|
|
@ -204,7 +204,7 @@ namespace Geometry
|
||||||
difference.r3c2 = minuend.r3c2 - subtrahend.r3c2;
|
difference.r3c2 = minuend.r3c2 - subtrahend.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in DPMatrix2x3 multiplicand, double multiplier, out DPMatrix2x3 product)
|
public static void Multiply(in F64Matrix2x3 multiplicand, double multiplier, out F64Matrix2x3 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = multiplicand.r1c1 * multiplier;
|
product.r1c1 = multiplicand.r1c1 * multiplier;
|
||||||
product.r1c2 = multiplicand.r1c2 * multiplier;
|
product.r1c2 = multiplicand.r1c2 * multiplier;
|
||||||
|
|
@ -216,7 +216,7 @@ namespace Geometry
|
||||||
product.r3c2 = multiplicand.r3c2 * multiplier;
|
product.r3c2 = multiplicand.r3c2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in DPMatrix2x3 dividend, double divisor, out DPMatrix2x3 quotient)
|
public static void Divide(in F64Matrix2x3 dividend, double divisor, out F64Matrix2x3 quotient)
|
||||||
{
|
{
|
||||||
quotient.r1c1 = dividend.r1c1 / divisor;
|
quotient.r1c1 = dividend.r1c1 / divisor;
|
||||||
quotient.r1c2 = dividend.r1c2 / divisor;
|
quotient.r1c2 = dividend.r1c2 / divisor;
|
||||||
|
|
@ -229,9 +229,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
double weight1, in DPMatrix2x3 matrix1,
|
double weight1, in F64Matrix2x3 matrix1,
|
||||||
double weight2, in DPMatrix2x3 matrix2,
|
double weight2, in F64Matrix2x3 matrix2,
|
||||||
out DPMatrix2x3 sum)
|
out F64Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
||||||
|
|
@ -244,10 +244,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
double weight1, in DPMatrix2x3 matrix1,
|
double weight1, in F64Matrix2x3 matrix1,
|
||||||
double weight2, in DPMatrix2x3 matrix2,
|
double weight2, in F64Matrix2x3 matrix2,
|
||||||
double weight3, in DPMatrix2x3 matrix3,
|
double weight3, in F64Matrix2x3 matrix3,
|
||||||
out DPMatrix2x3 sum)
|
out F64Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
||||||
|
|
@ -260,11 +260,11 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
double weight1, in DPMatrix2x3 matrix1,
|
double weight1, in F64Matrix2x3 matrix1,
|
||||||
double weight2, in DPMatrix2x3 matrix2,
|
double weight2, in F64Matrix2x3 matrix2,
|
||||||
double weight3, in DPMatrix2x3 matrix3,
|
double weight3, in F64Matrix2x3 matrix3,
|
||||||
double weight4, in DPMatrix2x3 matrix4,
|
double weight4, in F64Matrix2x3 matrix4,
|
||||||
out DPMatrix2x3 sum)
|
out F64Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
||||||
|
|
@ -277,12 +277,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
double weight1, in DPMatrix2x3 matrix1,
|
double weight1, in F64Matrix2x3 matrix1,
|
||||||
double weight2, in DPMatrix2x3 matrix2,
|
double weight2, in F64Matrix2x3 matrix2,
|
||||||
double weight3, in DPMatrix2x3 matrix3,
|
double weight3, in F64Matrix2x3 matrix3,
|
||||||
double weight4, in DPMatrix2x3 matrix4,
|
double weight4, in F64Matrix2x3 matrix4,
|
||||||
double weight5, in DPMatrix2x3 matrix5,
|
double weight5, in F64Matrix2x3 matrix5,
|
||||||
out DPMatrix2x3 sum)
|
out F64Matrix2x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
||||||
|
|
@ -294,14 +294,14 @@ namespace Geometry
|
||||||
sum.r3c2 = (matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2) + (matrix3.r3c2 * weight3 + matrix4.r3c2 * weight4) + matrix5.r3c2 * weight5;
|
sum.r3c2 = (matrix1.r3c2 * weight1 + matrix2.r3c2 * weight2) + (matrix3.r3c2 * weight3 + matrix4.r3c2 * weight4) + matrix5.r3c2 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetRightProduct(in DPMatrix2x3 matrix, in DPVector2 vector, out DPVector3 result)
|
public static void GetRightProduct(in F64Matrix2x3 matrix, in F64Vector2 vector, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2;
|
||||||
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2;
|
||||||
result.x3 = matrix.r3c1 * vector.x1 + matrix.r3c2 * vector.x2;
|
result.x3 = matrix.r3c1 * vector.x1 + matrix.r3c2 * vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetLeftProduct(in DPVector3 vector, in DPMatrix2x3 matrix, out DPVector2 result)
|
public static void GetLeftProduct(in F64Vector3 vector, in F64Matrix2x3 matrix, out F64Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1 + vector.x3 * matrix.r3c1;
|
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1 + vector.x3 * matrix.r3c1;
|
||||||
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2 + vector.x3 * matrix.r3c2;
|
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2 + vector.x3 * matrix.r3c2;
|
||||||
|
|
@ -20,14 +20,14 @@ using System;
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 11 Nov 2024
|
* Date: 11 Nov 2024
|
||||||
*/
|
*/
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPMatrix3x2
|
public struct F64Matrix3x2
|
||||||
{
|
{
|
||||||
public double r1c1, r1c2, r1c3;
|
public double r1c1, r1c2, r1c3;
|
||||||
public double r2c1, r2c2, r2c3;
|
public double r2c1, r2c2, r2c3;
|
||||||
|
|
||||||
public DPMatrix3x2()
|
public F64Matrix3x2()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0;
|
this.r1c1 = 0.0;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Geometry
|
||||||
this.r2c3 = 0.0;
|
this.r2c3 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix3x2(in DPMatrix3x2 matrix)
|
public F64Matrix3x2(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c3;
|
this.r2c3 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix3x2(in SPMatrix3x2 matrix)
|
public F64Matrix3x2(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -60,7 +60,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c3;
|
this.r2c3 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix3x2(in DPMatrix2x3 matrix)
|
public F64Matrix3x2(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -71,7 +71,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c2;
|
this.r2c3 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix3x2(in SPMatrix2x3 matrix)
|
public F64Matrix3x2(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetValues(in DPMatrix3x2 matrix)
|
public void SetValues(in F64Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -105,7 +105,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c3;
|
this.r2c3 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPMatrix3x2 matrix)
|
public void SetValues(in F32Matrix3x2 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -116,7 +116,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c3;
|
this.r2c3 = matrix.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in DPMatrix2x3 matrix)
|
public void SetTransposed(in F64Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Geometry
|
||||||
this.r2c3 = matrix.r2c2;
|
this.r2c3 = matrix.r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposed(in SPMatrix2x3 matrix)
|
public void SetTransposed(in F32Matrix2x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r2c1;
|
this.r1c2 = matrix.r2c1;
|
||||||
|
|
@ -170,7 +170,7 @@ namespace Geometry
|
||||||
this.r2c3 = r2;
|
this.r2c3 = r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in DPMatrix3x2 matrix1, in DPMatrix3x2 matrix2, out DPMatrix3x2 sum)
|
public static void Add(in F64Matrix3x2 matrix1, in F64Matrix3x2 matrix2, out F64Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
||||||
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
||||||
|
|
@ -181,7 +181,7 @@ namespace Geometry
|
||||||
sum.r2c3 = matrix1.r2c3 + matrix2.r2c3;
|
sum.r2c3 = matrix1.r2c3 + matrix2.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in DPMatrix3x2 minuend, in DPMatrix3x2 subtrahend, out DPMatrix3x2 difference)
|
public static void Subtract(in F64Matrix3x2 minuend, in F64Matrix3x2 subtrahend, out F64Matrix3x2 difference)
|
||||||
{
|
{
|
||||||
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
||||||
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Geometry
|
||||||
difference.r2c3 = minuend.r2c3 - subtrahend.r2c3;
|
difference.r2c3 = minuend.r2c3 - subtrahend.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in DPMatrix3x2 multiplicand, double multiplier, out DPMatrix3x2 product)
|
public static void Multiply(in F64Matrix3x2 multiplicand, double multiplier, out F64Matrix3x2 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = multiplicand.r1c1 * multiplier;
|
product.r1c1 = multiplicand.r1c1 * multiplier;
|
||||||
product.r1c2 = multiplicand.r1c2 * multiplier;
|
product.r1c2 = multiplicand.r1c2 * multiplier;
|
||||||
|
|
@ -203,7 +203,7 @@ namespace Geometry
|
||||||
product.r2c3 = multiplicand.r2c3 * multiplier;
|
product.r2c3 = multiplicand.r2c3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in DPMatrix3x2 dividend, double divisor, out DPMatrix3x2 quotient)
|
public static void Divide(in F64Matrix3x2 dividend, double divisor, out F64Matrix3x2 quotient)
|
||||||
{
|
{
|
||||||
quotient.r1c1 = dividend.r1c1 / divisor;
|
quotient.r1c1 = dividend.r1c1 / divisor;
|
||||||
quotient.r1c2 = dividend.r1c2 / divisor;
|
quotient.r1c2 = dividend.r1c2 / divisor;
|
||||||
|
|
@ -215,9 +215,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
double weight1, in DPMatrix3x2 matrix1,
|
double weight1, in F64Matrix3x2 matrix1,
|
||||||
double weight2, in DPMatrix3x2 matrix2,
|
double weight2, in F64Matrix3x2 matrix2,
|
||||||
out DPMatrix3x2 sum)
|
out F64Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
||||||
|
|
@ -229,10 +229,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
double weight1, in DPMatrix3x2 matrix1,
|
double weight1, in F64Matrix3x2 matrix1,
|
||||||
double weight2, in DPMatrix3x2 matrix2,
|
double weight2, in F64Matrix3x2 matrix2,
|
||||||
double weight3, in DPMatrix3x2 matrix3,
|
double weight3, in F64Matrix3x2 matrix3,
|
||||||
out DPMatrix3x2 sum)
|
out F64Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
||||||
|
|
@ -244,11 +244,11 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
double weight1, in DPMatrix3x2 matrix1,
|
double weight1, in F64Matrix3x2 matrix1,
|
||||||
double weight2, in DPMatrix3x2 matrix2,
|
double weight2, in F64Matrix3x2 matrix2,
|
||||||
double weight3, in DPMatrix3x2 matrix3,
|
double weight3, in F64Matrix3x2 matrix3,
|
||||||
double weight4, in DPMatrix3x2 matrix4,
|
double weight4, in F64Matrix3x2 matrix4,
|
||||||
out DPMatrix3x2 sum)
|
out F64Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
||||||
|
|
@ -260,12 +260,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
double weight1, in DPMatrix3x2 matrix1,
|
double weight1, in F64Matrix3x2 matrix1,
|
||||||
double weight2, in DPMatrix3x2 matrix2,
|
double weight2, in F64Matrix3x2 matrix2,
|
||||||
double weight3, in DPMatrix3x2 matrix3,
|
double weight3, in F64Matrix3x2 matrix3,
|
||||||
double weight4, in DPMatrix3x2 matrix4,
|
double weight4, in F64Matrix3x2 matrix4,
|
||||||
double weight5, in DPMatrix3x2 matrix5,
|
double weight5, in F64Matrix3x2 matrix5,
|
||||||
out DPMatrix3x2 sum)
|
out F64Matrix3x2 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
||||||
|
|
@ -276,13 +276,13 @@ namespace Geometry
|
||||||
sum.r2c3 = (matrix1.r2c3 * weight1 + matrix2.r2c3 * weight2) + (matrix3.r2c3 * weight3 + matrix4.r2c3 * weight4) + matrix5.r2c3 * weight5;
|
sum.r2c3 = (matrix1.r2c3 * weight1 + matrix2.r2c3 * weight2) + (matrix3.r2c3 * weight3 + matrix4.r2c3 * weight4) + matrix5.r2c3 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetRightProduct(in DPMatrix3x2 matrix, in DPVector3 vector, out DPVector2 result)
|
public static void GetRightProduct(in F64Matrix3x2 matrix, in F64Vector3 vector, out F64Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2 + matrix.r1c3 * vector.x3;
|
result.x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2 + matrix.r1c3 * vector.x3;
|
||||||
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2 + matrix.r2c3 * vector.x3;
|
result.x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2 + matrix.r2c3 * vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetLeftProduct(in DPVector2 vector, in DPMatrix3x2 matrix, out DPVector3 result)
|
public static void GetLeftProduct(in F64Vector2 vector, in F64Matrix3x2 matrix, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
result.x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1;
|
||||||
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
result.x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2;
|
||||||
|
|
@ -21,9 +21,9 @@ using System;
|
||||||
* Date: 10 Feb 2019
|
* Date: 10 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPMatrix3x3
|
public struct F64Matrix3x3
|
||||||
{
|
{
|
||||||
public double r1c1, r1c2, r1c3;
|
public double r1c1, r1c2, r1c3;
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Geometry
|
||||||
|
|
||||||
public double r3c1, r3c2, r3c3;
|
public double r3c1, r3c2, r3c3;
|
||||||
|
|
||||||
public DPMatrix3x3()
|
public F64Matrix3x3()
|
||||||
{
|
{
|
||||||
this.r1c1 = 0.0;
|
this.r1c1 = 0.0;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Geometry
|
||||||
this.r3c3 = 0.0;
|
this.r3c3 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix3x3(double d1, double d2, double d3)
|
public F64Matrix3x3(double d1, double d2, double d3)
|
||||||
{
|
{
|
||||||
this.r1c1 = d1;
|
this.r1c1 = d1;
|
||||||
this.r1c2 = 0.0;
|
this.r1c2 = 0.0;
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Geometry
|
||||||
this.r3c3 = d3;
|
this.r3c3 = d3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix3x3(in DPMatrix3x3 matrix)
|
public F64Matrix3x3(in F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -76,7 +76,7 @@ namespace Geometry
|
||||||
this.r3c3 = matrix.r3c3;
|
this.r3c3 = matrix.r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPMatrix3x3(in SPMatrix3x3 matrix)
|
public F64Matrix3x3(in F32Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -101,7 +101,7 @@ namespace Geometry
|
||||||
public readonly bool IsSingular()
|
public readonly bool IsSingular()
|
||||||
{
|
{
|
||||||
double determinant = this.GetDeterminant();
|
double determinant = this.GetDeterminant();
|
||||||
return -DPUtility.EPSYLON <= determinant && determinant <= DPUtility.EPSYLON;
|
return -F64Utility.EPSYLON <= determinant && determinant <= F64Utility.EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Transpose()
|
public void Transpose()
|
||||||
|
|
@ -115,7 +115,7 @@ namespace Geometry
|
||||||
{
|
{
|
||||||
double determinant = this.GetDeterminant();
|
double determinant = this.GetDeterminant();
|
||||||
|
|
||||||
if (-DPUtility.EPSYLON <= determinant && determinant <= DPUtility.EPSYLON) {
|
if (-F64Utility.EPSYLON <= determinant && determinant <= F64Utility.EPSYLON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,7 +191,7 @@ namespace Geometry
|
||||||
this.r2c3 = d3;
|
this.r2c3 = d3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(DPMatrix3x3 matrix)
|
public void SetValues(F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -206,7 +206,7 @@ namespace Geometry
|
||||||
this.r3c3 = matrix.r3c3;
|
this.r3c3 = matrix.r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(SPMatrix3x3 matrix)
|
public void SetValues(F32Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r1c2 = matrix.r1c2;
|
this.r1c2 = matrix.r1c2;
|
||||||
|
|
@ -221,7 +221,7 @@ namespace Geometry
|
||||||
this.r3c3 = matrix.r3c3;
|
this.r3c3 = matrix.r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposedOf(in DPMatrix3x3 matrix)
|
public void SetTransposedOf(in F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
|
|
@ -232,7 +232,7 @@ namespace Geometry
|
||||||
(this.r2c3, this.r3c2) = (matrix.r3c2, matrix.r2c3);
|
(this.r2c3, this.r3c2) = (matrix.r3c2, matrix.r2c3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetTransposedOf(in SPMatrix3x3 matrix)
|
public void SetTransposedOf(in F32Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
this.r1c1 = matrix.r1c1;
|
this.r1c1 = matrix.r1c1;
|
||||||
this.r2c2 = matrix.r2c2;
|
this.r2c2 = matrix.r2c2;
|
||||||
|
|
@ -243,11 +243,11 @@ namespace Geometry
|
||||||
(this.r2c3, this.r3c2) = (matrix.r3c2, matrix.r2c3);
|
(this.r2c3, this.r3c2) = (matrix.r3c2, matrix.r2c3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SetInvertedOf(in DPMatrix3x3 matrix)
|
public bool SetInvertedOf(in F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
double determinant = matrix.GetDeterminant();
|
double determinant = matrix.GetDeterminant();
|
||||||
|
|
||||||
if (-DPUtility.EPSYLON <= determinant && determinant <= DPUtility.EPSYLON) {
|
if (-F64Utility.EPSYLON <= determinant && determinant <= F64Utility.EPSYLON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -320,7 +320,7 @@ namespace Geometry
|
||||||
this.r3c3 = r3;
|
this.r3c3 = r3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in DPMatrix3x3 matrix1, in DPMatrix3x3 matrix2, out DPMatrix3x3 sum)
|
public static void Add(in F64Matrix3x3 matrix1, in F64Matrix3x3 matrix2, out F64Matrix3x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
sum.r1c1 = matrix1.r1c1 + matrix2.r1c1;
|
||||||
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
sum.r1c2 = matrix1.r1c2 + matrix2.r1c2;
|
||||||
|
|
@ -335,7 +335,7 @@ namespace Geometry
|
||||||
sum.r3c3 = matrix1.r3c3 + matrix2.r3c3;
|
sum.r3c3 = matrix1.r3c3 + matrix2.r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in DPMatrix3x3 minuend, in DPMatrix3x3 subtrahend, out DPMatrix3x3 difference)
|
public static void Subtract(in F64Matrix3x3 minuend, in F64Matrix3x3 subtrahend, out F64Matrix3x3 difference)
|
||||||
{
|
{
|
||||||
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
difference.r1c1 = minuend.r1c1 - subtrahend.r1c1;
|
||||||
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
difference.r1c2 = minuend.r1c2 - subtrahend.r1c2;
|
||||||
|
|
@ -350,7 +350,7 @@ namespace Geometry
|
||||||
difference.r3c3 = minuend.r3c3 - subtrahend.r3c3;
|
difference.r3c3 = minuend.r3c3 - subtrahend.r3c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in DPMatrix3x3 multiplicand, double multiplier, out DPMatrix3x3 product)
|
public static void Multiply(in F64Matrix3x3 multiplicand, double multiplier, out F64Matrix3x3 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = multiplicand.r1c1 * multiplier;
|
product.r1c1 = multiplicand.r1c1 * multiplier;
|
||||||
product.r1c2 = multiplicand.r1c2 * multiplier;
|
product.r1c2 = multiplicand.r1c2 * multiplier;
|
||||||
|
|
@ -365,7 +365,7 @@ namespace Geometry
|
||||||
product.r3c3 = multiplicand.r3c3 * multiplier;
|
product.r3c3 = multiplicand.r3c3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in DPMatrix3x3 dividend, double divisor, out DPMatrix3x3 quotient)
|
public static void Divide(in F64Matrix3x3 dividend, double divisor, out F64Matrix3x3 quotient)
|
||||||
{
|
{
|
||||||
quotient.r1c1 = dividend.r1c1 / divisor;
|
quotient.r1c1 = dividend.r1c1 / divisor;
|
||||||
quotient.r1c2 = dividend.r1c2 / divisor;
|
quotient.r1c2 = dividend.r1c2 / divisor;
|
||||||
|
|
@ -381,9 +381,9 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
double weight1, in DPMatrix3x3 matrix1,
|
double weight1, in F64Matrix3x3 matrix1,
|
||||||
double weight2, in DPMatrix3x3 matrix2,
|
double weight2, in F64Matrix3x3 matrix2,
|
||||||
out DPMatrix3x3 sum)
|
out F64Matrix3x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2;
|
||||||
|
|
@ -399,10 +399,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
double weight1, in DPMatrix3x3 matrix1,
|
double weight1, in F64Matrix3x3 matrix1,
|
||||||
double weight2, in DPMatrix3x3 matrix2,
|
double weight2, in F64Matrix3x3 matrix2,
|
||||||
double weight3, in DPMatrix3x3 matrix3,
|
double weight3, in F64Matrix3x3 matrix3,
|
||||||
out DPMatrix3x3 sum)
|
out F64Matrix3x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
sum.r1c1 = matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2 + matrix3.r1c1 * weight3;
|
||||||
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
sum.r1c2 = matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2 + matrix3.r1c2 * weight3;
|
||||||
|
|
@ -418,11 +418,11 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
double weight1, in DPMatrix3x3 matrix1,
|
double weight1, in F64Matrix3x3 matrix1,
|
||||||
double weight2, in DPMatrix3x3 matrix2,
|
double weight2, in F64Matrix3x3 matrix2,
|
||||||
double weight3, in DPMatrix3x3 matrix3,
|
double weight3, in F64Matrix3x3 matrix3,
|
||||||
double weight4, in DPMatrix3x3 matrix4,
|
double weight4, in F64Matrix3x3 matrix4,
|
||||||
out DPMatrix3x3 sum)
|
out F64Matrix3x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4);
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4);
|
||||||
|
|
@ -438,12 +438,12 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
double weight1, in DPMatrix3x3 matrix1,
|
double weight1, in F64Matrix3x3 matrix1,
|
||||||
double weight2, in DPMatrix3x3 matrix2,
|
double weight2, in F64Matrix3x3 matrix2,
|
||||||
double weight3, in DPMatrix3x3 matrix3,
|
double weight3, in F64Matrix3x3 matrix3,
|
||||||
double weight4, in DPMatrix3x3 matrix4,
|
double weight4, in F64Matrix3x3 matrix4,
|
||||||
double weight5, in DPMatrix3x3 matrix5,
|
double weight5, in F64Matrix3x3 matrix5,
|
||||||
out DPMatrix3x3 sum)
|
out F64Matrix3x3 sum)
|
||||||
{
|
{
|
||||||
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
sum.r1c1 = (matrix1.r1c1 * weight1 + matrix2.r1c1 * weight2) + (matrix3.r1c1 * weight3 + matrix4.r1c1 * weight4) + matrix5.r1c1 * weight5;
|
||||||
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
sum.r1c2 = (matrix1.r1c2 * weight1 + matrix2.r1c2 * weight2) + (matrix3.r1c2 * weight3 + matrix4.r1c2 * weight4) + matrix5.r1c2 * weight5;
|
||||||
|
|
@ -458,7 +458,7 @@ namespace Geometry
|
||||||
sum.r3c3 = (matrix1.r3c3 * weight1 + matrix2.r3c3 * weight2) + (matrix3.r3c3 * weight3 + matrix4.r3c3 * weight4) + matrix5.r3c3 * weight5;
|
sum.r3c3 = (matrix1.r3c3 * weight1 + matrix2.r3c3 * weight2) + (matrix3.r3c3 * weight3 + matrix4.r3c3 * weight4) + matrix5.r3c3 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetRightProduct(in DPMatrix3x3 matrix, in DPVector3 vector, out DPVector3 result)
|
public static void GetRightProduct(in F64Matrix3x3 matrix, in F64Vector3 vector, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
double x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2 + matrix.r1c3 * vector.x3;
|
double x1 = matrix.r1c1 * vector.x1 + matrix.r1c2 * vector.x2 + matrix.r1c3 * vector.x3;
|
||||||
double x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2 + matrix.r2c3 * vector.x3;
|
double x2 = matrix.r2c1 * vector.x1 + matrix.r2c2 * vector.x2 + matrix.r2c3 * vector.x3;
|
||||||
|
|
@ -469,7 +469,7 @@ namespace Geometry
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetLeftProduct(in DPVector3 vector, in DPMatrix3x3 matrix, out DPVector3 result)
|
public static void GetLeftProduct(in F64Vector3 vector, in F64Matrix3x3 matrix, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
double x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1 + vector.x3 * matrix.r3c1;
|
double x1 = vector.x1 * matrix.r1c1 + vector.x2 * matrix.r2c1 + vector.x3 * matrix.r3c1;
|
||||||
double x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2 + vector.x3 * matrix.r3c2;
|
double x2 = vector.x1 * matrix.r1c2 + vector.x2 * matrix.r2c2 + vector.x3 * matrix.r3c2;
|
||||||
|
|
@ -480,7 +480,7 @@ namespace Geometry
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadZero(out DPMatrix3x3 matrix)
|
public static void LoadZero(out F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = 0.0;
|
matrix.r1c1 = 0.0;
|
||||||
matrix.r1c2 = 0.0;
|
matrix.r1c2 = 0.0;
|
||||||
|
|
@ -495,7 +495,7 @@ namespace Geometry
|
||||||
matrix.r3c3 = 0.0;
|
matrix.r3c3 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadIdentity(out DPMatrix3x3 matrix)
|
public static void LoadIdentity(out F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = 1.0;
|
matrix.r1c1 = 1.0;
|
||||||
matrix.r1c2 = 0.0;
|
matrix.r1c2 = 0.0;
|
||||||
|
|
@ -510,7 +510,7 @@ namespace Geometry
|
||||||
matrix.r3c3 = 1.0;
|
matrix.r3c3 = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadDiagonal(double d1, double d2, double d3, out DPMatrix3x3 matrix)
|
public static void LoadDiagonal(double d1, double d2, double d3, out F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
matrix.r1c1 = d1;
|
matrix.r1c1 = d1;
|
||||||
matrix.r1c2 = 0.0;
|
matrix.r1c2 = 0.0;
|
||||||
|
|
@ -20,11 +20,11 @@ using System;
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 11 Nov 2024
|
* Date: 11 Nov 2024
|
||||||
*/
|
*/
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public class DPMatrixProduct
|
public class F64MatrixProduct
|
||||||
{
|
{
|
||||||
public static void Get2x2At2x2(in DPMatrix2x2 left, in DPMatrix2x2 right, out DPMatrix2x2 product)
|
public static void Get2x2At2x2(in F64Matrix2x2 left, in F64Matrix2x2 right, out F64Matrix2x2 product)
|
||||||
{
|
{
|
||||||
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Geometry
|
||||||
product.r2c2 = r2c2;
|
product.r2c2 = r2c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get2x2At3x2(in DPMatrix2x2 left, in DPMatrix3x2 right, out DPMatrix3x2 product)
|
public static void Get2x2At3x2(in F64Matrix2x2 left, in F64Matrix3x2 right, out F64Matrix3x2 product)
|
||||||
{
|
{
|
||||||
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Geometry
|
||||||
product.r2c3 = r2c3;
|
product.r2c3 = r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get2x3At2x2(in DPMatrix2x3 left, in DPMatrix2x2 right, out DPMatrix2x3 product)
|
public static void Get2x3At2x2(in F64Matrix2x3 left, in F64Matrix2x2 right, out F64Matrix2x3 product)
|
||||||
{
|
{
|
||||||
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -79,7 +79,7 @@ namespace Geometry
|
||||||
product.r3c2 = r3c2;
|
product.r3c2 = r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get2x3At3x2(in DPMatrix2x3 left, in DPMatrix3x2 right, out DPMatrix3x3 product)
|
public static void Get2x3At3x2(in F64Matrix2x3 left, in F64Matrix3x2 right, out F64Matrix3x3 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1;
|
||||||
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2;
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Geometry
|
||||||
product.r3c3 = left.r3c1 * right.r1c2 + left.r3c2 * right.r2c3;
|
product.r3c3 = left.r3c1 * right.r1c2 + left.r3c2 * right.r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x2At3x3(in DPMatrix3x2 left, in DPMatrix3x3 right, out DPMatrix3x2 product)
|
public static void Get3x2At3x3(in F64Matrix3x2 left, in F64Matrix3x3 right, out F64Matrix3x2 product)
|
||||||
{
|
{
|
||||||
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Geometry
|
||||||
product.r2c3 = r2c3;
|
product.r2c3 = r2c3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x2At2x3(in DPMatrix3x2 left, in DPMatrix2x3 right, out DPMatrix2x2 product)
|
public static void Get3x2At2x3(in F64Matrix3x2 left, in F64Matrix2x3 right, out F64Matrix2x2 product)
|
||||||
{
|
{
|
||||||
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
product.r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
product.r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -122,7 +122,7 @@ namespace Geometry
|
||||||
product.r2c2 = left.r2c1 * right.r1c2 + left.r2c2 * right.r2c2 + left.r2c3 * right.r3c2;
|
product.r2c2 = left.r2c1 * right.r1c2 + left.r2c2 * right.r2c2 + left.r2c3 * right.r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x3At2x3(in DPMatrix3x3 left, in DPMatrix2x3 right, out DPMatrix2x3 product)
|
public static void Get3x3At2x3(in F64Matrix3x3 left, in F64Matrix2x3 right, out F64Matrix2x3 product)
|
||||||
{
|
{
|
||||||
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -143,7 +143,7 @@ namespace Geometry
|
||||||
product.r3c2 = r3c2;
|
product.r3c2 = r3c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Get3x3At3x3(in DPMatrix3x3 left, in DPMatrix3x3 right, out DPMatrix3x3 product)
|
public static void Get3x3At3x3(in F64Matrix3x3 left, in F64Matrix3x3 right, out F64Matrix3x3 product)
|
||||||
{
|
{
|
||||||
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
double r1c1 = left.r1c1 * right.r1c1 + left.r1c2 * right.r2c1 + left.r1c3 * right.r3c1;
|
||||||
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
double r1c2 = left.r1c1 * right.r1c2 + left.r1c2 * right.r2c2 + left.r1c3 * right.r3c2;
|
||||||
|
|
@ -1,204 +1,204 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPQuaternion
|
public struct F64Quaternion
|
||||||
{
|
{
|
||||||
public double s0, x1, x2, x3;
|
public double s0, x1, x2, x3;
|
||||||
|
|
||||||
public DPQuaternion(double s0, double x1, double x2, double x3)
|
public F64Quaternion(double s0, double x1, double x2, double x3)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPQuaternion(in SPQuaternion quaternion)
|
public F64Quaternion(in F32Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = quaternion.x1;
|
this.x1 = quaternion.x1;
|
||||||
this.x2 = quaternion.x2;
|
this.x2 = quaternion.x2;
|
||||||
this.x3 = quaternion.x3;
|
this.x3 = quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPQuaternion(in DPQuaternion quaternion)
|
public F64Quaternion(in F64Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = quaternion.x1;
|
this.x1 = quaternion.x1;
|
||||||
this.x2 = quaternion.x2;
|
this.x2 = quaternion.x2;
|
||||||
this.x3 = quaternion.x3;
|
this.x3 = quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
this.s0 = 0.0;
|
this.s0 = 0.0;
|
||||||
this.x1 = 0.0;
|
this.x1 = 0.0;
|
||||||
this.x2 = 0.0;
|
this.x2 = 0.0;
|
||||||
this.x3 = 0.0;
|
this.x3 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Conjugate()
|
public void Conjugate()
|
||||||
{
|
{
|
||||||
this.x1 = -this.x1;
|
this.x1 = -this.x1;
|
||||||
this.x2 = -this.x2;
|
this.x2 = -this.x2;
|
||||||
this.x3 = -this.x3;
|
this.x3 = -this.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(double s0, double x1, double x2, double x3)
|
public void SetValues(double s0, double x1, double x2, double x3)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPQuaternion quaternion)
|
public void SetValues(in F32Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = quaternion.x1;
|
this.x1 = quaternion.x1;
|
||||||
this.x2 = quaternion.x2;
|
this.x2 = quaternion.x2;
|
||||||
this.x3 = quaternion.x3;
|
this.x3 = quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPQuaternion quaternion)
|
public void SetValues(in F64Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = quaternion.x1;
|
this.x1 = quaternion.x1;
|
||||||
this.x2 = quaternion.x2;
|
this.x2 = quaternion.x2;
|
||||||
this.x3 = quaternion.x3;
|
this.x3 = quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetConjugateOf(in DPQuaternion quaternion)
|
public void SetConjugateOf(in F64Quaternion quaternion)
|
||||||
{
|
{
|
||||||
this.s0 = quaternion.s0;
|
this.s0 = quaternion.s0;
|
||||||
this.x1 = -quaternion.x1;
|
this.x1 = -quaternion.x1;
|
||||||
this.x2 = -quaternion.x2;
|
this.x2 = -quaternion.x2;
|
||||||
this.x3 = -quaternion.x3;
|
this.x3 = -quaternion.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeRotationMatrix(out DPMatrix3x3 matrix)
|
public readonly void MakeRotationMatrix(out F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
double s0s0 = this.s0 * this.s0;
|
double s0s0 = this.s0 * this.s0;
|
||||||
double x1x1 = this.x1 * this.x1;
|
double x1x1 = this.x1 * this.x1;
|
||||||
double x2x2 = this.x2 * this.x2;
|
double x2x2 = this.x2 * this.x2;
|
||||||
double x3x3 = this.x3 * this.x3;
|
double x3x3 = this.x3 * this.x3;
|
||||||
|
|
||||||
double squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
double squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-DPUtility.EPSYLON <= squareModule && squareModule <= DPUtility.EPSYLON)
|
if (-F64Utility.EPSYLON <= squareModule && squareModule <= F64Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
DPMatrix3x3.LoadIdentity(out matrix);
|
F64Matrix3x3.LoadIdentity(out matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double corrector1;
|
double corrector1;
|
||||||
double corrector2;
|
double corrector2;
|
||||||
|
|
||||||
if (1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + DPUtility.TWO_EPSYLON) {
|
if (1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + F64Utility.TWO_EPSYLON) {
|
||||||
corrector1 = 2.0 - squareModule;
|
corrector1 = 2.0 - squareModule;
|
||||||
corrector2 = 2.0 * corrector1;
|
corrector2 = 2.0 * corrector1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
corrector1 = 1.0 / squareModule;
|
corrector1 = 1.0 / squareModule;
|
||||||
corrector2 = 2.0 / squareModule;
|
corrector2 = 2.0 / squareModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
double s0x1 = this.s0 * this.x1;
|
double s0x1 = this.s0 * this.x1;
|
||||||
double s0x2 = this.s0 * this.x2;
|
double s0x2 = this.s0 * this.x2;
|
||||||
double s0x3 = this.s0 * this.x3;
|
double s0x3 = this.s0 * this.x3;
|
||||||
double x1x2 = this.x1 * this.x2;
|
double x1x2 = this.x1 * this.x2;
|
||||||
double x1x3 = this.x1 * this.x3;
|
double x1x3 = this.x1 * this.x3;
|
||||||
double x2x3 = this.x2 * this.x3;
|
double x2x3 = this.x2 * this.x3;
|
||||||
|
|
||||||
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||||
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||||
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||||
|
|
||||||
matrix.r1c2 = corrector2 * (x1x2 - s0x3);
|
matrix.r1c2 = corrector2 * (x1x2 - s0x3);
|
||||||
matrix.r2c3 = corrector2 * (x2x3 - s0x1);
|
matrix.r2c3 = corrector2 * (x2x3 - s0x1);
|
||||||
matrix.r3c1 = corrector2 * (x1x3 - s0x2);
|
matrix.r3c1 = corrector2 * (x1x3 - s0x2);
|
||||||
|
|
||||||
matrix.r2c1 = corrector2 * (x1x2 + s0x3);
|
matrix.r2c1 = corrector2 * (x1x2 + s0x3);
|
||||||
matrix.r3c2 = corrector2 * (x2x3 + s0x1);
|
matrix.r3c2 = corrector2 * (x2x3 + s0x1);
|
||||||
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeReverseMatrix(out DPMatrix3x3 matrix)
|
public readonly void MakeReverseMatrix(out F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
double s0s0 = this.s0 * this.s0;
|
double s0s0 = this.s0 * this.s0;
|
||||||
double x1x1 = this.x1 * this.x1;
|
double x1x1 = this.x1 * this.x1;
|
||||||
double x2x2 = this.x2 * this.x2;
|
double x2x2 = this.x2 * this.x2;
|
||||||
double x3x3 = this.x3 * this.x3;
|
double x3x3 = this.x3 * this.x3;
|
||||||
|
|
||||||
double squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
double squareModule = (s0s0 + x1x1) + (x2x2 + x3x3);
|
||||||
|
|
||||||
if (-DPUtility.EPSYLON <= squareModule && squareModule <= DPUtility.EPSYLON)
|
if (-F64Utility.EPSYLON <= squareModule && squareModule <= F64Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
DPMatrix3x3.LoadIdentity(out matrix);
|
F64Matrix3x3.LoadIdentity(out matrix);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double corrector1;
|
double corrector1;
|
||||||
double corrector2;
|
double corrector2;
|
||||||
|
|
||||||
if (1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + DPUtility.TWO_EPSYLON) {
|
if (1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + F64Utility.TWO_EPSYLON) {
|
||||||
corrector1 = 2.0 - squareModule;
|
corrector1 = 2.0 - squareModule;
|
||||||
corrector2 = 2.0 * corrector1;
|
corrector2 = 2.0 * corrector1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
corrector1 = 1.0 / squareModule;
|
corrector1 = 1.0 / squareModule;
|
||||||
corrector2 = 2.0 / squareModule;
|
corrector2 = 2.0 / squareModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
double s0x1 = this.s0 * this.x1;
|
double s0x1 = this.s0 * this.x1;
|
||||||
double s0x2 = this.s0 * this.x2;
|
double s0x2 = this.s0 * this.x2;
|
||||||
double s0x3 = this.s0 * this.x3;
|
double s0x3 = this.s0 * this.x3;
|
||||||
double x1x2 = this.x1 * this.x2;
|
double x1x2 = this.x1 * this.x2;
|
||||||
double x1x3 = this.x1 * this.x3;
|
double x1x3 = this.x1 * this.x3;
|
||||||
double x2x3 = this.x2 * this.x3;
|
double x2x3 = this.x2 * this.x3;
|
||||||
|
|
||||||
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
matrix.r1c1 = corrector1 * ((s0s0 + x1x1) - (x2x2 + x3x3));
|
||||||
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
matrix.r2c2 = corrector1 * ((s0s0 + x2x2) - (x1x1 + x3x3));
|
||||||
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
matrix.r3c3 = corrector1 * ((s0s0 + x3x3) - (x1x1 + x2x2));
|
||||||
|
|
||||||
matrix.r1c2 = corrector2 * (x1x2 + s0x3);
|
matrix.r1c2 = corrector2 * (x1x2 + s0x3);
|
||||||
matrix.r2c3 = corrector2 * (x2x3 + s0x1);
|
matrix.r2c3 = corrector2 * (x2x3 + s0x1);
|
||||||
matrix.r3c1 = corrector2 * (x1x3 + s0x2);
|
matrix.r3c1 = corrector2 * (x1x3 + s0x2);
|
||||||
|
|
||||||
matrix.r2c1 = corrector2 * (x1x2 - s0x3);
|
matrix.r2c1 = corrector2 * (x1x2 - s0x3);
|
||||||
matrix.r3c2 = corrector2 * (x2x3 - s0x1);
|
matrix.r3c2 = corrector2 * (x2x3 - s0x1);
|
||||||
matrix.r1c3 = corrector2 * (x1x3 - s0x2);
|
matrix.r1c3 = corrector2 * (x1x3 - s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in DPQuaternion quaternion1, in DPQuaternion quaternion2, out DPQuaternion sum)
|
public static void Add(in F64Quaternion quaternion1, in F64Quaternion quaternion2, out F64Quaternion sum)
|
||||||
{
|
{
|
||||||
sum.s0 = quaternion1.s0 + quaternion2.s0;
|
sum.s0 = quaternion1.s0 + quaternion2.s0;
|
||||||
sum.x1 = quaternion1.x1 + quaternion2.x1;
|
sum.x1 = quaternion1.x1 + quaternion2.x1;
|
||||||
sum.x2 = quaternion1.x2 + quaternion2.x2;
|
sum.x2 = quaternion1.x2 + quaternion2.x2;
|
||||||
sum.x3 = quaternion1.x3 + quaternion2.x3;
|
sum.x3 = quaternion1.x3 + quaternion2.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in DPQuaternion minuend, in DPQuaternion subtrahend, out DPQuaternion difference)
|
public static void Subtract(in F64Quaternion minuend, in F64Quaternion subtrahend, out F64Quaternion difference)
|
||||||
{
|
{
|
||||||
difference.s0 = minuend.s0 - subtrahend.s0;
|
difference.s0 = minuend.s0 - subtrahend.s0;
|
||||||
difference.x1 = minuend.x1 - subtrahend.x1;
|
difference.x1 = minuend.x1 - subtrahend.x1;
|
||||||
difference.x2 = minuend.x2 - subtrahend.x2;
|
difference.x2 = minuend.x2 - subtrahend.x2;
|
||||||
difference.x3 = minuend.x3 - subtrahend.x3;
|
difference.x3 = minuend.x3 - subtrahend.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(in DPQuaternion left, in DPQuaternion right, out DPQuaternion product)
|
public static void Multiply(in F64Quaternion left, in F64Quaternion right, out F64Quaternion product)
|
||||||
{
|
{
|
||||||
double s0 = (left.s0 * right.s0 - left.x1 * right.x1) - (left.x2 * right.x2 + left.x3 * right.x3);
|
double s0 = (left.s0 * right.s0 - left.x1 * right.x1) - (left.x2 * right.x2 + left.x3 * right.x3);
|
||||||
double x1 = (left.x1 * right.s0 + left.s0 * right.x1) - (left.x3 * right.x2 - left.x2 * right.x3);
|
double x1 = (left.x1 * right.s0 + left.s0 * right.x1) - (left.x3 * right.x2 - left.x2 * right.x3);
|
||||||
double x2 = (left.x2 * right.s0 + left.s0 * right.x2) - (left.x1 * right.x3 - left.x3 * right.x1);
|
double x2 = (left.x2 * right.s0 + left.s0 * right.x2) - (left.x1 * right.x3 - left.x3 * right.x1);
|
||||||
double x3 = (left.x3 * right.s0 + left.s0 * right.x3) - (left.x2 * right.x1 - left.x1 * right.x2);
|
double x3 = (left.x3 * right.s0 + left.s0 * right.x3) - (left.x2 * right.x1 - left.x1 * right.x2);
|
||||||
|
|
||||||
product.s0 = s0;
|
product.s0 = s0;
|
||||||
product.x1 = x1;
|
product.x1 = x1;
|
||||||
product.x2 = x2;
|
product.x2 = x2;
|
||||||
product.x3 = x3;
|
product.x3 = x3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
75
BGC/F64Radians.cs
Normal file
75
BGC/F64Radians.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 18 Nov 2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public class F64Radians
|
||||||
|
{
|
||||||
|
public const double PI = 3.14159265358979324;
|
||||||
|
public const double TWO_PI = 6.28318530717958648;
|
||||||
|
public const double HALF_OF_PI = 1.57079632679489662;
|
||||||
|
public const double THIRD_OF_PI = 1.04719755119659775;
|
||||||
|
public const double FOURTH_OF_PI = 0.78539816339744831;
|
||||||
|
public const double SIXTH_OF_PI = 0.523598775598298873;
|
||||||
|
|
||||||
|
public const double DEGREES_IN_RADIAN = 57.2957795130823209;
|
||||||
|
public const double TURNS_IN_RADIAN = 0.159154943091895336;
|
||||||
|
|
||||||
|
public static double ToDegrees(double radians)
|
||||||
|
{
|
||||||
|
return radians * DEGREES_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ToTurns(double radians)
|
||||||
|
{
|
||||||
|
return radians * TURNS_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ToUnits(double radians, AngleUnit toUnit)
|
||||||
|
{
|
||||||
|
if (toUnit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return radians * DEGREES_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUnit == AngleUnit.TURNS)
|
||||||
|
{
|
||||||
|
return radians * TURNS_IN_RADIAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double Normalize(double radians, AngleRange range)
|
||||||
|
{
|
||||||
|
if (range == AngleRange.UNSIGNED_RANGE)
|
||||||
|
{
|
||||||
|
if (0.0 <= radians && radians < TWO_PI)
|
||||||
|
{
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (-PI < radians && radians <= PI)
|
||||||
|
{
|
||||||
|
return radians;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double turns = radians * TURNS_IN_RADIAN;
|
||||||
|
|
||||||
|
turns -= Math.Floor(turns);
|
||||||
|
|
||||||
|
if (range == AngleRange.SIGNED_RANGE && turns > 0.5)
|
||||||
|
{
|
||||||
|
turns -= 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return turns * TWO_PI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
63
BGC/F64Turns.cs
Normal file
63
BGC/F64Turns.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Andrey Pokidov
|
||||||
|
* Date: 18 Nov 2024
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BGC
|
||||||
|
{
|
||||||
|
public class F64Turns
|
||||||
|
{
|
||||||
|
public static double TurnsToRadians(double turns)
|
||||||
|
{
|
||||||
|
return turns * F64Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double TurnsToDegrees(double turns)
|
||||||
|
{
|
||||||
|
return turns * 360.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ToUnits(double turns, AngleUnit toUnit)
|
||||||
|
{
|
||||||
|
if (toUnit == AngleUnit.RADIANS)
|
||||||
|
{
|
||||||
|
return turns * F64Radians.TWO_PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUnit == AngleUnit.DEGREES)
|
||||||
|
{
|
||||||
|
return turns * 360.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return turns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double Normalize(double turns, AngleRange range)
|
||||||
|
{
|
||||||
|
if (range == AngleRange.UNSIGNED_RANGE)
|
||||||
|
{
|
||||||
|
if (0.0 <= turns && turns < 1.0)
|
||||||
|
{
|
||||||
|
return turns;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (-0.5 < turns && turns <= 0.5)
|
||||||
|
{
|
||||||
|
return turns;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double rest = turns - Math.Floor(turns);
|
||||||
|
|
||||||
|
if (range == AngleRange.SIGNED_RANGE && rest > 0.5)
|
||||||
|
{
|
||||||
|
rest -= 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public class DPUtility
|
public class F64Utility
|
||||||
{
|
{
|
||||||
public const double EPSYLON = 5E-14;
|
public const double EPSYLON = 5E-14;
|
||||||
public const double TWO_EPSYLON = 1E-13;
|
public const double TWO_EPSYLON = 1E-13;
|
||||||
public const double SQUARE_EPSYLON = 2.5E-27;
|
public const double SQUARE_EPSYLON = 2.5E-27;
|
||||||
|
|
||||||
public const double EPSYLON_EFFECTIVENESS_LIMIT = 1.0;
|
public const double EPSYLON_EFFECTIVENESS_LIMIT = 1.0;
|
||||||
|
|
||||||
public const double ONE_THIRD = 0.333333333333333333;
|
public const double ONE_THIRD = 0.333333333333333333;
|
||||||
public const double ONE_SIXTH = 0.166666666666666667;
|
public const double ONE_SIXTH = 0.166666666666666667;
|
||||||
public const double ONE_NINETH = 0.111111111111111111;
|
public const double ONE_NINETH = 0.111111111111111111;
|
||||||
|
|
||||||
public const double GOLDEN_RATIO_HIGH = 1.61803398874989485;
|
public const double GOLDEN_RATIO_HIGH = 1.61803398874989485;
|
||||||
public const double GOLDEN_RATIO_LOW = 0.61803398874989485;
|
public const double GOLDEN_RATIO_LOW = 0.61803398874989485;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,28 +21,28 @@ using System;
|
||||||
* Date: 1 Feb 2019
|
* Date: 1 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPVector2
|
public struct F64Vector2
|
||||||
{
|
{
|
||||||
public static readonly DPVector2 ZERO = new DPVector2(0.0, 0.0);
|
public static readonly F64Vector2 ZERO = new F64Vector2(0.0, 0.0);
|
||||||
|
|
||||||
public double x1;
|
public double x1;
|
||||||
public double x2;
|
public double x2;
|
||||||
|
|
||||||
public DPVector2(double x1, double x2)
|
public F64Vector2(double x1, double x2)
|
||||||
{
|
{
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVector2(in DPVector2 vector)
|
public F64Vector2(in F64Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVector2(in SPVector2 vector)
|
public F64Vector2(in F32Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
|
|
@ -62,12 +62,12 @@ namespace Geometry
|
||||||
{
|
{
|
||||||
double squareModule = this.GetSquareModule();
|
double squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + DPUtility.TWO_EPSYLON)
|
if (1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + F64Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -81,23 +81,23 @@ namespace Geometry
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly DPVector2 GetNormalized()
|
public readonly F64Vector2 GetNormalized()
|
||||||
{
|
{
|
||||||
double squareModule = this.GetSquareModule();
|
double squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + DPUtility.TWO_EPSYLON)
|
if (1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + F64Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
double module = Math.Sqrt(squareModule);
|
double module = Math.Sqrt(squareModule);
|
||||||
|
|
||||||
return new DPVector2(
|
return new F64Vector2(
|
||||||
this.x1 / module,
|
this.x1 / module,
|
||||||
this.x2 / module
|
this.x2 / module
|
||||||
);
|
);
|
||||||
|
|
@ -111,13 +111,13 @@ namespace Geometry
|
||||||
|
|
||||||
public readonly bool IsZero()
|
public readonly bool IsZero()
|
||||||
{
|
{
|
||||||
return this.GetSquareModule() <= DPUtility.SQUARE_EPSYLON;
|
return this.GetSquareModule() <= F64Utility.SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsUnit()
|
public readonly bool IsUnit()
|
||||||
{
|
{
|
||||||
double squareModule = this.GetSquareModule();
|
double squareModule = this.GetSquareModule();
|
||||||
return 1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= DPUtility.EPSYLON;
|
return 1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= F64Utility.EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
|
|
@ -132,25 +132,25 @@ namespace Geometry
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPVector2 vector)
|
public void SetValues(in F64Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPVector2 vector)
|
public void SetValues(in F32Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in DPVector2 vector)
|
public void SetReverseOf(in F64Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -vector.x1;
|
this.x1 = -vector.x1;
|
||||||
this.x2 = -vector.x2;
|
this.x2 = -vector.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in SPVector2 vector)
|
public void SetReverseOf(in F32Vector2 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -vector.x1;
|
this.x1 = -vector.x1;
|
||||||
this.x2 = -vector.x2;
|
this.x2 = -vector.x2;
|
||||||
|
|
@ -161,34 +161,34 @@ namespace Geometry
|
||||||
return String.Format("DPVector2({0}, {1})", this.x1, this.x2);
|
return String.Format("DPVector2({0}, {1})", this.x1, this.x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in DPVector2 vector1, in DPVector2 vector2, out DPVector2 sum)
|
public static void Add(in F64Vector2 vector1, in F64Vector2 vector2, out F64Vector2 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 + vector2.x1;
|
sum.x1 = vector1.x1 + vector2.x1;
|
||||||
sum.x2 = vector1.x2 + vector2.x2;
|
sum.x2 = vector1.x2 + vector2.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in DPVector2 minuend, in DPVector2 subtrahend, out DPVector2 difference)
|
public static void Subtract(in F64Vector2 minuend, in F64Vector2 subtrahend, out F64Vector2 difference)
|
||||||
{
|
{
|
||||||
difference.x1 = minuend.x1 - subtrahend.x1;
|
difference.x1 = minuend.x1 - subtrahend.x1;
|
||||||
difference.x2 = minuend.x2 - subtrahend.x2;
|
difference.x2 = minuend.x2 - subtrahend.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Muliply(in DPVector2 multiplicand, double multiplier, out DPVector2 product)
|
public static void Muliply(in F64Vector2 multiplicand, double multiplier, out F64Vector2 product)
|
||||||
{
|
{
|
||||||
product.x1 = multiplicand.x1 * multiplier;
|
product.x1 = multiplicand.x1 * multiplier;
|
||||||
product.x2 = multiplicand.x2 * multiplier;
|
product.x2 = multiplicand.x2 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in DPVector2 dividend, double divisor, out DPVector2 quotient)
|
public static void Divide(in F64Vector2 dividend, double divisor, out F64Vector2 quotient)
|
||||||
{
|
{
|
||||||
quotient.x1 = dividend.x1 / divisor;
|
quotient.x1 = dividend.x1 / divisor;
|
||||||
quotient.x2 = dividend.x2 / divisor;
|
quotient.x2 = dividend.x2 / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
double weight1, in DPVector2 vector1,
|
double weight1, in F64Vector2 vector1,
|
||||||
double weight2, in DPVector2 vector2,
|
double weight2, in F64Vector2 vector2,
|
||||||
out DPVector2 sum
|
out F64Vector2 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
||||||
|
|
@ -196,10 +196,10 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
double weight1, in DPVector2 vector1,
|
double weight1, in F64Vector2 vector1,
|
||||||
double weight2, in DPVector2 vector2,
|
double weight2, in F64Vector2 vector2,
|
||||||
double weight3, in DPVector2 vector3,
|
double weight3, in F64Vector2 vector3,
|
||||||
out DPVector2 sum
|
out F64Vector2 sum
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
||||||
|
|
@ -207,112 +207,112 @@ namespace Geometry
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
double weight1, in DPVector2 vector1,
|
double weight1, in F64Vector2 vector1,
|
||||||
double weight2, in DPVector2 vector2,
|
double weight2, in F64Vector2 vector2,
|
||||||
double weight3, in DPVector2 vector3,
|
double weight3, in F64Vector2 vector3,
|
||||||
double weight4, in DPVector2 vector4,
|
double weight4, in F64Vector2 vector4,
|
||||||
out DPVector2 sum)
|
out F64Vector2 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
||||||
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4);
|
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
double weight1, in DPVector2 vector1,
|
double weight1, in F64Vector2 vector1,
|
||||||
double weight2, in DPVector2 vector2,
|
double weight2, in F64Vector2 vector2,
|
||||||
double weight3, in DPVector2 vector3,
|
double weight3, in F64Vector2 vector3,
|
||||||
double weight4, in DPVector2 vector4,
|
double weight4, in F64Vector2 vector4,
|
||||||
double weight5, in DPVector2 vector5,
|
double weight5, in F64Vector2 vector5,
|
||||||
out DPVector2 sum)
|
out F64Vector2 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4) + vector5.x1 * weight5;
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4) + vector5.x1 * weight5;
|
||||||
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4) + vector5.x2 * weight5;
|
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4) + vector5.x2 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean2(
|
public static void GetMean2(
|
||||||
in DPVector2 vector1,
|
in F64Vector2 vector1,
|
||||||
in DPVector2 vector2,
|
in F64Vector2 vector2,
|
||||||
out DPVector2 result)
|
out F64Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1) * 0.5;
|
result.x1 = (vector1.x1 + vector2.x1) * 0.5;
|
||||||
result.x2 = (vector1.x2 + vector2.x2) * 0.5;
|
result.x2 = (vector1.x2 + vector2.x2) * 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean3(
|
public static void GetMean3(
|
||||||
in DPVector2 vector1,
|
in F64Vector2 vector1,
|
||||||
in DPVector2 vector2,
|
in F64Vector2 vector2,
|
||||||
in DPVector2 vector3,
|
in F64Vector2 vector3,
|
||||||
out DPVector2 result)
|
out F64Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * DPUtility.ONE_THIRD;
|
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * F64Utility.ONE_THIRD;
|
||||||
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * DPUtility.ONE_THIRD;
|
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * F64Utility.ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean4(
|
public static void GetMean4(
|
||||||
in DPVector2 vector1,
|
in F64Vector2 vector1,
|
||||||
in DPVector2 vector2,
|
in F64Vector2 vector2,
|
||||||
in DPVector2 vector3,
|
in F64Vector2 vector3,
|
||||||
in DPVector2 vector4,
|
in F64Vector2 vector4,
|
||||||
out DPVector2 result)
|
out F64Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25;
|
||||||
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2)) * 0.25;
|
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2)) * 0.25;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean5(
|
public static void GetMean5(
|
||||||
in DPVector2 vector1,
|
in F64Vector2 vector1,
|
||||||
in DPVector2 vector2,
|
in F64Vector2 vector2,
|
||||||
in DPVector2 vector3,
|
in F64Vector2 vector3,
|
||||||
in DPVector2 vector4,
|
in F64Vector2 vector4,
|
||||||
in DPVector2 vector5,
|
in F64Vector2 vector5,
|
||||||
out DPVector2 result)
|
out F64Vector2 result)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2;
|
||||||
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2) + vector5.x2) * 0.2;
|
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2) + vector5.x2) * 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetScalarProduct(in DPVector2 vector1, in DPVector2 vector2)
|
public static double GetScalarProduct(in F64Vector2 vector1, in F64Vector2 vector2)
|
||||||
{
|
{
|
||||||
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2;
|
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetCrossProduct(in DPVector2 vector1, in DPVector2 vector2)
|
public static double GetCrossProduct(in F64Vector2 vector1, in F64Vector2 vector2)
|
||||||
{
|
{
|
||||||
return vector1.x1 * vector2.x2 - vector1.x2 * vector2.x1;
|
return vector1.x1 * vector2.x2 - vector1.x2 * vector2.x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetAngle(in DPVector2 vector1, in DPVector2 vector2, AngleUnit unit)
|
public static double GetAngle(in F64Vector2 vector1, in F64Vector2 vector2, AngleUnit unit)
|
||||||
{
|
{
|
||||||
double squareModule1 = vector1.GetSquareModule();
|
double squareModule1 = vector1.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule1 <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule1 <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double squareModule2 = vector2.GetSquareModule();
|
double squareModule2 = vector2.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule2 <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule2 <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double cosine = DPVector2.GetScalarProduct(vector1, vector2) / Math.Sqrt(squareModule1 * squareModule2);
|
double cosine = F64Vector2.GetScalarProduct(vector1, vector2) / Math.Sqrt(squareModule1 * squareModule2);
|
||||||
|
|
||||||
if (1.0 - DPUtility.EPSYLON <= cosine)
|
if (1.0 - F64Utility.EPSYLON <= cosine)
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -(1.0 - DPUtility.EPSYLON))
|
if (cosine <= -(1.0 - F64Utility.EPSYLON))
|
||||||
{
|
{
|
||||||
return DPAngle.GetHalfCircle(unit);
|
return F64Angle.GetHalfCircle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DPAngle.ConvertFromRadians(Math.Acos(cosine), unit);
|
return F64Radians.ToUnits(Math.Acos(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetSquareDistance(in DPVector2 vector1, in DPVector2 vector2)
|
public static double GetSquareDistance(in F64Vector2 vector1, in F64Vector2 vector2)
|
||||||
{
|
{
|
||||||
double dx1 = vector1.x1 - vector2.x1;
|
double dx1 = vector1.x1 - vector2.x1;
|
||||||
double dx2 = vector1.x2 - vector2.x2;
|
double dx2 = vector1.x2 - vector2.x2;
|
||||||
|
|
@ -320,29 +320,29 @@ namespace Geometry
|
||||||
return dx1 * dx1 + dx2 * dx2;
|
return dx1 * dx1 + dx2 * dx2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetDistance(in DPVector2 vector1, in DPVector2 vector2)
|
public static double GetDistance(in F64Vector2 vector1, in F64Vector2 vector2)
|
||||||
{
|
{
|
||||||
return Math.Sqrt(GetSquareDistance(vector1, vector2));
|
return Math.Sqrt(GetSquareDistance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AreEqual(in DPVector2 vector1, in DPVector2 vector2)
|
public static bool AreEqual(in F64Vector2 vector1, in F64Vector2 vector2)
|
||||||
{
|
{
|
||||||
double squareModule1 = vector1.GetSquareModule();
|
double squareModule1 = vector1.GetSquareModule();
|
||||||
double squareModule2 = vector2.GetSquareModule();
|
double squareModule2 = vector2.GetSquareModule();
|
||||||
double squareModule3 = GetSquareDistance(vector1, vector2);
|
double squareModule3 = GetSquareDistance(vector1, vector2);
|
||||||
|
|
||||||
// 2.0 means dimension amount
|
// 2.0 means dimension amount
|
||||||
if (squareModule1 < DPUtility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < DPUtility.EPSYLON_EFFECTIVENESS_LIMIT)
|
if (squareModule1 < F64Utility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < F64Utility.EPSYLON_EFFECTIVENESS_LIMIT)
|
||||||
{
|
{
|
||||||
return squareModule3 < (2.0 * DPUtility.SQUARE_EPSYLON);
|
return squareModule3 < (2.0 * F64Utility.SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule1 <= squareModule2)
|
if (squareModule1 <= squareModule2)
|
||||||
{
|
{
|
||||||
return squareModule3 <= (2.0 * DPUtility.SQUARE_EPSYLON) * squareModule2;
|
return squareModule3 <= (2.0 * F64Utility.SQUARE_EPSYLON) * squareModule2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return squareModule3 <= (2.0 * DPUtility.SQUARE_EPSYLON) * squareModule1;
|
return squareModule3 <= (2.0 * F64Utility.SQUARE_EPSYLON) * squareModule1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,397 +1,397 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Author: Andrey Pokidov
|
* Author: Andrey Pokidov
|
||||||
* Date: 1 Feb 2019
|
* Date: 1 Feb 2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPVector3
|
public struct F64Vector3
|
||||||
{
|
{
|
||||||
public static readonly DPVector3 ZERO = new DPVector3(0.0, 0.0, 0.0);
|
public static readonly F64Vector3 ZERO = new F64Vector3(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
public double x1;
|
public double x1;
|
||||||
public double x2;
|
public double x2;
|
||||||
public double x3;
|
public double x3;
|
||||||
|
|
||||||
public DPVector3(double x1, double x2, double x3)
|
public F64Vector3(double x1, double x2, double x3)
|
||||||
{
|
{
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVector3(in DPVector3 vector)
|
public F64Vector3(in F64Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
this.x3 = vector.x3;
|
this.x3 = vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVector3(in SPVector3 vector)
|
public F64Vector3(in F32Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
this.x3 = vector.x3;
|
this.x3 = vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly double GetSquareModule()
|
public readonly double GetSquareModule()
|
||||||
{
|
{
|
||||||
return this.x1 * this.x1 + this.x2 * this.x2 + this.x3 * this.x3;
|
return this.x1 * this.x1 + this.x2 * this.x2 + this.x3 * this.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly double GetModule()
|
public readonly double GetModule()
|
||||||
{
|
{
|
||||||
return Math.Sqrt(this.GetSquareModule());
|
return Math.Sqrt(this.GetSquareModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Normalize()
|
public int Normalize()
|
||||||
{
|
{
|
||||||
double squareModule = this.GetSquareModule();
|
double squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + DPUtility.TWO_EPSYLON)
|
if (1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + F64Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double module = Math.Sqrt(squareModule);
|
double module = Math.Sqrt(squareModule);
|
||||||
|
|
||||||
this.x1 /= module;
|
this.x1 /= module;
|
||||||
this.x2 /= module;
|
this.x2 /= module;
|
||||||
this.x3 /= module;
|
this.x3 /= module;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly DPVector3 GetNormalized()
|
public readonly F64Vector3 GetNormalized()
|
||||||
{
|
{
|
||||||
double squareModule = this.GetSquareModule();
|
double squareModule = this.GetSquareModule();
|
||||||
|
|
||||||
if (1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + DPUtility.TWO_EPSYLON)
|
if (1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= 1.0 + F64Utility.TWO_EPSYLON)
|
||||||
{
|
{
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return ZERO;
|
return ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
double module = Math.Sqrt(squareModule);
|
double module = Math.Sqrt(squareModule);
|
||||||
|
|
||||||
return new DPVector3(
|
return new F64Vector3(
|
||||||
this.x1 / module,
|
this.x1 / module,
|
||||||
this.x2 / module,
|
this.x2 / module,
|
||||||
this.x3 / module
|
this.x3 / module
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reverse()
|
public void Reverse()
|
||||||
{
|
{
|
||||||
this.x1 = -this.x1;
|
this.x1 = -this.x1;
|
||||||
this.x2 = -this.x2;
|
this.x2 = -this.x2;
|
||||||
this.x3 = -this.x3;
|
this.x3 = -this.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsZero()
|
public readonly bool IsZero()
|
||||||
{
|
{
|
||||||
return this.GetSquareModule() <= DPUtility.SQUARE_EPSYLON;
|
return this.GetSquareModule() <= F64Utility.SQUARE_EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool IsUnit()
|
public readonly bool IsUnit()
|
||||||
{
|
{
|
||||||
double squareModule = this.GetSquareModule();
|
double squareModule = this.GetSquareModule();
|
||||||
return 1.0 - DPUtility.TWO_EPSYLON <= squareModule && squareModule <= DPUtility.EPSYLON;
|
return 1.0 - F64Utility.TWO_EPSYLON <= squareModule && squareModule <= F64Utility.EPSYLON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
this.x1 = 0.0;
|
this.x1 = 0.0;
|
||||||
this.x2 = 0.0;
|
this.x2 = 0.0;
|
||||||
this.x3 = 0.0;
|
this.x3 = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(double x1, double x2, double x3)
|
public void SetValues(double x1, double x2, double x3)
|
||||||
{
|
{
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
this.x2 = x2;
|
this.x2 = x2;
|
||||||
this.x3 = x3;
|
this.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPVector3 vector)
|
public void SetValues(in F64Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
this.x3 = vector.x3;
|
this.x3 = vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPVector3 vector)
|
public void SetValues(in F32Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = vector.x1;
|
this.x1 = vector.x1;
|
||||||
this.x2 = vector.x2;
|
this.x2 = vector.x2;
|
||||||
this.x3 = vector.x3;
|
this.x3 = vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in DPVector3 vector)
|
public void SetReverseOf(in F64Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -vector.x1;
|
this.x1 = -vector.x1;
|
||||||
this.x2 = -vector.x2;
|
this.x2 = -vector.x2;
|
||||||
this.x3 = -vector.x3;
|
this.x3 = -vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetReverseOf(in SPVector3 vector)
|
public void SetReverseOf(in F32Vector3 vector)
|
||||||
{
|
{
|
||||||
this.x1 = -vector.x1;
|
this.x1 = -vector.x1;
|
||||||
this.x2 = -vector.x2;
|
this.x2 = -vector.x2;
|
||||||
this.x3 = -vector.x3;
|
this.x3 = -vector.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly override string ToString()
|
public readonly override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("DPVector3({0}, {1}, {2})", this.x1, this.x2, this.x3);
|
return String.Format("DPVector3({0}, {1}, {2})", this.x1, this.x2, this.x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(in DPVector3 vector1, in DPVector3 vector2, out DPVector3 sum)
|
public static void Add(in F64Vector3 vector1, in F64Vector3 vector2, out F64Vector3 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 + vector2.x1;
|
sum.x1 = vector1.x1 + vector2.x1;
|
||||||
sum.x2 = vector1.x2 + vector2.x2;
|
sum.x2 = vector1.x2 + vector2.x2;
|
||||||
sum.x3 = vector1.x3 + vector2.x3;
|
sum.x3 = vector1.x3 + vector2.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(in DPVector3 minuend, in DPVector3 subtrahend, out DPVector3 difference)
|
public static void Subtract(in F64Vector3 minuend, in F64Vector3 subtrahend, out F64Vector3 difference)
|
||||||
{
|
{
|
||||||
difference.x1 = minuend.x1 - subtrahend.x1;
|
difference.x1 = minuend.x1 - subtrahend.x1;
|
||||||
difference.x2 = minuend.x2 - subtrahend.x2;
|
difference.x2 = minuend.x2 - subtrahend.x2;
|
||||||
difference.x3 = minuend.x3 - subtrahend.x3;
|
difference.x3 = minuend.x3 - subtrahend.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Muliply(in DPVector3 multiplicand, double multiplier, out DPVector3 product)
|
public static void Muliply(in F64Vector3 multiplicand, double multiplier, out F64Vector3 product)
|
||||||
{
|
{
|
||||||
product.x1 = multiplicand.x1 * multiplier;
|
product.x1 = multiplicand.x1 * multiplier;
|
||||||
product.x2 = multiplicand.x2 * multiplier;
|
product.x2 = multiplicand.x2 * multiplier;
|
||||||
product.x3 = multiplicand.x3 * multiplier;
|
product.x3 = multiplicand.x3 * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(in DPVector3 dividend, double divisor, out DPVector3 quotient)
|
public static void Divide(in F64Vector3 dividend, double divisor, out F64Vector3 quotient)
|
||||||
{
|
{
|
||||||
quotient.x1 = dividend.x1 / divisor;
|
quotient.x1 = dividend.x1 / divisor;
|
||||||
quotient.x2 = dividend.x2 / divisor;
|
quotient.x2 = dividend.x2 / divisor;
|
||||||
quotient.x3 = dividend.x3 / divisor;
|
quotient.x3 = dividend.x3 / divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum2(
|
public static void GetWeightedSum2(
|
||||||
double weight1, in DPVector3 vector1,
|
double weight1, in F64Vector3 vector1,
|
||||||
double weight2, in DPVector3 vector2,
|
double weight2, in F64Vector3 vector2,
|
||||||
out DPVector3 sum)
|
out F64Vector3 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2;
|
||||||
sum.x2 = vector1.x2 * weight1 + vector2.x2 * weight2;
|
sum.x2 = vector1.x2 * weight1 + vector2.x2 * weight2;
|
||||||
sum.x3 = vector1.x3 * weight1 + vector2.x3 * weight2;
|
sum.x3 = vector1.x3 * weight1 + vector2.x3 * weight2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum3(
|
public static void GetWeightedSum3(
|
||||||
double weight1, in DPVector3 vector1,
|
double weight1, in F64Vector3 vector1,
|
||||||
double weight2, in DPVector3 vector2,
|
double weight2, in F64Vector3 vector2,
|
||||||
double weight3, in DPVector3 vector3,
|
double weight3, in F64Vector3 vector3,
|
||||||
out DPVector3 sum)
|
out F64Vector3 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
sum.x1 = vector1.x1 * weight1 + vector2.x1 * weight2 + vector3.x1 * weight3;
|
||||||
sum.x2 = vector1.x2 * weight1 + vector2.x2 * weight2 + vector3.x2 * weight3;
|
sum.x2 = vector1.x2 * weight1 + vector2.x2 * weight2 + vector3.x2 * weight3;
|
||||||
sum.x3 = vector1.x3 * weight1 + vector2.x3 * weight2 + vector3.x3 * weight3;
|
sum.x3 = vector1.x3 * weight1 + vector2.x3 * weight2 + vector3.x3 * weight3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum4(
|
public static void GetWeightedSum4(
|
||||||
double weight1, in DPVector3 vector1,
|
double weight1, in F64Vector3 vector1,
|
||||||
double weight2, in DPVector3 vector2,
|
double weight2, in F64Vector3 vector2,
|
||||||
double weight3, in DPVector3 vector3,
|
double weight3, in F64Vector3 vector3,
|
||||||
double weight4, in DPVector3 vector4,
|
double weight4, in F64Vector3 vector4,
|
||||||
out DPVector3 sum)
|
out F64Vector3 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4);
|
||||||
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4);
|
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4);
|
||||||
sum.x3 = (vector1.x3 * weight1 + vector2.x3 * weight2) + (vector3.x3 * weight3 + vector4.x3 * weight4);
|
sum.x3 = (vector1.x3 * weight1 + vector2.x3 * weight2) + (vector3.x3 * weight3 + vector4.x3 * weight4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetWeightedSum5(
|
public static void GetWeightedSum5(
|
||||||
double weight1, in DPVector3 vector1,
|
double weight1, in F64Vector3 vector1,
|
||||||
double weight2, in DPVector3 vector2,
|
double weight2, in F64Vector3 vector2,
|
||||||
double weight3, in DPVector3 vector3,
|
double weight3, in F64Vector3 vector3,
|
||||||
double weight4, in DPVector3 vector4,
|
double weight4, in F64Vector3 vector4,
|
||||||
double weight5, in DPVector3 vector5,
|
double weight5, in F64Vector3 vector5,
|
||||||
out DPVector3 sum)
|
out F64Vector3 sum)
|
||||||
{
|
{
|
||||||
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4) + vector5.x1 * weight5;
|
sum.x1 = (vector1.x1 * weight1 + vector2.x1 * weight2) + (vector3.x1 * weight3 + vector4.x1 * weight4) + vector5.x1 * weight5;
|
||||||
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4) + vector5.x2 * weight5;
|
sum.x2 = (vector1.x2 * weight1 + vector2.x2 * weight2) + (vector3.x2 * weight3 + vector4.x2 * weight4) + vector5.x2 * weight5;
|
||||||
sum.x3 = (vector1.x3 * weight1 + vector2.x3 * weight2) + (vector3.x3 * weight3 + vector4.x3 * weight4) + vector5.x3 * weight5;
|
sum.x3 = (vector1.x3 * weight1 + vector2.x3 * weight2) + (vector3.x3 * weight3 + vector4.x3 * weight4) + vector5.x3 * weight5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean2(
|
public static void GetMean2(
|
||||||
in DPVector3 vector1,
|
in F64Vector3 vector1,
|
||||||
in DPVector3 vector2,
|
in F64Vector3 vector2,
|
||||||
out DPVector3 result)
|
out F64Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1) * 0.5;
|
result.x1 = (vector1.x1 + vector2.x1) * 0.5;
|
||||||
result.x2 = (vector1.x2 + vector2.x2) * 0.5;
|
result.x2 = (vector1.x2 + vector2.x2) * 0.5;
|
||||||
result.x3 = (vector1.x3 + vector2.x3) * 0.5;
|
result.x3 = (vector1.x3 + vector2.x3) * 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean3(
|
public static void GetMean3(
|
||||||
in DPVector3 vector1,
|
in F64Vector3 vector1,
|
||||||
in DPVector3 vector2,
|
in F64Vector3 vector2,
|
||||||
in DPVector3 vector3,
|
in F64Vector3 vector3,
|
||||||
out DPVector3 result)
|
out F64Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * DPUtility.ONE_THIRD;
|
result.x1 = (vector1.x1 + vector2.x1 + vector3.x1) * F64Utility.ONE_THIRD;
|
||||||
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * DPUtility.ONE_THIRD;
|
result.x2 = (vector1.x2 + vector2.x2 + vector3.x2) * F64Utility.ONE_THIRD;
|
||||||
result.x3 = (vector1.x3 + vector2.x3 + vector3.x3) * DPUtility.ONE_THIRD;
|
result.x3 = (vector1.x3 + vector2.x3 + vector3.x3) * F64Utility.ONE_THIRD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean4(
|
public static void GetMean4(
|
||||||
in DPVector3 vector1,
|
in F64Vector3 vector1,
|
||||||
in DPVector3 vector2,
|
in F64Vector3 vector2,
|
||||||
in DPVector3 vector3,
|
in F64Vector3 vector3,
|
||||||
in DPVector3 vector4,
|
in F64Vector3 vector4,
|
||||||
out DPVector3 result)
|
out F64Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1)) * 0.25;
|
||||||
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2)) * 0.25;
|
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2)) * 0.25;
|
||||||
result.x3 = ((vector1.x3 + vector2.x3) + (vector3.x3 + vector4.x3)) * 0.25;
|
result.x3 = ((vector1.x3 + vector2.x3) + (vector3.x3 + vector4.x3)) * 0.25;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetMean5(
|
public static void GetMean5(
|
||||||
in DPVector3 vector1,
|
in F64Vector3 vector1,
|
||||||
in DPVector3 vector2,
|
in F64Vector3 vector2,
|
||||||
in DPVector3 vector3,
|
in F64Vector3 vector3,
|
||||||
in DPVector3 vector4,
|
in F64Vector3 vector4,
|
||||||
in DPVector3 vector5,
|
in F64Vector3 vector5,
|
||||||
out DPVector3 result)
|
out F64Vector3 result)
|
||||||
{
|
{
|
||||||
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2;
|
result.x1 = ((vector1.x1 + vector2.x1) + (vector3.x1 + vector4.x1) + vector5.x1) * 0.2;
|
||||||
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2) + vector5.x2) * 0.2;
|
result.x2 = ((vector1.x2 + vector2.x2) + (vector3.x2 + vector4.x2) + vector5.x2) * 0.2;
|
||||||
result.x3 = ((vector1.x3 + vector2.x3) + (vector3.x3 + vector4.x3) + vector5.x3) * 0.2;
|
result.x3 = ((vector1.x3 + vector2.x3) + (vector3.x3 + vector4.x3) + vector5.x3) * 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetScalarProduct(in DPVector3 vector1, in DPVector3 vector2)
|
public static double GetScalarProduct(in F64Vector3 vector1, in F64Vector3 vector2)
|
||||||
{
|
{
|
||||||
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2 + vector1.x3 * vector2.x3;
|
return vector1.x1 * vector2.x1 + vector1.x2 * vector2.x2 + vector1.x3 * vector2.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetCrossProduct(in DPVector3 vector1, in DPVector3 vector2, out DPVector3 result)
|
public static void GetCrossProduct(in F64Vector3 vector1, in F64Vector3 vector2, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
double x1 = vector1.x2 * vector2.x3 - vector1.x3 * vector2.x2;
|
double x1 = vector1.x2 * vector2.x3 - vector1.x3 * vector2.x2;
|
||||||
double x2 = vector1.x3 * vector2.x1 - vector1.x1 * vector2.x3;
|
double x2 = vector1.x3 * vector2.x1 - vector1.x1 * vector2.x3;
|
||||||
double x3 = vector1.x1 * vector2.x2 - vector1.x2 * vector2.x1;
|
double x3 = vector1.x1 * vector2.x2 - vector1.x2 * vector2.x1;
|
||||||
|
|
||||||
result.x1 = x1;
|
result.x1 = x1;
|
||||||
result.x2 = x2;
|
result.x2 = x2;
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetTripleProduct(in DPVector3 vector1, in DPVector3 vector2, in DPVector3 vector3)
|
public static double GetTripleProduct(in F64Vector3 vector1, in F64Vector3 vector2, in F64Vector3 vector3)
|
||||||
{
|
{
|
||||||
return vector1.x1 * (vector2.x2 * vector3.x3 - vector2.x3 * vector3.x2)
|
return vector1.x1 * (vector2.x2 * vector3.x3 - vector2.x3 * vector3.x2)
|
||||||
+ vector1.x2 * (vector2.x3 * vector3.x1 - vector2.x1 * vector3.x3)
|
+ vector1.x2 * (vector2.x3 * vector3.x1 - vector2.x1 * vector3.x3)
|
||||||
+ vector1.x3 * (vector2.x1 * vector3.x2 - vector2.x2 * vector3.x1);
|
+ vector1.x3 * (vector2.x1 * vector3.x2 - vector2.x2 * vector3.x1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetDoubleCrossProduct(in DPVector3 vector1, in DPVector3 vector2, in DPVector3 vector3, out DPVector3 result)
|
public static void GetDoubleCrossProduct(in F64Vector3 vector1, in F64Vector3 vector2, in F64Vector3 vector3, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
// [a x [b x c]] = b * (a, c) - c * (a, b)
|
// [a x [b x c]] = b * (a, c) - c * (a, b)
|
||||||
double ac = GetScalarProduct(vector1, vector3);
|
double ac = GetScalarProduct(vector1, vector3);
|
||||||
double ab = GetScalarProduct(vector1, vector2);
|
double ab = GetScalarProduct(vector1, vector2);
|
||||||
|
|
||||||
result.x1 = ac * vector2.x1 - ab * vector3.x1;
|
result.x1 = ac * vector2.x1 - ab * vector3.x1;
|
||||||
result.x2 = ac * vector2.x2 - ab * vector3.x2;
|
result.x2 = ac * vector2.x2 - ab * vector3.x2;
|
||||||
result.x3 = ac * vector2.x3 - ab * vector3.x3;
|
result.x3 = ac * vector2.x3 - ab * vector3.x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetAngle(in DPVector3 vector1, in DPVector3 vector2, AngleUnit unit)
|
public static double GetAngle(in F64Vector3 vector1, in F64Vector3 vector2, AngleUnit unit)
|
||||||
{
|
{
|
||||||
double squareModule1 = vector1.GetSquareModule();
|
double squareModule1 = vector1.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule1 <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule1 <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double squareModule2 = vector2.GetSquareModule();
|
double squareModule2 = vector2.GetSquareModule();
|
||||||
|
|
||||||
if (squareModule2 <= DPUtility.SQUARE_EPSYLON)
|
if (squareModule2 <= F64Utility.SQUARE_EPSYLON)
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double cosine = DPVector3.GetScalarProduct(vector1, vector2) / Math.Sqrt(squareModule1 * squareModule2);
|
double cosine = F64Vector3.GetScalarProduct(vector1, vector2) / Math.Sqrt(squareModule1 * squareModule2);
|
||||||
|
|
||||||
if (1.0 - DPUtility.EPSYLON <= cosine)
|
if (1.0 - F64Utility.EPSYLON <= cosine)
|
||||||
{
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cosine <= -(1.0 - DPUtility.EPSYLON))
|
if (cosine <= -(1.0 - F64Utility.EPSYLON))
|
||||||
{
|
{
|
||||||
return DPAngle.GetHalfCircle(unit);
|
return F64Angle.GetHalfCircle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DPAngle.ConvertFromRadians(Math.Acos(cosine), unit);
|
return F64Radians.ToUnits(Math.Acos(cosine), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetSquareDistance(in DPVector3 vector1, in DPVector3 vector2)
|
public static double GetSquareDistance(in F64Vector3 vector1, in F64Vector3 vector2)
|
||||||
{
|
{
|
||||||
double dx1 = vector1.x1 - vector2.x1;
|
double dx1 = vector1.x1 - vector2.x1;
|
||||||
double dx2 = vector1.x2 - vector2.x2;
|
double dx2 = vector1.x2 - vector2.x2;
|
||||||
double dx3 = vector1.x3 - vector2.x3;
|
double dx3 = vector1.x3 - vector2.x3;
|
||||||
|
|
||||||
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
return dx1 * dx1 + dx2 * dx2 + dx3 * dx3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double GetDistance(in DPVector3 vector1, in DPVector3 vector2)
|
public static double GetDistance(in F64Vector3 vector1, in F64Vector3 vector2)
|
||||||
{
|
{
|
||||||
return Math.Sqrt(GetSquareDistance(vector1, vector2));
|
return Math.Sqrt(GetSquareDistance(vector1, vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool AreEqual(in DPVector3 vector1, in DPVector3 vector2)
|
public static bool AreEqual(in F64Vector3 vector1, in F64Vector3 vector2)
|
||||||
{
|
{
|
||||||
double squareModule1 = vector1.GetSquareModule();
|
double squareModule1 = vector1.GetSquareModule();
|
||||||
double squareModule2 = vector2.GetSquareModule();
|
double squareModule2 = vector2.GetSquareModule();
|
||||||
double squareModule3 = GetSquareDistance(vector1, vector2);
|
double squareModule3 = GetSquareDistance(vector1, vector2);
|
||||||
|
|
||||||
// 3.0 means dimension amount
|
// 3.0 means dimension amount
|
||||||
if (squareModule1 < DPUtility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < DPUtility.EPSYLON_EFFECTIVENESS_LIMIT)
|
if (squareModule1 < F64Utility.EPSYLON_EFFECTIVENESS_LIMIT || squareModule2 < F64Utility.EPSYLON_EFFECTIVENESS_LIMIT)
|
||||||
{
|
{
|
||||||
return squareModule3 < (3.0 * DPUtility.SQUARE_EPSYLON);
|
return squareModule3 < (3.0 * F64Utility.SQUARE_EPSYLON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (squareModule1 <= squareModule2)
|
if (squareModule1 <= squareModule2)
|
||||||
{
|
{
|
||||||
return squareModule3 <= (3.0 * DPUtility.SQUARE_EPSYLON) * squareModule2;
|
return squareModule3 <= (3.0 * F64Utility.SQUARE_EPSYLON) * squareModule2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return squareModule3 <= (3.0 * DPUtility.SQUARE_EPSYLON) * squareModule1;
|
return squareModule3 <= (3.0 * F64Utility.SQUARE_EPSYLON) * squareModule1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -20,11 +20,11 @@
|
||||||
* Date: 20 Oct 2024
|
* Date: 20 Oct 2024
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Geometry
|
namespace BGC
|
||||||
{
|
{
|
||||||
public struct DPVersor
|
public struct F64Versor
|
||||||
{
|
{
|
||||||
public static readonly DPVersor IDLE = new DPVersor(1.0, 0.0, 0.0, 0.0, 1.0);
|
public static readonly F64Versor IDLE = new F64Versor(1.0, 0.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
private double s0;
|
private double s0;
|
||||||
private double x1;
|
private double x1;
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Geometry
|
||||||
private double x3;
|
private double x3;
|
||||||
private double corrector;
|
private double corrector;
|
||||||
|
|
||||||
private DPVersor(double s0, double x1, double x2, double x3, double corrector)
|
private F64Versor(double s0, double x1, double x2, double x3, double corrector)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
|
|
@ -41,7 +41,7 @@ namespace Geometry
|
||||||
this.corrector = corrector;
|
this.corrector = corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVersor()
|
public F64Versor()
|
||||||
{
|
{
|
||||||
this.s0 = 1.0;
|
this.s0 = 1.0;
|
||||||
this.x1 = 0.0;
|
this.x1 = 0.0;
|
||||||
|
|
@ -50,7 +50,7 @@ namespace Geometry
|
||||||
this.corrector = 1.0;
|
this.corrector = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVersor(double s0, double x1, double x2, double x3)
|
public F64Versor(double s0, double x1, double x2, double x3)
|
||||||
{
|
{
|
||||||
this.s0 = s0;
|
this.s0 = s0;
|
||||||
this.x1 = x1;
|
this.x1 = x1;
|
||||||
|
|
@ -61,13 +61,13 @@ namespace Geometry
|
||||||
|
|
||||||
this.corrector = 2.0 - squareModule;
|
this.corrector = 2.0 - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0 - DPUtility.TWO_EPSYLON || 1.0 + DPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0 - F64Utility.TWO_EPSYLON || 1.0 + F64Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVersor(in DPVersor versor)
|
public F64Versor(in F64Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.s0;
|
this.s0 = versor.s0;
|
||||||
this.x1 = versor.x1;
|
this.x1 = versor.x1;
|
||||||
|
|
@ -76,7 +76,7 @@ namespace Geometry
|
||||||
this.corrector = versor.corrector;
|
this.corrector = versor.corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DPVersor(in SPVersor versor)
|
public F64Versor(in F32Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.GetScalar();
|
this.s0 = versor.GetScalar();
|
||||||
this.x1 = versor.GetX1();
|
this.x1 = versor.GetX1();
|
||||||
|
|
@ -87,7 +87,7 @@ namespace Geometry
|
||||||
|
|
||||||
this.corrector = 2.0 - squareModule;
|
this.corrector = 2.0 - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0 - DPUtility.TWO_EPSYLON || 1.0 + DPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0 - F64Utility.TWO_EPSYLON || 1.0 + F64Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +120,7 @@ namespace Geometry
|
||||||
|
|
||||||
public readonly bool IsIdle()
|
public readonly bool IsIdle()
|
||||||
{
|
{
|
||||||
return this.s0 <= -(1.0 - DPUtility.EPSYLON) || (1.0 - DPUtility.EPSYLON) <= this.s0;
|
return this.s0 <= -(1.0 - F64Utility.EPSYLON) || (1.0 - F64Utility.EPSYLON) <= this.s0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
|
|
@ -141,19 +141,19 @@ namespace Geometry
|
||||||
|
|
||||||
public readonly double GetAngle(AngleUnit unit)
|
public readonly double GetAngle(AngleUnit unit)
|
||||||
{
|
{
|
||||||
if (this.s0 <= -(1.0 - DPUtility.TWO_EPSYLON) || 1.0 - DPUtility.TWO_EPSYLON <= this.s0) {
|
if (this.s0 <= -(1.0 - F64Utility.TWO_EPSYLON) || 1.0 - F64Utility.TWO_EPSYLON <= this.s0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-DPUtility.EPSYLON <= this.s0 && this.s0 <= DPUtility.EPSYLON)
|
if (-F64Utility.EPSYLON <= this.s0 && this.s0 <= F64Utility.EPSYLON)
|
||||||
{
|
{
|
||||||
return DPAngle.GetHalfCircle(unit);
|
return F64Angle.GetHalfCircle(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DPAngle.ConvertFromRadians(2.0 * Math.Acos(s0), unit);
|
return F64Radians.ToUnits(2.0 * Math.Acos(s0), unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeRotationMatrix(out DPMatrix3x3 matrix)
|
public readonly void MakeRotationMatrix(out F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
double s0s0 = this.s0 * this.s0;
|
double s0s0 = this.s0 * this.s0;
|
||||||
double x1x1 = this.x1 * this.x1;
|
double x1x1 = this.x1 * this.x1;
|
||||||
|
|
@ -184,7 +184,7 @@ namespace Geometry
|
||||||
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
matrix.r1c3 = corrector2 * (x1x3 + s0x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void MakeReverseMatrix(out DPMatrix3x3 matrix)
|
public readonly void MakeReverseMatrix(out F64Matrix3x3 matrix)
|
||||||
{
|
{
|
||||||
double s0s0 = this.s0 * this.s0;
|
double s0s0 = this.s0 * this.s0;
|
||||||
double x1x1 = this.x1 * this.x1;
|
double x1x1 = this.x1 * this.x1;
|
||||||
|
|
@ -226,13 +226,13 @@ namespace Geometry
|
||||||
|
|
||||||
this.corrector = 2.0 - squareModule;
|
this.corrector = 2.0 - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0 - DPUtility.TWO_EPSYLON || 1.0 + DPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0 - F64Utility.TWO_EPSYLON || 1.0 + F64Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in DPVersor versor)
|
public void SetValues(in F64Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.s0;
|
this.s0 = versor.s0;
|
||||||
this.x1 = versor.x1;
|
this.x1 = versor.x1;
|
||||||
|
|
@ -241,7 +241,7 @@ namespace Geometry
|
||||||
this.corrector = versor.corrector;
|
this.corrector = versor.corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetValues(in SPVersor versor)
|
public void SetValues(in F32Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.GetScalar();
|
this.s0 = versor.GetScalar();
|
||||||
this.x1 = versor.GetX1();
|
this.x1 = versor.GetX1();
|
||||||
|
|
@ -252,13 +252,13 @@ namespace Geometry
|
||||||
|
|
||||||
this.corrector = 2.0 - squareModule;
|
this.corrector = 2.0 - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0 - DPUtility.TWO_EPSYLON || 1.0 + DPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0 - F64Utility.TWO_EPSYLON || 1.0 + F64Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetInverted(in DPVersor versor)
|
public void SetInverted(in F64Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.s0;
|
this.s0 = versor.s0;
|
||||||
this.x1 = -versor.x1;
|
this.x1 = -versor.x1;
|
||||||
|
|
@ -267,7 +267,7 @@ namespace Geometry
|
||||||
this.corrector = versor.corrector;
|
this.corrector = versor.corrector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetInverted(in SPVersor versor)
|
public void SetInverted(in F32Versor versor)
|
||||||
{
|
{
|
||||||
this.s0 = versor.GetScalar();
|
this.s0 = versor.GetScalar();
|
||||||
this.x1 = -versor.GetX1();
|
this.x1 = -versor.GetX1();
|
||||||
|
|
@ -278,13 +278,13 @@ namespace Geometry
|
||||||
|
|
||||||
this.corrector = 2.0 - squareModule;
|
this.corrector = 2.0 - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0 - DPUtility.TWO_EPSYLON || 1.0 + DPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0 - F64Utility.TWO_EPSYLON || 1.0 + F64Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
this.Normalize(squareModule);
|
this.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void Turn(in DPVector3 vector, out DPVector3 result)
|
public readonly void Turn(in F64Vector3 vector, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
double multiplier = 2.0 * this.corrector;
|
double multiplier = 2.0 * this.corrector;
|
||||||
double tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
double tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
||||||
|
|
@ -300,7 +300,7 @@ namespace Geometry
|
||||||
result.x3 = x3;
|
result.x3 = x3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly void TurnBack(in DPVector3 vector, out DPVector3 result)
|
public readonly void TurnBack(in F64Vector3 vector, out F64Vector3 result)
|
||||||
{
|
{
|
||||||
double multiplier = 2.0 * this.corrector;
|
double multiplier = 2.0 * this.corrector;
|
||||||
double tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
double tx1 = multiplier * (this.x2 * vector.x3 - this.x3 * vector.x2);
|
||||||
|
|
@ -318,7 +318,7 @@ namespace Geometry
|
||||||
|
|
||||||
private void Normalize(double squareModule)
|
private void Normalize(double squareModule)
|
||||||
{
|
{
|
||||||
if (squareModule <= DPUtility.SQUARE_EPSYLON || (this.x1 * this.x1 + this.x2 * this.x2 + this.x3 * this.x3) <= DPUtility.SQUARE_EPSYLON * squareModule)
|
if (squareModule <= F64Utility.SQUARE_EPSYLON || (this.x1 * this.x1 + this.x2 * this.x2 + this.x3 * this.x3) <= F64Utility.SQUARE_EPSYLON * squareModule)
|
||||||
{
|
{
|
||||||
this.Reset();
|
this.Reset();
|
||||||
return;
|
return;
|
||||||
|
|
@ -334,7 +334,7 @@ namespace Geometry
|
||||||
this.corrector = 2.0 - (this.s0 * this.s0 + this.x1 * this.x1) - (this.x2 * this.x2 + this.x3 * this.x3);
|
this.corrector = 2.0 - (this.s0 * this.s0 + this.x1 * this.x1) - (this.x2 * this.x2 + this.x3 * this.x3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Combine(in DPVersor second, in DPVersor first, out DPVersor result)
|
public static void Combine(in F64Versor second, in F64Versor first, out F64Versor result)
|
||||||
{
|
{
|
||||||
double s0 = (second.s0 * first.s0 - second.x1 * first.x1) - (second.x2 * first.x2 + second.x3 * first.x3);
|
double s0 = (second.s0 * first.s0 - second.x1 * first.x1) - (second.x2 * first.x2 + second.x3 * first.x3);
|
||||||
double x1 = (second.x1 * first.s0 + second.s0 * first.x1) - (second.x3 * first.x2 - second.x2 * first.x3);
|
double x1 = (second.x1 * first.s0 + second.s0 * first.x1) - (second.x3 * first.x2 - second.x2 * first.x3);
|
||||||
|
|
@ -350,7 +350,7 @@ namespace Geometry
|
||||||
|
|
||||||
result.corrector = 2.0 - squareModule;
|
result.corrector = 2.0 - squareModule;
|
||||||
|
|
||||||
if (squareModule < 1.0 - DPUtility.TWO_EPSYLON || 1.0 + DPUtility.TWO_EPSYLON < squareModule)
|
if (squareModule < 1.0 - F64Utility.TWO_EPSYLON || 1.0 + F64Utility.TWO_EPSYLON < squareModule)
|
||||||
{
|
{
|
||||||
result.Normalize(squareModule);
|
result.Normalize(squareModule);
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Geometry\Geometry.csproj" />
|
<ProjectReference Include="..\BGC\BGC.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -1,80 +1,80 @@
|
||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Geometry;
|
using BGC;
|
||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
private static SPVersor[] AllocateVersors(int amount)
|
private static F32Versor[] AllocateVersors(int amount)
|
||||||
{
|
{
|
||||||
return new SPVersor[amount];
|
return new F32Versor[amount];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SPVersor[] MakeZeroVersors(int amount)
|
private static F32Versor[] MakeZeroVersors(int amount)
|
||||||
{
|
{
|
||||||
SPVersor[] versors = AllocateVersors(amount);
|
F32Versor[] versors = AllocateVersors(amount);
|
||||||
|
|
||||||
for (int i = 0; i < amount; i++)
|
for (int i = 0; i < amount; i++)
|
||||||
{
|
{
|
||||||
versors[i] = SPVersor.IDLE;
|
versors[i] = F32Versor.IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return versors;
|
return versors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SPVersor[] MakeRandomVersors(int amount)
|
private static F32Versor[] MakeRandomVersors(int amount)
|
||||||
{
|
{
|
||||||
Random randomizer = new Random(Environment.TickCount);
|
Random randomizer = new Random(Environment.TickCount);
|
||||||
|
|
||||||
SPVersor[] versors = AllocateVersors(amount);
|
F32Versor[] versors = AllocateVersors(amount);
|
||||||
|
|
||||||
for (int i = 0; i < amount; i++)
|
for (int i = 0; i < amount; i++)
|
||||||
{
|
{
|
||||||
versors[i] = new SPVersor(
|
versors[i] = new F32Versor(
|
||||||
randomizer.NextSingle(),
|
randomizer.NextSingle(),
|
||||||
randomizer.NextSingle(),
|
randomizer.NextSingle(),
|
||||||
randomizer.NextSingle(),
|
randomizer.NextSingle(),
|
||||||
randomizer.NextSingle()
|
randomizer.NextSingle()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return versors;
|
return versors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PrintVersor(in SPVersor versor)
|
private static void PrintVersor(in F32Versor versor)
|
||||||
{
|
{
|
||||||
Console.WriteLine("({0}, {1}, {2}, {3}) / {4:E}", versor.GetScalar(), versor.GetX1(), versor.GetX2(), versor.GetX3(), versor.GetCorrector() - 1.0f);
|
Console.WriteLine("({0}, {1}, {2}, {3}) / {4:E}", versor.GetScalar(), versor.GetX1(), versor.GetX2(), versor.GetX3(), versor.GetCorrector() - 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int Main()
|
public static int Main()
|
||||||
{
|
{
|
||||||
int amount = 1000000;
|
int amount = 1000000;
|
||||||
|
|
||||||
SPVersor[] versors1 = MakeRandomVersors(amount);
|
F32Versor[] versors1 = MakeRandomVersors(amount);
|
||||||
SPVersor[] versors2 = MakeRandomVersors(amount);
|
F32Versor[] versors2 = MakeRandomVersors(amount);
|
||||||
SPVersor[] results = MakeZeroVersors(amount);
|
F32Versor[] results = MakeZeroVersors(amount);
|
||||||
|
|
||||||
long start, end;
|
long start, end;
|
||||||
|
|
||||||
start = Environment.TickCount64;
|
start = Environment.TickCount64;
|
||||||
|
|
||||||
for (int j = 0; j < 1000; j++)
|
for (int j = 0; j < 1000; j++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < amount; i++)
|
for (int i = 0; i < amount; i++)
|
||||||
{
|
{
|
||||||
SPVersor.Combine(versors1[i], versors2[i], out results[i]);
|
F32Versor.Combine(versors1[i], versors2[i], out results[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end = Environment.TickCount64;
|
end = Environment.TickCount64;
|
||||||
|
|
||||||
Console.WriteLine("Time: {0}", end - start);
|
Console.WriteLine("Time: {0}", end - start);
|
||||||
|
|
||||||
PrintVersor(versors1[10]);
|
PrintVersor(versors1[10]);
|
||||||
PrintVersor(versors2[10]);
|
PrintVersor(versors2[10]);
|
||||||
PrintVersor(results[10]);
|
PrintVersor(results[10]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
|
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
|
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
|
||||||
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
||||||
<ProjectReference Include="..\Geometry\Geometry.csproj" />
|
<ProjectReference Include="..\BGC\BGC.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using Geometry;
|
using BGC;
|
||||||
|
|
||||||
namespace GeometryTest
|
namespace BGCTest
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class Vector2FloatTest
|
public class F32Vector2Test
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestInitialization()
|
public void TestInitialization()
|
||||||
{
|
{
|
||||||
SPVector2 vector = new SPVector2(1.0f, 2.0f);
|
F32Vector2 vector = new F32Vector2(1.0f, 2.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,305 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Author: Andrey Pokidov
|
|
||||||
* Date: 1 Feb 2019
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Geometry
|
|
||||||
{
|
|
||||||
public static class DPAngle
|
|
||||||
{
|
|
||||||
public const double PI = 3.14159265358979324;
|
|
||||||
public const double TWO_PI = 6.28318530717958648;
|
|
||||||
public const double HALF_OF_PI = 1.57079632679489662;
|
|
||||||
public const double THIRD_OF_PI = 1.04719755119659775;
|
|
||||||
public const double FOURTH_OF_PI = 0.78539816339744831;
|
|
||||||
public const double SIXTH_OF_PI = 0.523598775598298873;
|
|
||||||
|
|
||||||
public const double DEGREES_IN_RADIAN = 57.2957795130823209;
|
|
||||||
public const double TURNS_IN_RADIAN = 0.159154943091895336;
|
|
||||||
public const double RADIANS_IN_DEGREE = 1.74532925199432958E-2;
|
|
||||||
public const double TURNS_IN_DEGREE = 2.77777777777777778E-3;
|
|
||||||
|
|
||||||
public static double RadiansToDegrees(double radians)
|
|
||||||
{
|
|
||||||
return radians * DEGREES_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double RadiansToTurns(double radians)
|
|
||||||
{
|
|
||||||
return radians * TURNS_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double DegreesToRadians(double degrees)
|
|
||||||
{
|
|
||||||
return degrees * RADIANS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double DegreesToTurns(double degrees)
|
|
||||||
{
|
|
||||||
return degrees * TURNS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double TurnsToRadians(double turns)
|
|
||||||
{
|
|
||||||
return turns * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double TurnsToDegrees(double turns)
|
|
||||||
{
|
|
||||||
return turns * 360.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double ConvertFromRadians(double radians, AngleUnit toUnit)
|
|
||||||
{
|
|
||||||
if (toUnit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return radians * DEGREES_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toUnit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return radians * TURNS_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double ConvertFromDegrees(double degrees, AngleUnit toUnit)
|
|
||||||
{
|
|
||||||
if (toUnit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return degrees * RADIANS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toUnit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return degrees * TURNS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double ConvertFromTurns(double turns, AngleUnit toUnit)
|
|
||||||
{
|
|
||||||
if (toUnit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return turns * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toUnit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return turns * 360.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return turns;
|
|
||||||
}
|
|
||||||
public static double ConvertToRadians(double angle, AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return angle * RADIANS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return angle * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double ConvertToDegrees(double angle, AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return angle * DEGREES_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return angle * 360.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double ConvertToTurns(double angle, AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return angle * TURNS_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return angle * TURNS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double GetFullCircle(AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return 360.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double GetHalfCircle(AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return 180.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double GetQuarterCircle(AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return HALF_OF_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return 90.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0.25;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double NormalizeRadians(double radians, AngleRange range)
|
|
||||||
{
|
|
||||||
if (range == AngleRange.UNSIGNED_RANGE)
|
|
||||||
{
|
|
||||||
if (0.0 <= radians && radians < TWO_PI)
|
|
||||||
{
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (-PI < radians && radians <= PI)
|
|
||||||
{
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double turns = radians * TURNS_IN_RADIAN;
|
|
||||||
|
|
||||||
turns -= Math.Floor(turns);
|
|
||||||
|
|
||||||
if (range == AngleRange.SIGNED_RANGE && turns > 0.5)
|
|
||||||
{
|
|
||||||
turns -= 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return turns * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double NormalizeDegrees(double degrees, AngleRange range)
|
|
||||||
{
|
|
||||||
if (range == AngleRange.UNSIGNED_RANGE)
|
|
||||||
{
|
|
||||||
if (0.0 <= degrees && degrees < 360.0)
|
|
||||||
{
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (-180.0 < degrees && degrees <= 180.0)
|
|
||||||
{
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double turns = degrees * TURNS_IN_DEGREE;
|
|
||||||
|
|
||||||
turns -= Math.Floor(turns);
|
|
||||||
|
|
||||||
if (range == AngleRange.SIGNED_RANGE && turns > 0.5)
|
|
||||||
{
|
|
||||||
turns -= 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return turns * 360.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double NormalizeTurns(double turns, AngleRange range)
|
|
||||||
{
|
|
||||||
if (range == AngleRange.UNSIGNED_RANGE)
|
|
||||||
{
|
|
||||||
if (0.0 <= turns && turns < 1.0)
|
|
||||||
{
|
|
||||||
return turns;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (-0.5 < turns && turns <= 0.5)
|
|
||||||
{
|
|
||||||
return turns;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double rest = turns - Math.Floor(turns);
|
|
||||||
|
|
||||||
if (range == AngleRange.SIGNED_RANGE && rest > 0.5)
|
|
||||||
{
|
|
||||||
rest -= 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double Normalize(double angle, AngleUnit unit, AngleRange range)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return NormalizeRadians(angle, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return NormalizeDegrees(angle, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NormalizeTurns(angle, range);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,306 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019-2025 Andrey Pokidov <andrey.pokidov@gmail.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Author: Andrey Pokidov
|
|
||||||
* Date: 1 Feb 2019
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Geometry
|
|
||||||
{
|
|
||||||
public static class SPAngle
|
|
||||||
{
|
|
||||||
public const float PI = 3.1415926536f;
|
|
||||||
public const float TWO_PI = 6.2831853072f;
|
|
||||||
public const float HALF_OF_PI = 1.5707963268f;
|
|
||||||
public const float THIRD_OF_PI = 1.0471975512f;
|
|
||||||
public const float FOURTH_OF_PI = 0.7853981634f;
|
|
||||||
public const float SIXTH_OF_PI = 0.5235987756f;
|
|
||||||
|
|
||||||
public const float DEGREES_IN_RADIAN = 57.295779513f;
|
|
||||||
public const float TURNS_IN_RADIAN = 0.1591549431f;
|
|
||||||
public const float RADIANS_IN_DEGREE = 1.745329252E-2f;
|
|
||||||
public const float TURNS_IN_DEGREE = 2.7777777778E-3f;
|
|
||||||
|
|
||||||
public static float RadiansToDegrees(float radians)
|
|
||||||
{
|
|
||||||
return radians * DEGREES_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float RadiansToTurns(float radians)
|
|
||||||
{
|
|
||||||
return radians * TURNS_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float DegreesToRadians(float degrees)
|
|
||||||
{
|
|
||||||
return degrees * RADIANS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float DegreesToTurns(float degrees)
|
|
||||||
{
|
|
||||||
return degrees * TURNS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float TurnsToRadians(float turns)
|
|
||||||
{
|
|
||||||
return turns * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float TurnsToDegrees(float turns)
|
|
||||||
{
|
|
||||||
return turns * 360.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float ConvertFromRadians(float radians, AngleUnit toUnit)
|
|
||||||
{
|
|
||||||
if (toUnit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return radians * DEGREES_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toUnit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return radians * TURNS_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float ConvertFromDegrees(float degrees, AngleUnit toUnit)
|
|
||||||
{
|
|
||||||
if (toUnit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return degrees * RADIANS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toUnit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return degrees * TURNS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float ConvertFromTurns(float turns, AngleUnit toUnit)
|
|
||||||
{
|
|
||||||
if (toUnit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return turns * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toUnit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return turns * 360.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return turns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float ConvertToRadians(float angle, AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return angle * RADIANS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return angle * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float ConvertToDegrees(float angle, AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return angle * DEGREES_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.TURNS)
|
|
||||||
{
|
|
||||||
return angle * 360.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float ConvertToTurns(float angle, AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return angle * TURNS_IN_RADIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return angle * TURNS_IN_DEGREE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float GetFullCircle(AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return 360.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float GetHalfCircle(AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return 180.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float GetQuarterCircle(AngleUnit unit)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return HALF_OF_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return 90.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0.25f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float NormalizeRadians(float radians, AngleRange range)
|
|
||||||
{
|
|
||||||
if (range == AngleRange.UNSIGNED_RANGE)
|
|
||||||
{
|
|
||||||
if (0.0 <= radians && radians < TWO_PI)
|
|
||||||
{
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (-PI < radians && radians <= PI)
|
|
||||||
{
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float turns = radians * TURNS_IN_RADIAN;
|
|
||||||
|
|
||||||
turns -= MathF.Floor(turns);
|
|
||||||
|
|
||||||
if (range == AngleRange.SIGNED_RANGE && turns > 0.5f)
|
|
||||||
{
|
|
||||||
turns -= 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return turns * TWO_PI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float NormalizeDegrees(float radians, AngleRange range)
|
|
||||||
{
|
|
||||||
if (range == AngleRange.UNSIGNED_RANGE)
|
|
||||||
{
|
|
||||||
if (0.0f <= radians && radians < 360.0f)
|
|
||||||
{
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (-180.0f < radians && radians <= 180.0f)
|
|
||||||
{
|
|
||||||
return radians;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float turns = radians * TURNS_IN_DEGREE;
|
|
||||||
|
|
||||||
turns -= MathF.Floor(turns);
|
|
||||||
|
|
||||||
if (range == AngleRange.SIGNED_RANGE && turns > 0.5f)
|
|
||||||
{
|
|
||||||
turns -= 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return turns * 360.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float NormalizeTurns(float turns, AngleRange range)
|
|
||||||
{
|
|
||||||
if (range == AngleRange.UNSIGNED_RANGE)
|
|
||||||
{
|
|
||||||
if (0.0f <= turns && turns < 1.0f)
|
|
||||||
{
|
|
||||||
return turns;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (-0.5f < turns && turns <= 0.5f)
|
|
||||||
{
|
|
||||||
return turns;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float rest = turns - MathF.Floor(turns);
|
|
||||||
|
|
||||||
if (range == AngleRange.SIGNED_RANGE && rest > 0.5f)
|
|
||||||
{
|
|
||||||
rest -= 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float Normalize(float angle, AngleUnit unit, AngleRange range)
|
|
||||||
{
|
|
||||||
if (unit == AngleUnit.RADIANS)
|
|
||||||
{
|
|
||||||
return NormalizeRadians(angle, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unit == AngleUnit.DEGREES)
|
|
||||||
{
|
|
||||||
return NormalizeDegrees(angle, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NormalizeTurns(angle, range);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue