Ejemplo n.º 1
0
        public override int Extend(List <Point> points, List <double> weigths, bool[] extended)
        {
            double[] actdata = DataFromPoints(points, weigths, out int addcount);
            for (int i = 0; i < 10; i++)
            {
                this.data[i] += actdata[i];
            }
            this.actnum += addcount;

            Func <Vector <double>, Vector <double> > target = (s) => Fun(s, data[3], data[4], data[5], data[6], data[7], data[8]);
            Func <Vector <double>, Matrix <double> > jacobi = (s) => Jacobi(s, data[3], data[4], data[5], data[6], data[7], data[8]);
            Vector <double> start = Vector <double> .Build.Dense(4, 0);

            for (int i = 0; i < 3; i++)
            {
                start[i] = this.versor[i];
            }
            (Vector <double> res_versor, int cnt) = MatrixExt.Fsolve(start, target, jacobi);
            this.versor = res_versor;
            for (int i = 0; i < 3; i++)
            {
                this.versor[i] = res_versor[i];
            }
            this.d = -(data[0] * versor[0] + data[1] * versor[1] + data[2] * versor[2]) / data[9];
            return(cnt);
        }
Ejemplo n.º 2
0
        public void Generate(Point[] points, out int iter, Vector <double> start, bool regenerate = true)
        {
            int n = points.Length;

            double[] x = new double[n];
            double[] y = new double[n];
            double[] z = new double[n];
            for (int i = 0; i < n; i++)
            {
                x[i] = points[i].x;
                y[i] = points[i].y;
                z[i] = points[i].z;
            }
            Vector <double> Vx = Vector <double> .Build.DenseOfArray(x);

            Vector <double> Vy = Vector <double> .Build.DenseOfArray(y);

            Vector <double> Vz = Vector <double> .Build.DenseOfArray(z);

            double Mx = Vx.Average();
            double My = Vy.Average();
            double Mz = Vz.Average();

            Vx -= Mx;
            Vy -= My;
            Vz -= Mz;
            double x2 = Vx.DotProduct(Vx);
            double y2 = Vy.DotProduct(Vy);
            double z2 = Vz.DotProduct(Vz);
            double xy = Vx.DotProduct(Vy);
            double xz = Vx.DotProduct(Vz);
            double yz = Vy.DotProduct(Vz);

            Func <Vector <double>, Vector <double> > target = (s) => Fun(s, x2, y2, z2, xy, yz, xz);
            Func <Vector <double>, Matrix <double> > jacobi = (s) => Jacobi(s, x2, y2, z2, xy, yz, xz);

            (Vector <double> res_versor, int cnt) = MatrixExt.Fsolve(start, target, jacobi);

            this.versor = res_versor;
            iter        = cnt;
            this.d      = -(Mx * versor[0] + My * versor[1] + Mz * versor[2]);
            double dist;

            disp = 0;
            Connected.Clear();
            for (int i = 0; i < n; i++)
            {
                if ((dist = Distance(points[i])) < Control.AcceptRangePlain)
                {
                    Connected.Add(points[i]);
                    disp += dist * dist;
                }
            }
            pointnum = Connected.Count;
            if (regenerate)
            {
                Regenerate();
            }
        }
Ejemplo n.º 3
0
 public Triangle(Point p1, Point p2, Point p3, Vector <double> ver = null)
 {
     vertix = new Point[3] {
         p1, p2, p3
     };
     weight = GetArea();
     if (ver == null)
     {
         versor = MatrixExt.WersorFromPlane(p1, p2, p3);
     }
     else
     {
         versor = ver;
     }
 }
Ejemplo n.º 4
0
        public override void Generate(Point[] points, out int iter, bool regenerate = true)
        {
            int             n  = points.Length;
            Vector <double> sw = Vector <double> .Build.Dense(3, 0);

            for (int i = 0; i + 2 < n; i++)
            {
                sw += MatrixExt.WersorFromPlane(points[i], points[i + 1], points[i + 2]);
            }
            sw = sw.Normalize(2);
            Vector <double> start = Vector <double> .Build.Dense(4, 0);

            for (int i = 0; i < 3; i++)
            {
                start[i] = sw[i];
            }
            Generate(points, out iter, start, regenerate);
        }
