示例#1
0
        public bool SlidePoint(int index, PointF mouse, Transformer WorldToScreen)
        {
            //// get the mouse-coord x for the originally clicked fitpoint position
            Vect2 uv = new Vect2();
            Vect3 xyz0 = new Vect3();
            //xVal(FitPoints[index].UV, ref xyz0);
            //Point3D m0 = WorldToScreen(new Point3D(xyz0.Array));

            //get the mouse-coord for the starting fixed point
            CurvePoint warp = FitPoints[index] as CurvePoint;
            warp.m_curve.xVal(warp.SCurve, ref uv, ref xyz0);
            Vect3 xyz = new Vect3(xyz0);
            Point3D x0 = WorldToScreen(new Point3D(xyz0.Array));

            // small offset
            double delta_s = .005;
            //			for (; xyz.Distance(xyz0) < 1e-4 && delta_s < 1; delta_s +=.05 )//ensure nonzero tangent
            //			{
            warp.m_curve.xVal(warp.SCurve + delta_s, ref uv, ref xyz);

            //			}
            //convert to mouse coords
            Point3D del = WorldToScreen(new Point3D(xyz.ToArray()));
            Vect2 dmds = new Vect2(del.X - x0.X, del.Y - x0.Y);
            //dmds -= new Vect2(x0.X, x0.Y);//get deltaxy/deltas

            Vect2 dm = new Vect2(mouse);
            dm -= new Vect2(x0.X, x0.Y);//get delta mouse

            //double reduce = Math.Max(dm.Magnitude, dmds.Magnitude);
            double dot = dmds.Dot(dm);//mouse.X * dmds.X + mouse.Y * dmds.Y;
            dot = dot / (dm.Magnitude * dmds.Magnitude);
            if (BLAS.is_equal(dot, 0, 1e-5))//dont move when perpendicular to the mouse
                return true;

            dot *= delta_s;// / dmds.Magnitude;
            //dot *= delta_s / reduce;// / dmds.Magnitude;

            //	Utilities.LimitRange(-.005, ref dot, .005);
            warp.SCurve += dot;

            warp.SCurve = Utilities.LimitRange(-.2, warp.SCurve + dot, 1.2);
            //ReFit();
            return true;
        }
示例#2
0
        public virtual List<Entity> CreateEntities(bool bFitPoints, double TolAngle, out double[] sPos)
        {
            if (!AllFitPointsValid())
            {
                sPos = null;
                return new List<Entity>();
            }

            List<double> spos = new List<double>();
            const int TEST = 8;
            int FitLength = FitPoints.Length;
            double[] stest = new double[(FitLength - 1) * TEST];
            Vect3[] xtest = new Vect3[(FitLength - 1) * TEST];
            Vect2 uv = new Vect2();
            Vect3 xyz = new Vect3();
            Vect3 dxp = new Vect3(), dxm = new Vect3();
            //initial 8 subdivisions per segment
            int nFit, nTest = 0;
            for (nFit = 1; nFit < FitLength; nFit++)
            {
                for (int i = 0; i < TEST; i++, nTest++)
                {
                    stest[nTest] = BLAS.interpolate(i, TEST, FitPoints[nFit].S, FitPoints[nFit - 1].S);
                    xtest[nTest] = new Vect3();
                    xVal(stest[nTest], ref uv, ref xtest[nTest]);
                }
            }

            //test the midpoint of each subsegment to determine required # of points
            int[] nAdd = new int[stest.Length];
            double cosA;
            double smid;
            int nTotal = FitLength;
            for (nTest = 1; nTest < stest.Length; nTest++)
            {
                //midpoint position
                smid = (stest[nTest] + stest[nTest - 1]) / 2.0;
                xVal(smid, ref uv, ref xyz);
                //forward and backward tangents
                dxp = xtest[nTest] - xyz;
                dxm = xtest[nTest - 1] - xyz;
                //change in angle between for and aft tans
                cosA = -(dxp.Dot(dxm)) / (dxp.Magnitude * dxm.Magnitude);
                Utilities.LimitRange(-1, ref cosA, 1);
                cosA = Math.Acos(cosA);
                //determine additional points and sum total
                nTotal += nAdd[nTest] = (int)(cosA / TolAngle + 1);
            }

            m_Length = 0;
            Vect3 xprev = new Vect3();
            Vect3 dx = new Vect3();
            List<Point3D> pnts = new List<Point3D>();
            List<Vect3> tans = new List<Vect3>();
            xVal(stest[0], ref uv, ref xprev);
            pnts.Add(new Point3D(xprev.ToArray()));
            spos.Add(stest[0]);
            for (nTest = 1; nTest < stest.Length; nTest++)
            {
                for (int i = 1; i <= nAdd[nTest]; i++)
                {
                    smid = ((nAdd[nTest] - i) * stest[nTest - 1] + i * stest[nTest]) / nAdd[nTest];
                    xVec(smid, ref uv, ref xyz, ref dx);
                    spos.Add(smid);
                    pnts.Add(new Point3D(xyz.ToArray()));
                    tans.Add(new Vect3(dx));
                    m_Length += xyz.Distance(xprev);
                    xprev.Set(xyz);
                }
            }

            if (EXTENDENTITY)
            {
                //add for-cast/back-cast points
                for (int i = 0; i < 2; i++)
                {
                    for (nTest = 0; nTest < 10; nTest++)
                    {
                        smid = BLAS.interpolant(nTest, 10) * 0.05;//scale down to .1 cast
                        if (i == 0)
                            smid = -smid;
                        else
                            smid += 1.0;

                        xVal(smid, ref uv, ref xyz);
                        if (i == 0)
                            pnts.Insert(0, new Point3D(xyz.ToArray()));
                        else
                            pnts.Add(new Point3D(xyz.ToArray()));
                    }
                }
            }

            LinearPath lp = new LinearPath(pnts);
            lp.EntityData = this;
            //lp.LineWeight = 3.0f;
            //lp.LineWeightMethod = colorMethodType.byEntity;
            List<Entity> tanpaths = new List<Entity>();
            tanpaths.Add(lp);
            if (bFitPoints)
            {
                //LinearPath path;
                //int npnt = 0;
                //foreach (Vect3 pnt in tans)
                //{
                //	pnt.Magnitude = 2;
                //	xyz = new Vect3(pnts[npnt].ToArray());
                //	xyz += pnt;
                //	path = new LinearPath(pnts[npnt], new Point3D(xyz.ToArray()));
                //	path.EntityData = this;
                //	tanpaths.Add(path);
                //	npnt++;
                //	//xVal(pnt.UV, ref xyz);
                //	//pnts.Add(new Point3D(xyz.ToArray()));
                //}
                pnts = new List<Point3D>();
                foreach (IFitPoint pnt in FitPoints)
                {
                    xVal(pnt.UV, ref xyz);
                    pnts.Add(new Point3D(xyz.ToArray()));
                }
                PointCloud pc = new PointCloud(pnts, 8f);
                pc.EntityData = this;
                tanpaths.Add(pc);
            }
            sPos = spos.ToArray();
            return tanpaths;
        }