예제 #1
0
 public void PushCoordinateSystem(CoordinateSystem csystem) {
     if (csystems.Count == 0) {
         csystems.Push(csystem);
     } else {
         csystems.Push(csystems.Peek().ToAbsolute(csystem));
     }
 }
예제 #2
0
 public void ScaleTest()
 {
     var cs = new CoordinateSystem();
     cs.Scale(2, 5, 7);
     Assert.AreEqual(new Vector3D(2, 0, 0), cs.U);
     Assert.AreEqual(new Vector3D(0, 5, 0), cs.V);
     Assert.AreEqual(new Vector3D(0, 0, 7), cs.W);
 }
예제 #3
0
 public CoordinateSystem ToAbsolute(CoordinateSystem cs)
 {
     var res = new CoordinateSystem {
         U = ToAbsolute(cs.U),
         V = ToAbsolute(cs.V),
         W = ToAbsolute(cs.W),
         Position = cs.Position + Position
     };
     return res;
 }
예제 #4
0
        public void DoubleConversionTest()
        {
            var cs = new CoordinateSystem {
                U = new Vector3D(1, 5, 2),
                V = new Vector3D(10, -2, 4),
                W = new Vector3D(3, 4, -2),
                Position = new Vector3D(100, 50, 20)
            };
            var localPoint = new Vector3D(-1, 5, 7);
            var globalPoint = cs.ToAbsolute(localPoint);

            var csReversed = cs.ToReverse();
            var local = csReversed.ToAbsolute(globalPoint);

            const double epsilon = 0.000001;
            Assert.AreEqual(localPoint.X, local.X, epsilon);
            Assert.AreEqual(localPoint.Y, local.Y, epsilon);
            Assert.AreEqual(localPoint.Z, local.Z, epsilon);
        }
예제 #5
0
 public Camera3D() {
     CoordinateSystem = new CoordinateSystem();
     Ratio = 4.0 / 3.0;
     FocusDistance = 0.035;
     FOV = 60 * System.Math.PI / 180;
 }
예제 #6
0
 public void Shift()
 {
     var cs = new CoordinateSystem();
     cs.Shift(2, 5, 7);
     Assert.AreEqual(new Vector3D(2, 5, 7), cs.Position);
 }
예제 #7
0
 protected REBaseShape(Shape3D origin) {
     _material = origin.Material;
     _inner = origin.CoordinateSystem;
     _outer = origin.CoordinateSystem.ToReverse();
 }
예제 #8
0
 protected Object3D(Vector3D position) {
     CoordinateSystem = new CoordinateSystem {
         Position = position
     };
 }
예제 #9
0
        public CoordinateSystem ToReverse()
        {
            var det = CalcDet();

            var u = U;
            var v = V;
            var w = W;

            var c11 = (v.Y * w.Z - w.Y * v.Z) / det;
            var c12 = (w.Y * u.Z - u.Y * w.Z) / det;
            var c13 = (u.Y * v.Z - v.Y * u.Z) / det;

            var c21 = (w.X * v.Z - v.X * w.Z) / det;
            var c22 = (u.X * w.Z - w.X * u.Z) / det;
            var c23 = (v.X * u.Z - u.X * v.Z) / det;

            var c31 = (v.X * w.Y - w.X * v.Y) / det;
            var c32 = (w.X * u.Y - u.X * w.Y) / det;
            var c33 = (u.X * v.Y - v.X * u.Y) / det;

            var cs = new CoordinateSystem {
                U = new Vector3D(c11, c12, c13),
                V = new Vector3D(c21, c22, c23),
                W = new Vector3D(c31, c32, c33),
                Position = new Vector3D(
                    -(Position.X * c11 + Position.Y * c21 + Position.Z * c31),
                    -(Position.X * c12 + Position.Y * c22 + Position.Z * c32),
                    -(Position.X * c13 + Position.Y * c23 + Position.Z * c33)
                )
            };
            return cs;
        }