Ejemplo n.º 5
0
        public override void Generate(List <Point> points, List <double> weigths, out int iter)
        {
            int             n  = points.Count;
            Vector <double> sw = Vector <double> .Build.Dense(3, 0);

            for (int i = 0; i + 2 < n; i++)
            {
                sw += MatrixExt.WersorFromPlane(points[i], points[i + 1], points[i + 2]);
            }
            sw = sw.Normalize(2);
            Vector <double> start = Vector <double> .Build.Dense(4, 0);

            for (int i = 0; i < 3; i++)
            {
                start[i] = sw[i];
            }
            Generate(points, weigths, out iter, start);
        }
Ejemplo n.º 6
0
        static public Vector <double> WersorFromPlane(Point p1, Point p2, Point p3)
        {
            /* Matrix<double> A = Matrix<double>.Build.Dense(4, 4, 0);
             * A[0, 0] = p1.x; A[0, 1] = p1.y; ; A[0, 2] = p1.z; A[0, 3] = 1;
             * A[1, 0] = p2.x; A[1, 1] = p2.y; ; A[1, 2] = p2.z; A[1, 3] = 1;
             * A[2, 0] = p3.x; A[2, 1] = p3.y; ; A[2, 2] = p3.z; A[2, 3] = 1;
             * A[3, 0] = 1.0; A[3, 1] = 0; ; A[3, 2] = 0; A[3, 3] = 0;
             * if (A.Determinant() == 0) return Vector<double>.Build.Dense(3, 0);
             * Vector<double> b = Vector<double>.Build.DenseOfArray(new double[4] { 0, 0, 0, 1 });
             * Vector<double> res = A.Solve(b);
             * b = Vector<double>.Build.Dense(3);
             * for (int i = 0; i < 3; i++)
             *   b[i] = res[i];*/

            Vector <double> b = MatrixExt.Cross(p1 - p3, p2 - p3);

            if (b.L1Norm() == 0)
            {
                throw new AlgorithmException("Linear points");
            }
            return(b.Normalize(2));
        }
Ejemplo n.º 7
0
 public Triangle(Point p1, Point p2, Point p3, Vector <double> ver = null, int id = 0)
 {
     //status = 0;
     this.id = id;
     //Edges = new List<Edge>();
     vertix = new Point[3] {
         p1, p2, p3
     };
     weight = GetArea();
     if (ver == null)
     {
         versor = MatrixExt.WersorFromPlane(p1, p2, p3);
     }
     else
     {
         var v = MatrixExt.WersorFromPlane(p1, p2, p3);
         if ((v - ver).L2Norm() > Control.VertexLinear && (v + ver).L2Norm() > Control.VertexLinear)
         {
             ver = MatrixExt.WersorFromPlane(p1, p2, p3);
         }
         versor = ver;
     }
 }
Ejemplo n.º 8
0
        public void Generate(List <Point> points, List <double> weights, out int iter, Vector <double> start)
        {
            this.data = DataFromPoints(points, weights, out this.actnum);

            Func <Vector <double>, Vector <double> > target = (s) => Fun(s, data[3], data[4], data[5], data[6], data[7], data[8]);
            Func <Vector <double>, Matrix <double> > jacobi = (s) => Jacobi(s, data[3], data[4], data[5], data[6], data[7], data[8]);

            (Vector <double> res_versor, int cnt) = MatrixExt.Fsolve(start, target, jacobi);

            this.versor = Vector <double> .Build.Dense(3, 0);

            for (int i = 0; i < 3; i++)
            {
                this.versor[i] = res_versor[i];
            }
            iter   = cnt;
            this.d = -(data[0] * versor[0] + data[1] * versor[1] + data[2] * versor[2]) / data[9];

            /*if (regenerate)
             * {
             *  Regenerate();
             * }*/
        }
Ejemplo n.º 9
0
 private double GetArea()
 {
     return(MatrixExt.Cross(vertix[1] - vertix[0], vertix[2] - vertix[0]).Norm(2) / 2);
 }