Exemple #1
0
    public static MathNet.Numerics.LinearAlgebra.Vector <float> AddSubVector(
        this MathNet.Numerics.LinearAlgebra.Vector <float> vec,
        MathNet.Numerics.LinearAlgebra.Vector <float> sub)
    {
        for (int i = 0; i < sub.Count; i++)  // TODO: test performance
        {
            vec.At(i, vec.At(i) + sub.At(i));
        }

        return(vec);
    }
    public void Rescale()
    {
        Center();
        Matrix <double> A     = PositionMatrix();
        Matrix <double> cov   = 1.0f / ((float)A.RowCount) * A.Transpose() * A;
        Evd <double>    eigen = cov.Evd();

        MathNet.Numerics.LinearAlgebra.Vector <System.Numerics.Complex> eigenvals = eigen.EigenValues;
        double l1 = eigenvals[0].Real; //1 / Math.Sqrt(eigenvals[0].Real);
        double l2 = eigenvals[1].Real; //1 / Math.Sqrt(eigenvals[1].Real);
        double l3 = eigenvals[2].Real; // / Math.Sqrt(eigenvals[2].Real);

        Debug.Log("l1: " + l1 + ", l2: " + l2 + ", l3: " + l3);
        double vol = l1 * l2 * l3;
        double max = eigenvals.AbsoluteMaximum().Real;

        Debug.Log("max=" + max);
        //double det = cov.Determinant();

        A = A / Math.Sqrt(max) * 0.2;
        Debug.Log(A);

        //Debug.Log("determinant:");
        for (int i = 0; i < A.RowCount; i++)
        {
            poses_[i].Translation = new Vector3((float)A[i, 0], (float)A[i, 1], (float)A[i, 2]);
        }



        /* Matrix<double> A = PositionMatrix();
         * Matrix<double> cov = 1.0f / ((float)A.RowCount ) *A.Transpose() * A;
         *
         *
         * Debug.Log(cov.ToString());
         * Evd<double> eigen = cov.Evd();
         * Matrix<double> m = eigen.EigenVectors;
         * Matrix<double> points = m * A * m.Inverse();
         *
         * points = points * cov.Determinant() / 10;
         * points = m * points * m.Inverse();
         * for (int i = 0; i < points.RowCount; i++)
         * {
         *   poses_[i].Translation =new Vector3((float)points[i, 0], (float)points[i, 1], (float)points[i, 2]);
         * }*/
        /*double det = cov.Determinant();
         * cov_rotated = cov_rotated / det;
         * Matrix<double> cov_recovered = m * cov_rotated * m.Inverse();*/
        //Debug.Log(cov_recovered.ToString());
    }
 /// <summary>
 /// Outer product of this and another vector.
 /// </summary>
 /// <param name="v">The vector to operate on.</param>
 /// <returns>
 /// Matrix M[i,j] = this[i] * v[j].
 /// </returns>
 /// <seealso cref="OuterProduct(Vector{T}, Vector{T})"/>
 public Matrix <T> OuterProduct(Vector <T> v)
 {
     return(OuterProduct(this, v));
 }
 /// <summary>
 /// Adds another vector to this vector and stores the result into the result vector.
 /// </summary>
 /// <param name="other">The vector to add to this one.</param>
 /// <param name="result">The vector to store the result of the addition.</param>
 protected abstract void DoAdd(Vector <T> other, Vector <T> result);
 /// <summary>
 /// Adds a scalar to each element of the vector and stores the result in the result vector.
 /// </summary>
 /// <param name="scalar">The scalar to add.</param>
 /// <param name="result">The vector to store the result of the addition.</param>
 protected abstract void DoAdd(T scalar, Vector <T> result);
 /// <summary>
 /// Complex conjugates vector and save result to <paramref name="result"/>
 /// </summary>
 /// <param name="result">Target vector</param>
 protected abstract void DoConjugate(Vector <T> result);
 /// <summary>
 /// Negates vector and save result to <paramref name="result"/>
 /// </summary>
 /// <param name="result">Target vector</param>
 protected abstract void DoNegate(Vector <T> result);
 /// <summary>
 /// Computes the dot product between this vector and another vector.
 /// </summary>
 /// <param name="other">The other vector.</param>
 /// <returns>The sum of a[i]*b[i] for all i.</returns>
 protected abstract T DoDotProduct(Vector <T> other);
 /// <summary>
 /// Pointwise multiplies this vector with another vector and stores the result into the result vector.
 /// </summary>
 /// <param name="other">The vector to pointwise multiply with this one.</param>
 /// <param name="result">The vector to store the result of the pointwise multiplication.</param>
 protected abstract void DoPointwiseMultiply(Vector <T> other, Vector <T> result);
 /// <summary>
 /// Computes the modulus for the given dividend for each element of the vector.
 /// </summary>
 /// <param name="dividend">The scalar numerator to use.</param>
 /// <param name="result">A vector to store the results in.</param>
 protected abstract void DoModulusByThis(T dividend, Vector <T> result);
 /// <summary>
 /// Computes the modulus for each element of the vector for the given divisor.
 /// </summary>
 /// <param name="divisor">The scalar denominator to use.</param>
 /// <param name="result">A vector to store the results in.</param>
 protected abstract void DoModulus(T divisor, Vector <T> result);
 /// <summary>
 /// Divides a scalar by each element of the vector and stores the result in the result vector.
 /// </summary>
 /// <param name="dividend">The scalar numerator to use.</param>
 /// <param name="result">The vector to store the result of the division.</param>
 protected abstract void DoDivideByThis(T dividend, Vector <T> result);
 /// <summary>
 /// Divides each element of the vector by a scalar and stores the result in the result vector.
 /// </summary>
 /// <param name="divisor">The scalar denominator to use.</param>
 /// <param name="result">The vector to store the result of the division.</param>
 protected abstract void DoDivide(T divisor, Vector <T> result);
 /// <summary>
 /// Computes the dot product between the conjugate of this vector and another vector.
 /// </summary>
 /// <param name="other">The other vector.</param>
 /// <returns>The sum of conj(a[i])*b[i] for all i.</returns>
 protected abstract T DoConjugateDotProduct(Vector <T> other);
 /// <summary>
 /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
 /// </summary>
 /// <param name="scalar">The scalar to subtract.</param>
 /// <param name="result">The vector to store the result of the subtraction.</param>
 protected abstract void DoSubtract(T scalar, Vector <T> result);
 /// <summary>
 /// Pointwise divide this vector with another vector and stores the result into the result vector.
 /// </summary>
 /// <param name="divisor">The pointwise denominator vector to use.</param>
 /// <param name="result">The result of the division.</param>
 protected abstract void DoPointwiseDivide(Vector <T> divisor, Vector <T> result);
 /// <summary>
 /// Pointwise modulus this vector with another vector and stores the result into the result vector.
 /// </summary>
 /// <param name="divisor">The pointwise denominator vector to use.</param>
 /// <param name="result">The result of the modulus.</param>
 protected abstract void DoPointwiseModulus(Vector <T> divisor, Vector <T> result);
Exemple #18
0
 public double DistanceTo(MathNet.Numerics.LinearAlgebra.Vector x)
 {
     return(Math.Abs(_plane.SignedDistanceTo(x)));
 }
 /// <summary>
 /// Multiplies a scalar to each element of the vector and stores the result in the result vector.
 /// </summary>
 /// <param name="scalar">The scalar to multiply.</param>
 /// <param name="result">The vector to store the result of the multiplication.</param>
 protected abstract void DoMultiply(T scalar, Vector <T> result);