Exemplo n.º 1
0
        internal double[,] GetBestMatrix(int f0, double[] p0, int f1, double[] p1)
        {
            // move from (f0,p0) to (f1,p1); point p is on the cell surface.
            PFace F0 = Faces[f0], F1 = Faces[f1];

            if (F0.Base.Id != F1.Base.Id)
            {
                return(null);
            }
            double[] q0    = PGeom.ApplyInvMatrix(F0.Matrix, p0);
            double[] q1    = PGeom.ApplyInvMatrix(F1.Matrix, p1);
            double   dbest = double.MaxValue;

            double[,] mr = null;
            foreach (double[,] m in F0.Base.SMatrices)
            {
                double[] qq = PGeom.ApplyMatrix(m, q0);
                double   v  = PGeom.Dist2(qq, q1);
                if (v < dbest)
                {
                    dbest = v; mr = m;
                }
            }
            return(PGeom.MatrixMulInv2(F0.Matrix, PGeom.MatrixMul(mr, F1.Matrix)));
        }
Exemplo n.º 2
0
        private int FindFace(double[] p, double[,] matr)
        {
            p = PGeom.ApplyMatrix(matr, p);
            int    r0 = 0;
            double d0 = double.MaxValue;

            foreach (PFace F in Faces)
            {
                double v = PGeom.Dist2(p, F.Pole);
                if (v < d0)
                {
                    d0 = v; r0 = F.Id;
                }
            }
            return(r0);
        }
Exemplo n.º 3
0
        private int FindAxis(double[] dir)
        {
            int    r0 = 0;
            double d0 = double.MaxValue;

            foreach (PAxis Ax in Axes)
            {
                double v = PGeom.Dist2(dir, Ax.Dir);
                if (v < d0)
                {
                    d0 = v; r0 = Ax.Id + 1;
                }
                v = PGeom.Dist2Rev(dir, Ax.Dir);
                if (v < d0)
                {
                    d0 = v; r0 = -Ax.Id - 1;
                }
            }
            return(r0);
        }
Exemplo n.º 4
0
        private void CutFaces()
        {
            double RMax = 0;

            foreach (PBaseFace F in BaseFaces)
            {
                RMax = Math.Max(RMax, PGeom.VLength(F.Pole));
            }
            int minrank = int.MaxValue;

            foreach (PBaseFace F in BaseFaces)
            {
                CutNode  face = CutNode.GenCube(Dim, RMax * Dim);
                double[] hpln = CutNetwork.GetPlane(F.Pole, 1);
                face.Split(1, hpln, false);
                face = face.ZeroNode;
                int opgen = 1;
                foreach (PFace FF in Faces)
                {
                    if (F.Id != FF.Id)
                    {
                        hpln = CutNetwork.GetPlane(FF.Pole, 1);
                        face.Split(++opgen, hpln, true);
                        if (face.Status != CutNode.STAT_PLUS)
                        {
                            throw new Exception("Empty face: Id=" + F.Id);
                        }
                    }
                }

                int        nff   = face.Children.Length;
                double[][] ffpol = new double[nff][];
                for (int i = 0; i < nff; i++)
                {
                    ffpol[i] = face.Children[i].Pole;
                }
                F.FPoles = ffpol;

                LMesh m = new LMesh(Dim, true);
                face.FillLMesh(++opgen, m);
                m.CloseCtr();
                F.FaceMesh      = new PMesh(m);
                F.FaceMesh.FCtr = F.Pole;

                double[]   verts  = m.pts;
                int        nverts = m.npts;
                CutNetwork CN     = new CutNetwork(face, Dim, opgen);
                double[][] fctrs  = null;
                if (QSimplified)
                {
                    fctrs = CN.GetCtrs();
                }
                F.AxisLayers = new int[Axes.Length];
                for (int u = 0; u < Axes.Length; u++)
                {
                    PAxis    Ax = Axes[u];
                    double[] D = Ax.Dir;
                    double   lD = PGeom.Dist2(D, new double[Dim]);
                    double   smin = double.MaxValue, smax = double.MinValue;
                    for (int i = 0; i < nverts; i++)
                    {
                        double v = 0;
                        for (int j = 0; j < Dim; j++)
                        {
                            v += D[j] * verts[i * Dim + j];
                        }
                        if (v < smin)
                        {
                            smin = v;
                        }
                        if (v > smax)
                        {
                            smax = v;
                        }
                    }
                    smin /= lD; smax /= lD;
                    bool cs = false, cc = false;
                    int  k = Ax.Base.NLayers - 1;
                    for (int i = 0; i < Ax.Base.Cut.Length; i++)
                    {
                        double p = Ax.Base.Cut[i];
                        if (p >= smax - 0.0001)
                        {
                            continue;
                        }
                        if (!cs)
                        {
                            k = i; cs = true;
                        }
                        if (p <= smin + 0.0001)
                        {
                            break;
                        }
                        hpln = CutNetwork.GetPlane(Ax.Dir, p);
                        CN.Split(hpln, false);
                        cc = true;
                    }
                    if (cc)
                    {
                        k = -1;
                    }
                    F.AxisLayers[u] = k;
                }
                F.SetStickers(m, CN, Axes, fctrs);
                minrank = Math.Min(minrank, F.MinRank());
            }
            foreach (PBaseFace F in BaseFaces)
            {
                F.SubRank(minrank);
            }
        }