Beispiel #1
0
        private static Matrix Sum(TokenType left, TokenType right, bool negative)
        {
            Matrix l   = left as Matrix;
            Matrix r   = right as Matrix;
            Matrix ret = Matrix.CreateUnsafeMatrix(l.rows, l.columns);

            if (l.rows != r.rows || l.columns != r.columns)
            {
                throw new ExprCoreException("행과 열이 다른 행렬은 더할 수 없습니다.");
            }

            for (int i = 0; i < l.rows; i++)
            {
                for (int j = 0; j < l.columns; j++)
                {
                    TokenType lParam = l.data[i, j];
                    TokenType rParam = r.data[i, j];
                    if (lParam is Fraction && rParam is Fraction)
                    {
                        ret.data[i, j] = negative ? FractionOperators.Subtract(lParam, rParam) : FractionOperators.Add(lParam, rParam);
                    }
                    else
                    {
                        throw new ExprCoreException("상수인 행렬만 더할 수 있습니다.");
                    }
                }
            }

            return(ret);
        }
Beispiel #2
0
        public static Vec2 Subtract(TokenType left, TokenType right)
        {
            Vec2 l = left as Vec2;
            Vec2 r = right as Vec2;

            Vector.CheckNumberic(l, r);
            return(new Vec2(FractionOperators.Subtract(l.X, r.X), FractionOperators.Subtract(l.Y, r.Y)));
        }
Beispiel #3
0
        public static Vec3 Cross(TokenType left, TokenType right)
        {
            Vec3 l = left as Vec3;
            Vec3 r = right as Vec3;

            Vector.CheckNumberic(r);

            Fraction x = FractionOperators.Subtract(FractionOperators.Multiply(l.Y, r.Z), FractionOperators.Multiply(l.Z, r.Y));
            Fraction y = FractionOperators.Subtract(FractionOperators.Multiply(l.Z, r.X), FractionOperators.Multiply(l.X, r.Z));
            Fraction z = FractionOperators.Subtract(FractionOperators.Multiply(l.X, r.Y), FractionOperators.Multiply(l.Y, r.X));

            return(new Vec3(x, y, z));
        }