Ejemplo n.º 1
0
    public ShapeMatching(GameObject points)
    {
        //Instantiation method for shapematching object

        //Stores duplicates of points passed in to object as an array of original positions to be used in calculation
        particles = points;
        Transform [] original_transforms = particles.GetComponentsInChildren <Transform>();
        original_positions = new Vector3[original_transforms.Length - 1];
        for (int i = 1; i < original_transforms.Length; i++)         //i starts at one in order to avoid origin being added to positions
        {
            original_positions[i - 1] = particles.transform.InverseTransformPoint(original_transforms[i].position);
            cm0 += original_positions[i - 1];
        }
        cm0 /= original_positions.Length;

        //Precalculates Aqq from original positions
        aqq = new double [, ] {
            { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
        };
        for (int i = 0; i < original_positions.Length; i++)
        {
            original_positions[i] -= cm0;
            MatrixFunctions.matrix_add_3x3(ref aqq, MatrixFunctions.vector3_covariance(original_positions[i], original_positions[i]));
        }


        //performs inverse operation on Aqq matrix as stated in Muller paper
        MatrixFunctions.matrixInverse3x3(ref aqq);
    }