Esempio n. 1
0
        public void TestVelocityOnPlane()
        {
            Frisbee.SimulationState st = new Frisbee.SimulationState
                                             {
                                                 VX = 1,
                                                 VY = 1,
                                                 Theta = Math.PI / 4
                                             };

            Matrix<double> transformation =
                new SparseMatrix(new [,]
                                     {
                                         {st.CosTheta, st.SinTheta*st.SinPhi, -st.SinTheta*st.CosPhi},
                                         {0, st.CosPhi, st.SinPhi},
                                         {st.SinTheta, -st.CosTheta*st.SinPhi, st.CosTheta*st.CosPhi}
                                     });

            SparseVector c3 = new SparseVector(transformation.Row(2));

            SparseVector velocity = new SparseVector(new[] { st.VX, st.VY, st.VZ });
            double velocityMagnitude = velocity.Norm(2);

            double velocityC3 = velocity.DotProduct(c3);

            Vector<double> vp = velocity.Subtract(c3.Multiply(velocityC3));
            double vpMagnitude = vp.Norm(2);
        }
Esempio n. 2
0
 private static double CosineR(SparseVector Vector_a, SparseVector Vector_b)
 {
     return Vector_a.DotProduct(Vector_b) / (Vector_a.L2Norm() * Vector_b.L2Norm());
     //return Distance.Cosine(R.Row(a).ToArray(), R.Row(b).ToArray());
 }
        public void CanDotProductOfTwoSparseVectors()
        {
            var vectorA = new SparseVector(10000);
            vectorA[200] = 1;
            vectorA[500] = 3;
            vectorA[800] = 5;
            vectorA[100] = 7;
            vectorA[900] = 9;

            var vectorB = new SparseVector(10000);
            vectorB[300] = 3;
            vectorB[500] = 5;
            vectorB[800] = 7;

            Assert.AreEqual(50.0, vectorA.DotProduct(vectorB));
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            double theta = 45D*Math.PI/180D, phi = 0D*Math.PI/180D;

            //double x = Math.Sin(angle);
            //double y = -Math.Cos(angle) * Math.Sin(0D);
            //double z = Math.Cos(angle) * Math.Cos(0D);

            //SparseVector vectorSpeed = new SparseVector(new double[]{1D, 1D, 1D });
            //SparseVector vectorC3 = new SparseVector(new double[]{x, y, z });
            //double dotProduct = vectorSpeed.DotProduct(vectorC3);
            //Vector<double> subtract = vectorSpeed.Subtract(vectorC3.Multiply(dotProduct));

            //m_axeXZ.AddPoint(0.5, 0.5);
            //m_axeXZ.AddPoint(subtract[0], subtract[1]);

            Matrix<double> transformation =
                //new SparseMatrix(new double[,]
                //                     {
                //                         {Math.Cos(theta), Math.Sin(theta)*Math.Sin(phi), -Math.Sin(theta)*Math.Cos(phi)},
                //                         {0, Math.Cos(phi), Math.Cos(phi)},
                //                         {Math.Sin(theta), -Math.Cos(theta)*Math.Cos(phi), Math.Cos(theta)*Math.Cos(phi)}
                //                     });

                new SparseMatrix(new double[,]
                                     {
                                         {0, 0, 0},
                                         {0, 0, 0},
                                         {Math.Sin(theta), -Math.Cos(theta)*Math.Cos(phi), Math.Cos(theta)*Math.Cos(phi)}
                                     });

            //SparseVector vectorSpeed = new SparseVector(new double[] { 1D, 0D, 0D });

            //Vector<double> multiply = transformation.Multiply(vectorSpeed);

            //DisplayVector(multiply);

            SparseVector vectorC3 = new SparseVector(new double[] { 0D, 0D, 1D });
            SparseVector vectorSpeed = new SparseVector(new double[] { Math.Cos(Math.PI / 4), 0D, Math.Sin(Math.PI / 4) });

            double dotProduct = vectorSpeed.DotProduct(vectorC3);
        }