Exemple #1
0
        public static Blade InnerProduct(Basis e1, Basis e2)
        {
            int hashPair = Basis.GetHashPair(e1, e2);

            if (innerProductCache.ContainsKey(hashPair))
            {
                return(innerProductCache[hashPair]);
            }

            Blade result;

            if (e1.IsNullMetric || e2.IsNullMetric)
            {
                MultiVector m1 = e1.ToMinkowskiMetric();
                MultiVector m2 = e2.ToMinkowskiMetric();

                result = (Blade)MultiVector.InnerProduct(m1, m2).ToNullMetric();
            }
            else
            {
                if ((e1.bitMask & ~e2.bitMask) == 0)
                {
                    result = (Blade)(e1 * e2);
                }
                else
                {
                    result = Blade.Zero;
                }
            }

            innerProductCache.Add(hashPair, result);

            return(result);
        }
Exemple #2
0
        public static void GetPointPairParams(MultiVector obj, out MultiVector p1, out MultiVector p2)
        {
            if (!obj.ContainsOnly(3))
            {
                throw new InvalidEntityException();
            }

            obj = obj.Dual;

            double delta = Math.Sqrt(Math.Abs((double)MultiVector.InnerProduct(obj, obj)));

            try
            {
                MultiVector temp = MultiVector.InnerProduct(Basis.E8, obj);
                p1 = (+delta + obj) / temp;
                p2 = (-delta + obj) / temp;
            }
            catch (InvalidOperationException)
            {
                throw new InvalidEntityException();
            }
        }
Exemple #3
0
        public static GeometricEntity GetGeometricEntity(MultiVector obj)
        {
            if (obj.ContainsOnly(0))
            {
                return(GeometricEntity.Scalar);
            }

            if (obj.ContainsOnly(1))
            {
                if (obj.E0 == 0 && obj.E8 == 0)
                {
                    return(GeometricEntity.Vector);
                }

                if (obj.E0 == 0)
                {
                    return(GeometricEntity.Plane);
                }

                MultiVector center; double radius;
                GetSphereParams(obj, out center, out radius);

                if (radius == 0)
                {
                    return(GeometricEntity.Point);
                }

                return(GeometricEntity.Sphere);
            }

            if (obj.ContainsOnly(2))
            {
                if (obj.ContainsOnly(Basis.E12, Basis.E13, Basis.E23))
                {
                    return(GeometricEntity.Bivector);
                }

                if (MultiVector.InnerProduct(Basis.E8, obj) == 0.0)
                {
                    return(GeometricEntity.Line);
                }

                return(GeometricEntity.Circle);
            }

            if (obj.ContainsOnly(3))
            {
                if (obj.ContainsOnly(Basis.E123))
                {
                    return(GeometricEntity.Trivector);
                }

                try
                {
                    MultiVector p1, p2;
                    GetPointPairParams(obj, out p1, out p2);

                    return(GeometricEntity.PointPair);
                }
                catch (InvalidEntityException)
                {
                    return(GeometricEntity.Unknown);
                }
            }

            return(GeometricEntity.Unknown);
        }