Example #1
0
 public InfoParamInters(Param parA, Param parB): this()
 {
     if (parA==null)
     {
         this.param[0]=null;
     }
     else
     {
         this.param[0]=parA.Copy();
     }
     if (parB==null)
     {
         this.param[1]=null;
     }
     else
     {
         this.param[1]=parB.Copy();
     }
 }
Example #2
0
 /*
  *        METHODS
  */
 public bool IsSeg(out Param parM)
 {    
     /*
      *        MEANING: NON_DEGENERATED, PARAMETRIC segment
      *                 (implies, that the Bezier is not 
      *                 self-intersecting)
      */
     parM=null;
     if (this.IsDegen)
         return false;
     if (this.cp[0]==this.cp[2])
         return false; // S/I bezier
     if (this.cp[0]==this.cp[1])
     {
         parM=new Param(0);
         return true;
     }
     if (this.cp[1]==this.cp[2])
     {
         parM=new Param(1);
         return true;
     }
     SegD seg=new SegD(this.cp[0], this.cp[2]);
     LineD line=new LineD(seg);
     VecD pnt;
     Param par;
     this.cp[1].Project(line,out par,out pnt);
     if (this.cp[1].Dist(pnt)>MConsts.EPS_DEC) 
         return false;
     if (!seg.IsEvaluableStrict(par))
         return false;
     parM=par;
     if (Math.Abs(parM.Val-0.5)<MConsts.EPS_DEC)
     {
         parM.Val=0.5;
     }
     return true;
 }
Example #3
0
 public VecD Evaluate(Param par)
 {
     throw new ExceptionGMath("Contour","Evaluate","NOT IMPLEMENTED");
     //return null;
 }
Example #4
0
 public bool IsEvaluableStrict(Param par)
 {
     throw new ExceptionGMath("Contour","IsEvaluableStrict","NOT IMPLEMENTED");
     //return false;
 }
Example #5
0
 public VecD Evaluate(Param par)
 {
     if (!this.IsEvaluableWide(par))
     {
         throw new ExceptionGMath("RayD","Evaluate",null);
         //return null;
     }
     if (par.IsInfinite)
         return null;
     return (1-par)*this.cp[0]+par*this.cp[1];
 }
Example #6
0
 public bool IsEvaluableWide(Param par)
 {
     return ((par.IsValid)&&(!par.IsDegen));
 }
Example #7
0
 public double Curvature(Param par)
 {
     return 0;
 }
Example #8
0
 VecD Curve.DirTang(Param par)
 {
     return ((LCurve)this).DirTang;
 }
Example #9
0
 public void Subdivide(Param par, out BCurve curveS, out BCurve curveE)
 {
     /*
      *        ASSUMPTION: par should be in the range [0,1]
      */
     curveS=null;
     curveE=null;
     if (!this.IsEvaluableStrict(par))
         return;
     curveS=new DegenD(this.cp);
     curveE=new DegenD(this.cp);
 }
Example #10
0
        public BCurve SubCurve(Param parA, Param parB)
        {
            if ((!this.IsEvaluableStrict(parA))||(!this.IsEvaluableStrict(parB)))
                return null;

            Bez2D bezWork=new Bez2D(this);
            double valA=parA.Val;
            double valB=parB.Val;
            if (valA>valB)
            {
                bezWork.Reverse();
                valA=1-valA;
                valB=1-valB;
            }
            /*
            if ((valS==0)&&(valE==1))
                return new Bez2D(bezWork);
            CurveD curveS, curveE;
            if (valS==0)
            {
                bezWork.Subdivide(valB,out curveS, out curveE);
                return curveS;
            }
            if (valE==1)
            {
                bezWork.Subdivide(valA,out curveS, out curveE);
                return curveE;
            }
            */
            VecD a01,a12,b01,b12;
            a01=(1-valA)*bezWork.Cp(0)+valA*bezWork.Cp(1);
            a12=(1-valA)*bezWork.Cp(1)+valA*bezWork.Cp(2);
            b01=(1-valB)*bezWork.Cp(0)+valB*bezWork.Cp(1);
            b12=(1-valB)*bezWork.Cp(1)+valB*bezWork.Cp(2);

            VecD start, mid, end;
            start=(1-valA)*a01+valA*a12;
            end=(1-valB)*b01+valB*b12;
            mid=(1-valB)*a01+valB*a12; 
            // mid=(1-valA)*(1-valB)*bezWork.Cp(0)+valA*valB*bezWork.Cp(2)+
            //        ((1-valB)*valA+(1-valA)*valB))*bezWork.Cp(1);

            return new Bez2D(start,mid,end);
        }
