-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMatrix3RotationSimpleTest.cs
More file actions
117 lines (104 loc) · 3.88 KB
/
Matrix3RotationSimpleTest.cs
File metadata and controls
117 lines (104 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using FoundryMicroCore.Core.Extensions;
// -----------------------------------------------------------------------------
// Matrix3RotationSimpleTest.cs
//
// This test verifies that Transform3 rotation produces the expected matrix for
// simple 90-degree rotations about X, Y, and Z axes.
//
// IMPORTANT CONVENTIONS:
// - Euler angles in the Transform3 system are STORED INTERNALLY IN RADIANS.
// - Use Euler.FromDegrees(x, y, z) to construct Euler angles from degrees.
// - Use Euler.FromRadians(x, y, z) to construct Euler angles from radians.
// - Always be explicit about units when setting or reading Euler angles.
// - All tests here use degrees for clarity, but the system converts to radians internally.
//
// This documentation is intended to prevent confusion and bugs caused by mixing up degrees and radians.
// -----------------------------------------------------------------------------
using FoundryRulesAndUnits.Extensions;
using FoundryWorldsAndDrawings.ThreeD.Maths;
namespace Three2025
{
/// <summary>
/// Simple diagnostic tests for Transform3 rotation matrices.
///
/// Angle conventions:
/// - Euler angles are always stored in radians internally.
/// - Use Euler.FromDegrees for degree input, Euler.FromRadians for radian input.
/// - All test cases here use degrees for clarity.
/// </summary>
public class Matrix3RotationSimpleTest
{
public static void Run()
{
TestRotateX90();
TestRotateY90();
TestRotateZ90();
}
private static void TestRotateX90()
{
var t = new Transform3("TestX");
t.Rotation = Euler.FromDegrees(90, 0, 0); // degrees
var m = t.ToMatrix3();
// Expected 4x4 matrix for 90° rotation about X axis (right-handed system):
double[] expected = new double[]
{
1, 0, 0, 0,
0, 0, -1, 0,
0, 1, 0, 0,
0, 0, 0, 1
};
CheckMatrix("Transform3.RotateX(90)", m.Elements, expected);
}
private static void TestRotateY90()
{
var t = new Transform3("TestY");
t.Rotation = Euler.FromDegrees(0, 90, 0); // degrees
var m = t.ToMatrix3();
// Expected 4x4 matrix for 90° rotation about Y axis (right-handed system):
double[] expected = new double[]
{
0, 0, 1, 0,
0, 1, 0, 0,
-1, 0, 0, 0,
0, 0, 0, 1
};
CheckMatrix("Transform3.RotateY(90)", m.Elements, expected);
}
private static void TestRotateZ90()
{
var t = new Transform3("TestZ");
t.Rotation = Euler.FromDegrees(0, 0, 90); // degrees
var m = t.ToMatrix3();
// Expected 4x4 matrix for 90° rotation about Z axis (right-handed system):
double[] expected = new double[]
{
0, -1, 0, 0,
1, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
CheckMatrix("Transform3.RotateZ(90)", m.Elements, expected);
}
private static void CheckMatrix(string testName, double[] actual, double[] expected)
{
bool success = true;
int n = expected.Length; // Should be 16 for 4x4
for (int i = 0; i < n; i++)
{
if (Math.Abs(actual[i] - expected[i]) > 1e-6)
{
$"{testName}: Matrix element {i} mismatch (actual={actual[i]:F2}, expected={expected[i]:F2})".WriteError();
success = false;
}
}
if (success)
{
$"{testName}: Success".WriteSuccess();
}
else
{
$"{testName}: Failed".WriteError();
}
}
}
}