Example #1
0
        /// <returns>true if the basis blade scales of A and B match. Blades which are not present in both A and B are ignored</returns>
        public static bool BasisBladeScalesMatch(MV A, MV B)
        {
            if (A == null)
            {
                Console.WriteLine("Arrr!");
            }
            if (B == null)
            {
                Console.WriteLine("Arrr!");
            }
            Dictionary <Tuple <int, int>, Tuple <int, int> > D = GetCoordMap(A, B);

            foreach (KeyValuePair <Tuple <int, int>, Tuple <int, int> > kvp in D)
            {
                BasisBlade a = A.Group(kvp.Key.Value1)[kvp.Key.Value2];
                BasisBlade b = B.Group(kvp.Value.Value1)[kvp.Value.Value2];

                if (a.scale != b.scale)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Transforms <paramref name="A"/> to the metric basis (<paramref name="A"/> must be on eigenbasis).
        /// </summary>
        /// <param name="A">The list of BasisBlades (must be on the orthogonal 'eigen' basis).</param>
        /// <returns><paramref name="A"/> on the new basis.</returns>
        public ArrayList ToMetricBasis(ArrayList A)
        {
            ArrayList result = new ArrayList();

            for (int i = 0; i < A.Count; i++)
            {
                ArrayList tmp = ToMetricBasis((BasisBlade)A[i]);
                result.AddRange(tmp);
            }
            return(BasisBlade.Simplify(result));
        }
Example #3
0
        public BasisBlade AbsoluteLargestConstantBasisBlade()
        {
            double     maxValue = -1.0;
            BasisBlade B        = null;

            for (int c = 0; c < NbConstBasisBlade; c++)
            {
                if (Math.Abs(ConstBasisBlade(c).scale) > maxValue)
                {
                    maxValue = Math.Abs(ConstBasisBlade(c).scale);
                    B        = ConstBasisBlade(c);
                }
            }
            return(B);
        }
Example #4
0
        /// <summary>
        ///  Transforms a basis blade to another basis which is represented by the columns of M.
        /// </summary>
        /// <param name="a">The basis blade to transform according to <paramref name="M"/>.</param>
        /// <param name="M">The matrix to use to transform <paramref name="a"/>.</param>
        /// <returns>a list of BasisBlade whose sum represents <paramref name="a"/> on the new basis.</returns>
        public static ArrayList Transform(BasisBlade a, DotNetMatrix.GeneralMatrix M)
        {
            ArrayList A = new ArrayList();

            A.Add(new BasisBlade(0, a.scale, a.symScale)); // start with just the scalar part;

            int dim = M.RowDimension;

            // for each 1 bit: convert to list of blades
            int  i = 0;
            uint b = a.bitmap;

            while (b != 0)
            {
                if ((b & 1) != 0)
                {
                    // take column 'i' out of the matrix, wedge it to 'A'
                    ArrayList tmp = new ArrayList();
                    for (int j = 0; j < dim; j++)
                    {
                        double m = M.GetElement(j, i);
                        if (m != 0.0)
                        {
                            for (int k = 0; k < A.Count; k++)
                            {
                                BasisBlade o = BasisBlade.op((BasisBlade)A[k], new BasisBlade((uint)(1 << j), m));
                                if (o.scale != 0.0)
                                {
                                    tmp.Add(o);
                                }
                            }
                        }
                    }
                    A = tmp;
                }
                b >>= 1;
                i++;
            }
            return(A);
        }
Example #5
0
        public Metric RoundEigenMetric(double roundingEpsilon)
        {
            double[] newEigenMetric = (double[])m_eigenMetric.Clone();
            bool     changed        = false;

            for (int i = 0; i < newEigenMetric.Length; i++)
            {
                double r = BasisBlade.Round(roundingEpsilon, newEigenMetric[i]);
                if (r != newEigenMetric[i])
                {
                    newEigenMetric[i] = r;
                    changed           = true;
                }
            }

            if (changed)
            {
                return(new Metric(m_matrix, m_eig, newEigenMetric, m_invEigMatrix, m_isDiagonal, m_isEuclidean, m_isAntiEuclidean));
            }
            else
            {
                return(this);
            }
        }
Example #6
0
 private void sum(BasisBlade bb)
 {
     int idx = c3ga.BasisElementIndexByBitmap[bb.getBitmap()];
     coord[idx] += bb.getScale() / (float)c3ga.BasisElementSignByIndex[idx];
 }
Example #7
0
        private mv Parse()
        {
            int token;
            bool firstLoop = true;

            // get the first token
            token = getNextToken();

            while (true) {
                // reset for next basis blade
                BasisBlade bb = new BasisBlade();
                bool beDone = false; // basis element done

                if (token == T_END_OF_STRING) break;

                int cnt = 0;
                while ((token == T_PLUS) || (token == T_MINUS)) { // accept all +-
                    cnt++;
                    startIdx = endIdx+1;
                    if (token == T_MINUS) bb.multiply(-1.0f); // -
                    token = getNextToken();
                }

                // require at least one +- if this is not the first term:
                if ((!firstLoop) && (cnt == 0)) {
                    throw GetException("Expected '+' or '-'");
                }

                if ((token == T_NUMBER) ||
                    ((token >= T_FIRST_BASIS_VECTOR) && (token <= T_LAST_BASIS_VECTOR))) // must be number or basis vector
                {
                    if (token == T_NUMBER) {
                        { // multiply scale with value of number
                            try {
                                bb.multiply((float)Double.Parse(substring(startIdx, endIdx)));
                            } catch (Exception ) {
                                throw GetException("Cannot parse number");
                            }
                        }
                        startIdx = endIdx+1;

                        // * or ^ ?
                        token = getNextToken();
                        if ((token == T_WEDGE) || (token == T_MUL)) {
                            startIdx = endIdx+1;

                            // must find basis vector
                            token = getNextToken();
                        }
                        else { // just a single scalar is OK
                            startIdx = endIdx+1;
                            beDone = true;
                        }

                    }

                    if (!beDone) {
                        if ((token >= T_FIRST_BASIS_VECTOR) && (token <= T_LAST_BASIS_VECTOR)) {
                            int bvIdx = token - T_FIRST_BASIS_VECTOR;
                            bb.wedgeBasisVector(bvIdx);
                            startIdx = endIdx+1;
                        }
                        else {
                            throw GetException("Expected basis vector");
                        }
                    }

                    if (!beDone) {
                        // accept ^ basis vector as many times as it takes
                        while (true) {
                            // ^
                            token = getNextToken();
                            if (token != T_WEDGE) break;
                            startIdx = endIdx+1;

                            // basis vector
                            token = getNextToken();
                            if ((token >= T_FIRST_BASIS_VECTOR) && (token <= T_LAST_BASIS_VECTOR)) {
                                int bvIdx = token - T_FIRST_BASIS_VECTOR;
                                bb.wedgeBasisVector(bvIdx);
                                startIdx = endIdx+1;
                            }
                            else {
                                throw GetException("Expected basis vector");
                            }

                        }

                    }
                } // end of 'if number or bv'
                else if (token == T_BAD_CHARACTER) {
                    throw GetException("Bad character");
                }
                else if (token == T_BAD_NUMBER) {
                    throw GetException("Bad number");
                }
                else if (token == T_BAD_IDENTIFIER) {
                    throw GetException("Bad identifier");
                }
                else {
                    throw GetException("Unexpected token");
                }

                // add
                sum(bb);

                // remember that the first loop is done
                firstLoop = false;
            }

            mv result = new mv(GroupBitmap.GRADE_0 | GroupBitmap.GRADE_1 | GroupBitmap.GRADE_2 | GroupBitmap.GRADE_3 | GroupBitmap.GRADE_4 | GroupBitmap.GRADE_5 | 0,  coord);
            result.Compress(0.0f);
            return result;
        }
Example #8
0
 /// <summary>
 /// Transforms BasisBlade <paramref name="a"/> to the regular basis of this metric.
 /// </summary>
 /// <param name="a">The BasisBlade (must be on the orthogonal 'eigen' basis).</param>
 /// <returns><paramref name="a"/> on the new basis.</returns>
 public ArrayList ToMetricBasis(BasisBlade a)
 {
     return(Transform(a, m_eig.GetV()));
 }
Example #9
0
 /// <summary>
 /// Transforms BasisBlade <paramref name="a"/> to the orthogonal basis of this metric.
 /// </summary>
 /// <param name="a">The BasisBlade (must be on the regular basis).</param>
 /// <returns><paramref name="a"/> on the new basis.</returns>
 public ArrayList ToEigenbasis(BasisBlade a)
 {
     return(Transform(a, m_invEigMatrix));
 }
Example #10
0
        private mv Parse()
        {
            int  token;
            bool firstLoop = true;

            // get the first token
            token = getNextToken();

            while (true)
            {
                // reset for next basis blade
                BasisBlade bb     = new BasisBlade();
                bool       beDone = false;           // basis element done

                if (token == T_END_OF_STRING)
                {
                    break;
                }

                int cnt = 0;
                while ((token == T_PLUS) || (token == T_MINUS))                   // accept all +-
                {
                    cnt++;
                    startIdx = endIdx + 1;
                    if (token == T_MINUS)
                    {
                        bb.multiply(-1.0f);                                       // -
                    }
                    token = getNextToken();
                }

                // require at least one +- if this is not the first term:
                if ((!firstLoop) && (cnt == 0))
                {
                    throw GetException("Expected '+' or '-'");
                }

                if ((token == T_NUMBER) ||
                    ((token >= T_FIRST_BASIS_VECTOR) && (token <= T_LAST_BASIS_VECTOR)))                     // must be number or basis vector
                {
                    if (token == T_NUMBER)
                    {
                        {                         // multiply scale with value of number
                            try {
                                bb.multiply((float)Double.Parse(substring(startIdx, endIdx)));
                            } catch (Exception) {
                                throw GetException("Cannot parse number");
                            }
                        }
                        startIdx = endIdx + 1;

                        // * or ^ ?
                        token = getNextToken();
                        if ((token == T_WEDGE) || (token == T_MUL))
                        {
                            startIdx = endIdx + 1;

                            // must find basis vector
                            token = getNextToken();
                        }
                        else                           // just a single scalar is OK
                        {
                            startIdx = endIdx + 1;
                            beDone   = true;
                        }
                    }

                    if (!beDone)
                    {
                        if ((token >= T_FIRST_BASIS_VECTOR) && (token <= T_LAST_BASIS_VECTOR))
                        {
                            int bvIdx = token - T_FIRST_BASIS_VECTOR;
                            bb.wedgeBasisVector(bvIdx);
                            startIdx = endIdx + 1;
                        }
                        else
                        {
                            throw GetException("Expected basis vector");
                        }
                    }

                    if (!beDone)
                    {
                        // accept ^ basis vector as many times as it takes
                        while (true)
                        {
                            // ^
                            token = getNextToken();
                            if (token != T_WEDGE)
                            {
                                break;
                            }
                            startIdx = endIdx + 1;

                            // basis vector
                            token = getNextToken();
                            if ((token >= T_FIRST_BASIS_VECTOR) && (token <= T_LAST_BASIS_VECTOR))
                            {
                                int bvIdx = token - T_FIRST_BASIS_VECTOR;
                                bb.wedgeBasisVector(bvIdx);
                                startIdx = endIdx + 1;
                            }
                            else
                            {
                                throw GetException("Expected basis vector");
                            }
                        }
                    }
                }                 // end of 'if number or bv'
                else if (token == T_BAD_CHARACTER)
                {
                    throw GetException("Bad character");
                }
                else if (token == T_BAD_NUMBER)
                {
                    throw GetException("Bad number");
                }
                else if (token == T_BAD_IDENTIFIER)
                {
                    throw GetException("Bad identifier");
                }
                else
                {
                    throw GetException("Unexpected token");
                }

                // add
                sum(bb);

                // remember that the first loop is done
                firstLoop = false;
            }


            mv result = new mv(GroupBitmap.GRADE_0 | GroupBitmap.GRADE_1 | GroupBitmap.GRADE_2 | GroupBitmap.GRADE_3 | GroupBitmap.GRADE_4 | GroupBitmap.GRADE_5 | 0, coord);

            result.Compress(0.0f);
            return(result);
        } // end of Parse()
Example #11
0
        private void sum(BasisBlade bb)
        {
            int idx = c3ga.BasisElementIndexByBitmap[bb.getBitmap()];

            coord[idx] += bb.getScale() / (float)c3ga.BasisElementSignByIndex[idx];
        }