Example #11
0
 public void Subdivide(Param par, out BCurve curveS, out BCurve curveE)
 {
     /*
      *        ASSUMPTION: par should be in the range [0,1]
      */
     curveS=null;
     curveE=null;
     if (!this.IsEvaluableStrict(par))
         return;
     VecD pnt01=(1-par.Val)*this.cp[0]+par.Val*this.cp[1];
     VecD pnt12=(1-par.Val)*this.cp[1]+par.Val*this.cp[2];
     VecD pnt = (1-par.Val)*pnt01+par.Val*pnt12;
     curveS=new Bez2D(this.cp[0],pnt01,pnt);
     curveE=new Bez2D(pnt,pnt12,this.cp[2]);
 }
Example #12
0
        public bool ParamFromSeg(Param par)
        {
            double valSeg=par.Val;

            if ((valSeg<0)||(valSeg>1))
            {
                throw new ExceptionGMath("Bez2D","ParamFromSeg","");
                //return false;
            }
            Param parM;
            if (!this.IsSeg(out parM))
            {
                throw new ExceptionGMath("Bez2D","ParamFromSeg","");
                //return false;
            }
            double valM=parM.Val;

            if (Math.Abs(valM-0.5)<MConsts.EPS_DEC) 
                return true;

            double D = valM*valM+(1-2*valM)*valSeg;
            if (Math.Abs(D)<MConsts.EPS_DEC)
            {
                D=0;
            }
            if (D<0)
            {
                throw new ExceptionGMath("Bez2D","ParamFromSeg","");
                //return false;
            }
            double valBez=0;
            if ((0.3<valM)&&(valM<0.7)) // unstable for valM --> 0.5
            {
                valBez = valSeg/(valM+Math.Sqrt(D));
            }
            else 
            {
                valBez = (-valM+Math.Sqrt(D))/(1-2*valM);
            }
            par.Val=valBez;
            par.Round(0,1);
            if (!((par.Val>=0.0)&&(par.Val<=1.0)))
            {
                throw new ExceptionGMath("Bez2D","ParamFromSeg","");
                //return false;
            }
            return true;
        }
Example #13
0
        public bool ParamFromSupport(Param parSupport, out Param[] parsBez)
        {
            parsBez=null;
            parSupport.Round(0,1);
            if ((parSupport.Val<0)||(parSupport.Val>1))
            {
                throw new ExceptionGMath("Bez2D","ParamFromSupport",null);
                //return false;
            }

            Param parM;
            if (!this.IsSelfInters(out parM))
            {
                parsBez=new Param[1];
                parsBez[0]=parSupport.Copy();
                this.ParamFromSeg(parsBez[0]);
            }

            // self-intersecting Bezier
            double valM=parM.Val;
            if (valM==Param.Infinity)
            {
                double tau=0.5*parSupport.Val; // parameter with respect to [Cp(0),Cp(1)]
                parsBez=new Param[2];
                parsBez[0]=new Param(0.5*(1-Math.Sqrt(1-2*tau)));
                parsBez[1]=new Param(0.5*(1+Math.Sqrt(1-2*tau)));
            }
            else if (valM>1)
            {
                double tau=((valM*valM)/(1-2*valM))*parSupport.Val;
                double D=valM*valM+tau*(1-2*valM);
                if (Math.Abs(D)<MConsts.EPS_DEC)
                {
                    D=0;
                }
                if (D<0)
                {
                    throw new ExceptionGMath("BezD","ParamFromSegGeneral",null);
                    //return false;
                }
                if (tau<1)        
                {
                    parsBez=new Param[1];
                    parsBez[0]=new Param((valM-Math.Sqrt(D))/(1-2*valM));
                }
                else // 1<=tau<=(valM*valM)/(1-2*valM)
                {
                    parsBez=new Param[2];
                    parsBez[0]=new Param((valM-Math.Sqrt(D))/(1-2*valM));
                    parsBez[1]=new Param((valM+Math.Sqrt(D))/(1-2*valM));
                }
                return true;
            }
            else
            {
                // valM<0
                Bez2D bezRev=this.Reversed as Bez2D;
                if (!bezRev.ParamFromSupport(1-parSupport.Val, out parsBez))
                    return false;
                if (parsBez==null)
                    return true;
                for (int iParBez=0; iParBez<parsBez.Length; iParBez++)
                {
                    parsBez[iParBez].Reverse(1);
                }
                return true;
            }
            throw new ExceptionGMath("Bez2D","ParamFromSupport","NOT IMPLEMENTED");
            //return false;
        }
