Exemplo n.º 1
0
        public bool Project(Bez2D bez, out Param par, out VecD pnt)
        {
            /*
             *        MEANING:    the NEAREST point in the RANGE [0,1]
             *        ASSUMPTION:    -    bezier can be non-reduced
             *                    -    bezier is NOT self-intersecting
             */
            par = null;
            pnt = null;
            Param parM;

            if (bez.IsSelfInters(out parM))
            {
                throw new ExceptionGMath("VecD", "Project(bez)", null);
                //return false;
            }
            if (bez.IsDegen)
            {
                par = new Param(Param.Degen);
                pnt = bez.Middle;
                return(true);
            }
            if (bez.IsSeg(out parM))
            {
                SegD seg = bez.Reduced as SegD;
                this.Project(seg, out par, out pnt);
                bez.ParamFromSeg(par);
                return(true);
            }
            // case of non-flat Bezier
            Param[] parsPerp;
            if (!this.Perp(bez, out parsPerp))
            {
                return(false);
            }
            double distS   = this.Dist(bez.Start);
            double distE   = this.Dist(bez.End);
            double distMin = Math.Min(distS, distE);
            double parMin  = (distS <= distE)? 0.0: 1.0;

            if (parsPerp != null)
            {
                for (int iPerp = 0; iPerp < parsPerp.Length; iPerp++)
                {
                    if (bez.IsEvaluableStrict(parsPerp[iPerp]))
                    {
                        double distPerp = this.Dist(bez.Evaluate(parsPerp[iPerp]));
                        if (distPerp < distMin)
                        {
                            distMin = distPerp;
                            parMin  = parsPerp[iPerp];
                        }
                    }
                }
            }
            par = parMin;
            pnt = bez.Evaluate(parMin);
            return(true);
        }
Exemplo n.º 2
0
 public void FromReduced(BCurve bcurve)
 {
     // parameter of the (reduced)curve may be invalidated if
     // the curve intersects the self-intersecting Bezier
     if (this.val == Param.Invalid)
     {
         return;
     }
     if (bcurve.IsDegen)
     {
         return;
     }
     if (bcurve is Bez2D)
     {
         Bez2D bez = bcurve as Bez2D;
         Param parM;
         if (bez.IsSeg(out parM))
         {
             bez.ParamFromSeg(this);
         }
     }
 }
Exemplo n.º 3
0
 public bool Project(Bez2D bez, out Param par, out VecD pnt)
 {
     /*
      *        MEANING:    the NEAREST point in the RANGE [0,1]
      *        ASSUMPTION:    -    bezier can be non-reduced
      *                    -    bezier is NOT self-intersecting
      */
     par=null;
     pnt=null;
     Param parM;
     if (bez.IsSelfInters(out parM))
     {
         throw new ExceptionGMath("VecD","Project(bez)",null);
         //return false;
     }
     if (bez.IsDegen)
     {
         par=new Param(Param.Degen);
         pnt=bez.Middle;
         return true;
     }
     if (bez.IsSeg(out parM))
     {
         SegD seg=bez.Reduced as SegD;
         this.Project(seg,out par,out pnt);
         bez.ParamFromSeg(par);
         return true;
     }
     // case of non-flat Bezier
     Param[] parsPerp;
     if (!this.Perp(bez, out parsPerp))
         return false;
     double distS=this.Dist(bez.Start);
     double distE=this.Dist(bez.End);
     double distMin=Math.Min(distS,distE);
     double parMin=(distS<=distE)? 0.0: 1.0;
     if (parsPerp!=null)
     {
         for (int iPerp=0; iPerp<parsPerp.Length; iPerp++)
         {
             if (bez.IsEvaluableStrict(parsPerp[iPerp]))
             {
                 double distPerp=this.Dist(bez.Evaluate(parsPerp[iPerp]));
                 if (distPerp<distMin)
                 {
                     distMin=distPerp;
                     parMin=parsPerp[iPerp];
                 }
             }
         }
     }
     par=parMin;
     pnt=bez.Evaluate(parMin);
     return true;
 }