Beispiel #1
0
        double Orient3DExact_ScaledChecked(double[] pa, double[] pb, double[] pc, double[] pd, double scale = 1.0)
        {
            double axby1, bxcy1, cxdy1, dxay1, axcy1, bxdy1;
            double bxay1, cxby1, dxcy1, axdy1, cxay1, dxby1;
            double axby0, bxcy0, cxdy0, dxay0, axcy0, bxdy0;
            double bxay0, cxby0, dxcy0, axdy0, cxay0, dxby0;

            double[] ab    = new double[4];
            double[] bc    = new double[4];
            double[] cd    = new double[4];
            double[] da    = new double[4];
            double[] ac    = new double[4];
            double[] bd    = new double[4];
            double[] temp8 = new double[8];
            int      templen;

            double[] abc = new double[12];
            double[] bcd = new double[12];
            double[] cda = new double[12];
            double[] dab = new double[12];

            int abclen, bcdlen, cdalen, dablen;

            double[] adet = new double[24];
            double[] bdet = new double[24];
            double[] cdet = new double[24];
            double[] ddet = new double[24];

            int alen, blen, clen, dlen;

            double[] abdet = new double[48];
            double[] cddet = new double[48];
            int      ablen, cdlen;

            double[] deter = new double[96];
            int      deterlen;

            int i;

            ProductTests.TwoProduct_Checked(pa[0], pb[1], out axby1, out axby0);
            ProductTests.TwoProduct_Checked(pb[0], pa[1], out bxay1, out bxay0);
            SumTests.TwoTwoDiff_Checked(axby1, axby0, bxay1, bxay0, out ab[3], out ab[2], out ab[1], out ab[0]); // ab

            ProductTests.TwoProduct_Checked(pb[0], pc[1], out bxcy1, out bxcy0);
            ProductTests.TwoProduct_Checked(pc[0], pb[1], out cxby1, out cxby0);
            SumTests.TwoTwoDiff_Checked(bxcy1, bxcy0, cxby1, cxby0, out bc[3], out bc[2], out bc[1], out bc[0]); // bc

            ProductTests.TwoProduct_Checked(pc[0], pd[1], out cxdy1, out cxdy0);
            ProductTests.TwoProduct_Checked(pd[0], pc[1], out dxcy1, out dxcy0);
            SumTests.TwoTwoDiff_Checked(cxdy1, cxdy0, dxcy1, dxcy0, out cd[3], out cd[2], out cd[1], out cd[0]); // cd

            ProductTests.TwoProduct_Checked(pd[0], pa[1], out dxay1, out dxay0);
            ProductTests.TwoProduct_Checked(pa[0], pd[1], out axdy1, out axdy0);
            SumTests.TwoTwoDiff_Checked(dxay1, dxay0, axdy1, axdy0, out da[3], out da[2], out da[1], out da[0]); // da

            ProductTests.TwoProduct_Checked(pa[0], pc[1], out axcy1, out axcy0);
            ProductTests.TwoProduct_Checked(pc[0], pa[1], out cxay1, out cxay0);
            SumTests.TwoTwoDiff_Checked(axcy1, axcy0, cxay1, cxay0, out ac[3], out ac[2], out ac[1], out ac[0]); // ac

            ProductTests.TwoProduct_Checked(pb[0], pd[1], out bxdy1, out bxdy0);
            ProductTests.TwoProduct_Checked(pd[0], pb[1], out dxby1, out dxby0);
            SumTests.TwoTwoDiff_Checked(bxdy1, bxdy0, dxby1, dxby0, out bd[3], out bd[2], out bd[1], out bd[0]); // bd

            Debug.Print("Start CD");
            Debug.Print((pc[0] / scale).ToString());
            Debug.Print((pc[1] / scale).ToString());
            Debug.Print((pd[0] / scale).ToString());
            Debug.Print((pd[1] / scale).ToString());
            Debug.Print((cxdy0 / scale).ToString());
            Debug.Print((cxdy1 / scale).ToString());
            Debug.Print((dxcy0 / scale).ToString());
            Debug.Print((dxcy1 / scale).ToString());
            cd.Print(4, scale);
            Debug.Print("End CD");

            da.Print(4, scale);
            ac.Print(4, scale);

            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, cd, 4, da, temp8);
            cdalen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, ac, cda);          // cda
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, da, 4, ab, temp8);
            dablen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, bd, dab);          // dab
            for (i = 0; i < 4; i++)
            {
                bd[i] = -bd[i];
                ac[i] = -ac[i];
            }
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, ab, 4, bc, temp8);
            abclen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, ac, abc);          // abc
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, bc, 4, cd, temp8);
            bcdlen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, bd, bcd);          // bcd

            cda.Print(cdalen, scale);
            dab.Print(dablen, scale);
            abc.Print(abclen, scale);
            bcd.Print(bcdlen, scale);

            alen = ProductTests.ScaleExpansionZeroElim_Checked(bcdlen, bcd, pa[2], adet);
            blen = ProductTests.ScaleExpansionZeroElim_Checked(cdalen, cda, -pb[2], bdet);
            clen = ProductTests.ScaleExpansionZeroElim_Checked(dablen, dab, pc[2], cdet);
            dlen = ProductTests.ScaleExpansionZeroElim_Checked(abclen, abc, -pd[2], ddet);

            adet.Print(alen, scale);
            bdet.Print(blen, scale);
            cdet.Print(clen, scale);
            ddet.Print(dlen, scale);

            ablen    = ExpansionTests.FastExpansionSumZeroElim_Checked(alen, adet, blen, bdet, abdet);
            cdlen    = ExpansionTests.FastExpansionSumZeroElim_Checked(clen, cdet, dlen, ddet, cddet);
            deterlen = ExpansionTests.FastExpansionSumZeroElim_Checked(ablen, abdet, cdlen, cddet, deter);

            deter.Print(deterlen, scale);
            return(deter[deterlen - 1]);
        }