Example #14
0
 public bool IsEvaluableWide(Param par)
 {
     return((par.IsValid) && (!par.IsDegen));
 }
Example #15
0
 public double Curvature(Param par)
 {
     return(0);
 }
Example #16
0
 public double CurveLength(Param parS, Param parE)
 {
     throw new ExceptionGMath("Contour","CurveLength","NOT IMPLEMENTED");
     //return 0;
 }
Example #17
0
 VecD Curve.DirNorm(Param par)
 {
     return(((LCurve)this).DirNorm);
 }
Example #18
0
 /*
  *        CONSTRUCTORS
  */
 public IntersD0(Param parA, Param parB, VecD pnt, bool includeBezSI)
 {
     // COPY
     this.ipi=new InfoParamInters(parA,parB);
     this.pntInters=new VecD(pnt);
     this.includeBezSI=includeBezSI;
 }
Example #19
0
 public BCurve SubCurve(Param parA, Param parB)
 {
     if ((!this.IsEvaluableStrict(parA))||(!this.IsEvaluableStrict(parB)))
         return null;
     return new DegenD(this.cp);
 }
Example #20
0
 /*
  *        CONSTRUCTORS
  */
 public IntersD1(Param parInA, Param parInB, 
     Param parOutA, Param parOutB, 
     Curve curveInters, bool includeBezSI)
 {
     this.ipis=new InfoParamInters[2];
     this.ipis[0]=new InfoParamInters(parInA, parInB);
     this.ipis[1]=new InfoParamInters(parOutA, parOutB);
     this.curveInters=(curveInters==null)? null: curveInters.Copy();
     this.includeBezSI=includeBezSI;
 }
Example #21
0
 VecD Curve.DirNorm(Param par)
 {
     return ((LCurve)this).DirNorm;
 }
Example #22
0
 public bool IsEvaluableWide(Param par)
 {
     throw new ExceptionGMath("DegenD","IsEvaluableWide","NOT IMPLEMENTED");
     //return false;    
 }        
Example #23
0
        public Param.TypeParam ParamClassify(Param par)
        {
            par.Clip(-Param.Infinity,Param.Infinity);
            par.Round(0);

            double val=par.Val;
            if (val==Param.Degen)
                return Param.TypeParam.Invalid;    
            if (val==Param.Invalid)
                return Param.TypeParam.Invalid;
            if (val<0) 
            {
                return Param.TypeParam.Before;
            }
            else if (val==0) 
            {
                return Param.TypeParam.Start;
            }
            else
            {
                return Param.TypeParam.Inner;
            }
        }
Example #24
0
 public VecD DirTang(Param par)
 {
     return null;
 }
Example #25
0
 public bool IsEvaluableStrict(Param par)
 {
     if ((par.IsDegen)||(!par.IsValid))
         return false;
     par.Round(this.ParamStart,this.ParamEnd);
     if (par.Val<0)
         return false;
     return true;
 }
Example #26
0
 public VecD DirNorm(Param par)
 {
     return null;
 }
Example #27
0
 public double CurveLength(Param parS, Param parE)
 {
     if ((!this.IsEvaluableStrict(parS))||(!this.IsEvaluableStrict(parE)))
     {
         throw new ExceptionGMath("RayD","CurveLength",null);
     }
     double length=Math.Abs(parE-parS)*(this.cp[1]-this.cp[0]).Norm;
     if (Math.Abs(length)>=MConsts.Infinity)
     {
         length=MConsts.Infinity*Math.Sign(length);
     }
     return length;
 }
Example #28
0
 public double CurveLength(Param parS, Param parE)
 {
     return 0;
 }
Example #29
0
 public Param.TypeParam ParamClassify(Param par)
 {
     throw new ExceptionGMath("Contour","ParamClassify","NOT IMPLEMENTED");
     //return Param.TypeParam.Invalid;
 }
Example #30
0
 public double Curvature(Param par)
 {
     return MConsts.Infinity;
 }
Example #31
0
 public VecD DirNorm(Param par)
 {
     throw new ExceptionGMath("Contour","DirNorm","NOT IMPLEMENTED");
     //return null;
 }
Example #32
0
 public Param.TypeParam ParamClassify(Param par)
 {
     throw new ExceptionGMath("DegenD","ParamClassify","NOT IMPLEMENTED");
     //return Param.TypeParam.Inner;
 }
Example #33
0
 public double Curvature(Param par)
 {
     throw new ExceptionGMath("Contour","Curvature","NOT IMPLEMENTED");
     //return 0;
 }
Example #34
0
 VecD Curve.DirTang(Param par)
 {
     return(((LCurve)this).DirTang);
 }