Esempio n. 1
0
        private void testMatrices()
        {
            var v  = new JVertex3D(3, 4, 5, 1);
            var vr = new JVertex3D(0, 0, 5, 1);

            // trnaslation
            var a  = new JTranslationMatrix3D(new JVertex3D(1, 0, 0, 0));
            var b  = new JTranslationMatrix3D(new JVertex3D(0, 1, 0, 0));
            var c1 = b * v;
            var c2 = a * b * v;

            // scale
            var s  = new JScaleMatrix3D(new JVertex3D(2, 0.5, 1, 0));
            var vs = s * v;

            // quaternion
            var qxz  = new JQuaternion3D(new JVertex3D(1, 0, 0, 0), new JVertex3D(0, 0, 1, 0));
            var rxz  = new JRotationMatrix3D(qxz);
            var vrxz = rxz * vr;

            // rotate
            var qx  = new JQuaternion3D(new JVertex3D(1, 0, 0, 0), Math.PI / 2);
            var qy  = new JQuaternion3D(new JVertex3D(0, 1, 0, 0), Math.PI / 2);
            var qz  = new JQuaternion3D(new JVertex3D(0, 0, 1, 0), Math.PI / 2);
            var rx  = new JRotationMatrix3D(qx);
            var ry  = new JRotationMatrix3D(qy);
            var rz  = new JRotationMatrix3D(qz);
            var vrx = rx * vr;
            var vry = ry * vr;
            var vrz = rz * vr;
        }
Esempio n. 2
0
 public static JVertex3D Cross(JVertex3D a, JVertex3D b)
 {
     return(new JVertex3D(
                a.Y * b.Z - a.Z * b.Y,
                a.Z * b.X - a.X * b.Z,
                a.X * b.Y - a.Y * b.X,
                0));
 }
Esempio n. 3
0
        public JQuaternion3D(JVertex3D axis, double angle)
        {
            axis = axis.Normalized; // this provides that the quaternion is normalized

            X = axis.X * Math.Sin(angle / 2);
            Y = axis.Y * Math.Sin(angle / 2);
            Z = axis.Z * Math.Sin(angle / 2);
            W = Math.Cos(angle / 2);
        }
Esempio n. 4
0
        public JLine3D(JVertex3D start, JVertex3D stop)
        {
            Start = start;
            Stop  = stop;

            Start.W = 1;
            Stop.W  = 1;

            if (start == stop)
            {
                throw new ArgumentException("Start and Stoppoint of line are the same.");
            }
        }
Esempio n. 5
0
        public JQuaternion3D(JVertex3D a, JVertex3D b) // rotation from a to b
        {
            double    normAB = Math.Sqrt(a.SquaredLength * b.SquaredLength);
            double    ct     = JVertex3D.Dot(a, b) / normAB;
            double    hc     = Math.Sqrt(0.5 * (1.0 + ct));
            JVertex3D w      = JVertex3D.Cross(a, b) / (normAB * 2.0 * hc);

            X = w.X;
            Y = w.Y;
            Z = w.Z;
            W = hc;

            Normalize();

            /*
             * float norm_u_norm_v = sqrt(sqlength(u) * sqlength(v));
             * float cos_theta = dot(u, v) / norm_u_norm_v;
             * float half_cos = sqrt(0.5f * (1.f + cos_theta));
             * vec3 w = cross(u, v) / (norm_u_norm_v * 2.f * half_cos);
             * return quat(half_cos, w.x, w.y, w.z);
             */
        }
Esempio n. 6
0
 public static double Dot(JVertex3D a, JVertex3D b)
 {
     return(a.X * b.X + a.Y * b.Y + a.Z * b.Z);
 }