Beispiel #2
0
        double Orient3DExact_Checked2(double[] pa, double[] pb, double[] pc, double[] pd, bool test = false)
        {
            double axby1, bxcy1, cxdy1, dxay1, axcy1, bxdy1;
            double bxay1, cxby1, dxcy1, axdy1, cxay1, dxby1;
            double axby0, bxcy0, cxdy0, dxay0, axcy0, bxdy0;
            double bxay0, cxby0, dxcy0, axdy0, cxay0, dxby0;

            double[] ab    = new double[4];
            double[] bc    = new double[4];
            double[] cb    = new double[4]; // for test
            double[] cd    = new double[4];
            double[] da    = new double[4];
            double[] ad    = new double[4]; // for test
            double[] ac    = new double[4];
            double[] bd    = new double[4];
            double[] temp8 = new double[8];
            int      templen;

            double[] abc = new double[12];
            double[] bcd = new double[12];
            double[] cda = new double[12];
            double[] dab = new double[12];
            double[] abd = new double[12];
            double[] acd = new double[12];
            double[] acb = new double[12];
            double[] cbd = new double[12];
            int      abclen, bcdlen, cdalen, dablen;
            int      acblen, cbdlen, abdlen, acdlen;

            double[] adet = new double[24];
            double[] bdet = new double[24];
            double[] cdet = new double[24];
            double[] ddet = new double[24];
            double[] a2det = new double[24];
            double[] b2det = new double[24];
            double[] c2det = new double[24];
            double[] d2det = new double[24];
            int      alen, blen, clen, dlen;
            int      a2len, b2len, c2len, d2len;

            double[] abdet = new double[48];
            double[] cddet = new double[48];
            int      ablen, cdlen;

            double[] ab2det = new double[48];
            double[] cd2det = new double[48];
            int      ab2len, cd2len;

            double[] ac2det = new double[48];
            double[] bd2det = new double[48];
            int      ac2len, bd2len;

            double[] deter = new double[96];
            int      deterlen;

            double[] deter2 = new double[96];
            int      deter2len;

            double[] deter3 = new double[96];
            int      deter3len;
            int      i;

            ProductTests.TwoProduct_Checked(pa[0], pb[1], out axby1, out axby0);
            ProductTests.TwoProduct_Checked(pb[0], pa[1], out bxay1, out bxay0);
            SumTests.TwoTwoDiff_Checked(axby1, axby0, bxay1, bxay0, out ab[3], out ab[2], out ab[1], out ab[0]); // ab

            ProductTests.TwoProduct_Checked(pb[0], pc[1], out bxcy1, out bxcy0);
            ProductTests.TwoProduct_Checked(pc[0], pb[1], out cxby1, out cxby0);
            SumTests.TwoTwoDiff_Checked(bxcy1, bxcy0, cxby1, cxby0, out bc[3], out bc[2], out bc[1], out bc[0]); // bc

            ProductTests.TwoProduct_Checked(pc[0], pb[1], out cxby1, out cxby0);
            ProductTests.TwoProduct_Checked(pb[0], pc[1], out bxcy1, out bxcy0);
            SumTests.TwoTwoDiff_Checked(cxby1, cxby0, bxcy1, bxcy0, out cb[3], out cb[2], out cb[1], out cb[0]); // cb

            ProductTests.TwoProduct_Checked(pc[0], pd[1], out cxdy1, out cxdy0);
            ProductTests.TwoProduct_Checked(pd[0], pc[1], out dxcy1, out dxcy0);
            SumTests.TwoTwoDiff_Checked(cxdy1, cxdy0, dxcy1, dxcy0, out cd[3], out cd[2], out cd[1], out cd[0]); // cd

            ProductTests.TwoProduct_Checked(pd[0], pa[1], out dxay1, out dxay0);
            ProductTests.TwoProduct_Checked(pa[0], pd[1], out axdy1, out axdy0);
            SumTests.TwoTwoDiff_Checked(dxay1, dxay0, axdy1, axdy0, out da[3], out da[2], out da[1], out da[0]); // da

            ProductTests.TwoProduct_Checked(pa[0], pd[1], out axdy1, out axdy0);
            ProductTests.TwoProduct_Checked(pd[0], pa[1], out dxay1, out dxay0);
            SumTests.TwoTwoDiff_Checked(axdy1, axdy0, dxay1, dxay0, out ad[3], out ad[2], out ad[1], out ad[0]); // ad

            ProductTests.TwoProduct_Checked(pa[0], pc[1], out axcy1, out axcy0);
            ProductTests.TwoProduct_Checked(pc[0], pa[1], out cxay1, out cxay0);
            SumTests.TwoTwoDiff_Checked(axcy1, axcy0, cxay1, cxay0, out ac[3], out ac[2], out ac[1], out ac[0]); // ac

            ProductTests.TwoProduct_Checked(pb[0], pd[1], out bxdy1, out bxdy0);                                 // bx.dy
            ProductTests.TwoProduct_Checked(pd[0], pb[1], out dxby1, out dxby0);                                 // dx.by
            SumTests.TwoTwoDiff_Checked(bxdy1, bxdy0, dxby1, dxby0, out bd[3], out bd[2], out bd[1], out bd[0]); // bd = bx.dy - dx.by


            Assert.AreEqual(bc[3], -cb[3]);
            Assert.AreEqual(bc[2], -cb[2]);
            Assert.AreEqual(da[2], -ad[2]);
            Assert.AreEqual(da[2], -ad[2]);

            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, cd, 4, da, temp8);
            cdalen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, ac, cda);          // cda
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, da, 4, ab, temp8);
            dablen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, bd, dab);          // dab

            // Set bd = -bd
            //     ac = -ac
            for (i = 0; i < 4; i++)
            {
                bd[i] = -bd[i];
                ac[i] = -ac[i];
            }
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, ab, 4, bc, temp8);
            abclen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, ac, abc);          // abc
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, bc, 4, cd, temp8);
            bcdlen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, bd, bcd);          // bcd

            // (Re)set bd = -bd
            //         ac = -ac
            for (i = 0; i < 4; i++)
            {
                bd[i] = -bd[i];
                ac[i] = -ac[i];
            }

            //if (test)
            //{
            //    Assert.AreEqual(0.0, abc[abclen - 1]);
            //    Assert.AreEqual(0.0, bcd[bcdlen - 1]);
            //    Assert.AreEqual(dab[0], cda[0]);
            //    Assert.AreEqual(dab[1], cda[1]);
            //    Assert.AreNotEqual(pb[2], pc[2]);
            //}

            alen = ProductTests.ScaleExpansionZeroElim_Checked(bcdlen, bcd, pa[2], adet);
            blen = ProductTests.ScaleExpansionZeroElim_Checked(cdalen, cda, -pb[2], bdet);
            clen = ProductTests.ScaleExpansionZeroElim_Checked(dablen, dab, pc[2], cdet);
            dlen = ProductTests.ScaleExpansionZeroElim_Checked(abclen, abc, -pd[2], ddet);


            ablen    = ExpansionTests.FastExpansionSumZeroElim_Checked(alen, adet, blen, bdet, abdet);
            cdlen    = ExpansionTests.FastExpansionSumZeroElim_Checked(clen, cdet, dlen, ddet, cddet);
            deterlen = ExpansionTests.FastExpansionSumZeroElim_Checked(ablen, abdet, cdlen, cddet, deter);

            //////////////////
            ///////////////////////////////////

            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, bd, 4, da, temp8);
            abdlen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, ab, abd);          // abd
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, da, 4, ac, temp8);
            acdlen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, cd, acd);          // acd
            for (i = 0; i < 4; i++)
            {
                cd[i] = -cd[i];
                ab[i] = -ab[i];
            }
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, ac, 4, cb, temp8);
            acblen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, ab, acb);          // acb
            templen = ExpansionTests.FastExpansionSumZeroElim_Checked(4, cb, 4, bd, temp8);
            cbdlen  = ExpansionTests.FastExpansionSumZeroElim_Checked(templen, temp8, 4, cd, cbd);          // cbd

            Assert.IsTrue(bcd.SequenceEqual(cbd.Select(d => - d)));
            Assert.IsTrue(cda.SequenceEqual(acd));
            Assert.IsTrue(dab.SequenceEqual(abd));
            Assert.IsTrue(abc.SequenceEqual(acb.Select(d => - d)));

            //Assert.AreEqual(dab[0], bda[0]);
            //Assert.AreEqual(bcd[0], -cbd[0]);

            a2len = ProductTests.ScaleExpansionZeroElim_Checked(cbdlen, cbd, pa[2], a2det);
            c2len = ProductTests.ScaleExpansionZeroElim_Checked(abdlen, abd, -pc[2], c2det);
            b2len = ProductTests.ScaleExpansionZeroElim_Checked(acdlen, acd, pb[2], b2det);
            d2len = ProductTests.ScaleExpansionZeroElim_Checked(acblen, acb, -pd[2], d2det);

            Assert.IsTrue(adet.SequenceEqual(a2det.Select(d => - d)));
            Assert.IsTrue(bdet.SequenceEqual(b2det.Select(d => - d)));
            Assert.IsTrue(cdet.SequenceEqual(c2det.Select(d => - d)));
            Assert.IsTrue(ddet.SequenceEqual(d2det.Select(d => - d)));

            /// ///////////////

            ac2len = ExpansionTests.FastExpansionSumZeroElim_Checked(a2len, a2det, c2len, c2det, ac2det);
            bd2len = ExpansionTests.FastExpansionSumZeroElim_Checked(b2len, b2det, d2len, d2det, bd2det);

            deter2len = ExpansionTests.FastExpansionSumZeroElim_Checked(ac2len, ac2det, bd2len, bd2det, deter2);

            ab2len = ExpansionTests.FastExpansionSumZeroElim_Checked(a2len, a2det, b2len, b2det, ab2det);
            cd2len = ExpansionTests.FastExpansionSumZeroElim_Checked(c2len, c2det, d2len, d2det, cd2det);

            deter3len = ExpansionTests.FastExpansionSumZeroElim_Checked(ab2len, ab2det, cd2len, cd2det, deter3);

            Debug.Print("Before: {0:R}, {1:R}", ab2det[0], ab2det[1]);
            Debug.Print("After: {0:R}, {1:R}", deter3[0], deter3[1]);

            //Assert.AreEqual(deter2[deter2len - 1], deter3[deter3len - 1]);
            //Assert.AreEqual(deter[deterlen - 1], -deter2[deter2len - 1]);
            Assert.IsTrue((deter[deterlen - 1] == 0.0) == (deter2[deter2len - 1] == 0.0));
            Assert.IsTrue((deter2[deter2len - 1] == 0.0) == (deter3[deter3len - 1] == 0.0));
            return(deter[deterlen - 1]);
        }