Ejemplo n.º 1
0
        public static void GetLineParams(MultiVector obj, out MultiVector t, out MultiVector d)
        {
            if (!obj.ContainsOnly(2))
            {
                throw new InvalidEntityException();
            }

            d = MultiVector.Vector(
                -obj[Basis.E23],
                obj[Basis.E13],
                -obj[Basis.E12]);

            double norm = d.Length;

            if (norm == 0.0)
            {
                throw new InvalidEntityException();
            }

            d /= norm;

            // d cross t
            MultiVector dct = MultiVector.Vector(
                obj[Basis.E1 ^ Basis.E8],
                obj[Basis.E2 ^ Basis.E8],
                obj[Basis.E3 ^ Basis.E8]) / norm;

            t = MultiVector.CrossProduct(dct, d);
        }
Ejemplo n.º 2
0
        public static void GetPlaneParams(MultiVector obj, out MultiVector n, out double d)
        {
            if (!obj.ContainsOnly(1) || obj.E0 != 0.0)
            {
                throw new InvalidEntityException();
            }

            n = MultiVector.Vector(obj.E1, obj.E2, obj.E3);

            double norm = n.Length;

            n /= norm;
            d  = obj.E8 / norm;
        }
Ejemplo n.º 3
0
        public static void GetSphereParams(MultiVector obj, out MultiVector c, out double r)
        {
            if (!obj.ContainsOnly(1) || obj.E0 == 0.0)
            {
                throw new InvalidEntityException();
            }

            obj /= obj.E0;
            c    = MultiVector.Vector(obj.E1, obj.E2, obj.E3);
            r    = Math.Sqrt(Math.Abs(2 * obj.E8 - (double)MultiVector.ScalarProduct(c, c)));

            // HACK
            if (Math.Abs(r) < 1E-3)
            {
                r = 0.0;
            }
        }
Ejemplo n.º 4
0
        public static void GetCircleParams(MultiVector obj, out MultiVector n, out MultiVector c, out double r)
        {
            if (!obj.ContainsOnly(2))
            {
                throw new InvalidEntityException();
            }

            // c cross n
            MultiVector ccd = MultiVector.Vector(
                -obj[Basis.E23],
                obj[Basis.E13],
                -obj[Basis.E12]);

            // c dot n
            double d = obj[Basis.EPLANE];

            n = MultiVector.Vector(
                obj[Basis.E1 ^ Basis.E0],
                obj[Basis.E2 ^ Basis.E0],
                obj[Basis.E3 ^ Basis.E0]);

            c  = MultiVector.CrossProduct(n, ccd) + n * d;
            c /= (double)MultiVector.ScalarProduct(n, n);

            double x;

            if (n.E1 != 0)
            {
                x = (obj[Basis.E1 ^ Basis.E8] + (double)d * c.E1) / n.E1;
            }
            else if (n.E2 != 0)
            {
                x = (obj[Basis.E2 ^ Basis.E8] + (double)d * c.E2) / n.E2;
            }
            else if (n.E3 != 0)
            {
                x = (obj[Basis.E3 ^ Basis.E8] + (double)d * c.E3) / n.E3;
            }
            else
            {
                throw new InvalidEntityException();
            }

            r  = Math.Sqrt((double)MultiVector.ScalarProduct(c, c) - 2 * x);
            n /= n.Length;
        }
Ejemplo n.º 5
0
        public static MultiVector CreatePoint(double e1, double e2, double e3)
        {
            MultiVector v = MultiVector.Vector(e1, e2, e3);

            return(v + 0.5 * MultiVector.ScalarProduct(v, v) * Basis.E8 + Basis.E0);
        }