// Transform by matrix public void PlaneTransformTest1() { PlaneD target = new PlaneD(1, 2, 3, 4); target = PlaneD.Normalize(target); Matrix4x4D m = Matrix4x4D.CreateRotationX(MathHelper.ToRadians(30.0f)) * Matrix4x4D.CreateRotationY(MathHelper.ToRadians(30.0f)) * Matrix4x4D.CreateRotationZ(MathHelper.ToRadians(30.0f)); m.M41 = 10.0f; m.M42 = 20.0f; m.M43 = 30.0f; PlaneD expected = new PlaneD(); Matrix4x4D.Invert(m, out var inv); Matrix4x4D itm = Matrix4x4D.Transpose(inv); double x = target.Normal.X, y = target.Normal.Y, z = target.Normal.Z, w = target.D; expected.Normal = new Vector3D( x * itm.M11 + y * itm.M21 + z * itm.M31 + w * itm.M41, x * itm.M12 + y * itm.M22 + z * itm.M32 + w * itm.M42, x * itm.M13 + y * itm.M23 + z * itm.M33 + w * itm.M43); expected.D = x * itm.M14 + y * itm.M24 + z * itm.M34 + w * itm.M44; PlaneD actual; actual = PlaneD.Transform(target, m); Assert.True(MathHelper.Equal(expected, actual), "PlaneD.Transform did not return the expected value."); }
// Transform by QuaternionD public void PlaneTransformTest2() { PlaneD target = new PlaneD(1, 2, 3, 4); target = PlaneD.Normalize(target); Matrix4x4D m = Matrix4x4D.CreateRotationX(MathHelper.ToRadians(30.0f)) * Matrix4x4D.CreateRotationY(MathHelper.ToRadians(30.0f)) * Matrix4x4D.CreateRotationZ(MathHelper.ToRadians(30.0f)); QuaternionD q = QuaternionD.CreateFromRotationMatrix(m); PlaneD expected = new PlaneD(); double x = target.Normal.X, y = target.Normal.Y, z = target.Normal.Z, w = target.D; expected.Normal = new Vector3D( x * m.M11 + y * m.M21 + z * m.M31 + w * m.M41, x * m.M12 + y * m.M22 + z * m.M32 + w * m.M42, x * m.M13 + y * m.M23 + z * m.M33 + w * m.M43); expected.D = x * m.M14 + y * m.M24 + z * m.M34 + w * m.M44; PlaneD actual; actual = PlaneD.Transform(target, q); Assert.True(MathHelper.Equal(expected, actual), "PlaneD.Transform did not return the expected value."); }
public void PlaneNormalizeTest() { PlaneD target = new PlaneD(1, 2, 3, 4); double f = target.Normal.LengthSquared(); double invF = 1.0f / (double)Math.Sqrt(f); PlaneD expected = new PlaneD(target.Normal * invF, target.D * invF); PlaneD actual = PlaneD.Normalize(target); Assert.True(MathHelper.Equal(expected, actual), "PlaneD.Normalize returns unexpected value."); // normalize, normalized normal. actual = PlaneD.Normalize(actual); Assert.True(MathHelper.Equal(expected, actual), "PlaneD.Normalize returns unexpected value."); }
public void Normalize_Instance(PlaneD plane, PlaneD expected) { var normalizedPlane = plane.Normalize(); Assert.Equal(normalizedPlane, expected); }