public void Update()
        {
            foreach (GregorySubpatch g in gregorySubpatches)
            {
                g.CalculateControlPoints();
            }
            MyPoint temp = MyMath.Medium(gregorySubpatches[0].ControlPoints[13], gregorySubpatches[1].ControlPoints[13], gregorySubpatches[2].ControlPoints[13]);
            MyPoint p0   = MyMath.AddDifference2(temp, gregorySubpatches[0].ControlPoints[13], 0.66);
            MyPoint p1   = MyMath.AddDifference2(temp, gregorySubpatches[1].ControlPoints[13], 0.66);
            MyPoint p2   = MyMath.AddDifference2(temp, gregorySubpatches[2].ControlPoints[13], 0.66);

            foreach (GregorySubpatch g in gregorySubpatches)
            {
                g.ControlPoints[13].SetCoordinates(temp);
            }
            gregorySubpatches[0].ControlPoints[14].SetCoordinates(p0);
            gregorySubpatches[1].ControlPoints[14].SetCoordinates(p1);
            gregorySubpatches[2].ControlPoints[14].SetCoordinates(p2);
            gregorySubpatches[0].ControlPoints[15] = gregorySubpatches[1].ControlPoints[14];
            gregorySubpatches[1].ControlPoints[15] = gregorySubpatches[2].ControlPoints[14];
            gregorySubpatches[2].ControlPoints[15] = gregorySubpatches[0].ControlPoints[14];

            for (int i = 0; i < 3; i++)
            {
                MyPoint a0 = MyMath.Difference(gregorySubpatches[i].ControlPoints[13], gregorySubpatches[i].ControlPoints[14]);
                MyPoint b0 = MyMath.Difference(gregorySubpatches[i].ControlPoints[15], gregorySubpatches[i].ControlPoints[13]);
                MyPoint g0 = new MyPoint();
                g0.SetInterpolatedCoordinates(a0, b0, 0.5);
                MyPoint g3 = MyMath.Difference(gregorySubpatches[i].ControlPoints[5], gregorySubpatches[i].ControlPoints[6]);
                MyPoint g1 = new MyPoint();
                g1.SetInterpolatedCoordinates(g0, g3, 0.5);
                MyPoint temp2 = new MyPoint();
                temp2 = MyMath.BernstetInterpolation(g3, g0, g1, 0.66);
                gregorySubpatches[i].ControlPoints[16] = MyMath.AddVector(gregorySubpatches[i].ControlPoints[12], temp2);
                temp2 = MyMath.BernstetInterpolation(g0, g3, g1, 0.33);
                gregorySubpatches[i].ControlPoints[17] = MyMath.AddVector(gregorySubpatches[i].ControlPoints[15], temp2);

                a0 = MyMath.Difference(gregorySubpatches[i].ControlPoints[13], gregorySubpatches[(i + 2) % 3].ControlPoints[14]);
                b0 = MyMath.Difference(gregorySubpatches[i].ControlPoints[14], gregorySubpatches[i].ControlPoints[13]);
                g0.SetInterpolatedCoordinates(a0, b0, 0.5);
                g3 = MyMath.Difference(gregorySubpatches[i].ControlPoints[1], gregorySubpatches[i].ControlPoints[0]);
                g1.SetInterpolatedCoordinates(g0, g3, 0.5);

                temp2.SetInterpolatedCoordinates(g3, g0, 0.66);
                gregorySubpatches[i].ControlPoints[18] = MyMath.AddVector(gregorySubpatches[i].ControlPoints[7], temp2);
                temp2 = MyMath.BernstetInterpolation(g0, g3, g1, 0.33);
                gregorySubpatches[i].ControlPoints[19] = MyMath.AddVector(gregorySubpatches[i].ControlPoints[14], temp2);

                gregorySubpatches[i].UpdateControlTable();
            }
        }
        public virtual List <MyPoint> getP(double u1, double v1)
        {
            double  step = 0.05;
            MyPoint p1   = new MyPoint();
            MyPoint p2   = new MyPoint();
            MyPoint p3   = new MyPoint();

            p1.SetCoordinates(this.ComputePointForParameter(u1, v1));
            p2.SetCoordinates(this.ComputePointForParameter(u1, v1 + step));
            p3.SetCoordinates(MyMath.Substract(p2, p1));
            p3.Normalized();

            //points.Clear();
            //_knots.Clear();
            double delta = 0.001f;
            //_knots2.Clear();
            int l = this.isCylinder ? 3 : 0;

            double step1, step2;
            int    m = DeBoorControlPoints.GetLength(0) + Degree + 1 + l;

            //for (int i = 0; i < m; i++)
            //    _knots.Add((double)i / (double)(m - 1));
            //m = DeBoorControlPoints.GetLength(1) + Degree + 1;
            //for (int i = 0; i < m; i++)
            //    _knots2.Add((double)i / (double)(m - 1));
            step1 = (_knots2[DeBoorControlPoints.GetLength(1)] - _knots2[Degree]) / (double)(samplesNumber - 1);
            step2 = (_knots[DeBoorControlPoints.GetLength(0) + l] - _knots[Degree]) / (double)(samplesNumber - 1);
            double         u, v;
            List <MyPoint> qPoints = new List <MyPoint>();

            v = _knots2[Degree]; //N
            double x = 0, y = 0, z = 0, a = 0, b = 0, c = 0;

            while (v - delta <= _knots2[DeBoorControlPoints.GetLength(1)])
            {
                for (int i = 0; i < mSize + l; i++)
                {
                    x = y = z = 0;
                    for (int j = 0; j < nSize; j++)
                    {
                        x += (DeBoorControlPoints[i % mSize, j].x * Nik2(v, j, Degree));
                        y += (DeBoorControlPoints[i % mSize, j].y * Nik2(v, j, Degree));
                        z += (DeBoorControlPoints[i % mSize, j].z * Nik2(v, j, Degree));
                    }
                    qPoints.Add(new MyPoint(x, y, z));
                    v += step1;
                }
            }

            List <MyPoint> qPointsDer = new List <MyPoint>();

            qPointsDer.Add(new MyPoint());
            for (int i = 0; i < qPoints.Count - 1; i++)
            {
                qPointsDer.Add(new MyPoint());
                qPointsDer[i].SetCoordinates(MyMath.Difference(qPoints[i + 1], qPoints[i]));
            }
            //qPointsDer[0].SetCoordinates(MyMath.AddDifference(qPointsDer[0], qPointsDer[1]));
            //policzyc krzywa stalego parametru
            //Qi = (delta P)
            _knotsDeriv.Clear();
            m = qPointsDer.Count + Degree - 1 + 1; //stopień = 2
            for (int i = 0; i < m; i++)
            {
                _knotsDeriv.Add((double)i / (double)(m - 1));
            }
            double t;

            t = u1;
            //        while (t < _knotsDeriv[qPointsDer.Count])
            //       {
            x = y = z = 0;
            for (int i = 0; i < qPointsDer.Count; i++)
            {
                x += (qPointsDer[i].x * Nik3(t, i, Degree - 1));
                y += (qPointsDer[i].y * Nik3(t, i, Degree - 1));
                z += (qPointsDer[i].z * Nik3(t, i, Degree - 1));
            }
            //        }
            //Ci = suma i = 0 .. n-1 Ni,p-1(u),Qi
            return(qPointsDer);
//            return p3;
        }