/* * METHODS: MISORIENTED */ public bool RayAlmostNormal(out RayD ray, out CParam parStartRay) { ray = null; parStartRay = null; bool isCurveOK = false; int numTrialMax = 100; // TODO: make constant int numTrialCur = 0; while ((!isCurveOK) && (numTrialCur < numTrialMax)) { numTrialCur++; try { int pozKnotStart = rand.Next(this.NumKnot); BCurve curveStart = this.CurveByPoz(pozKnotStart); if (curveStart == null) { pozKnotStart = this.PozNext(pozKnotStart); curveStart = this.CurveByPoz(pozKnotStart); if (curveStart == null) { //Debug.Assert(false, "Contour: RayAlmostNormal"); continue; } } InfoInters inters; if ((!curveStart.IsDegen) && (curveStart.BBox.Diag >= 1 - MConsts.EPS_DEC_WEAK) && (!curveStart.IsSelfInters(out inters))) { double parVal = 0.25 * rand.Next(1, 4); VecD pntStart = curveStart.Evaluate(parVal); VecD dirNorm = curveStart.DirNorm(parVal); if ((pntStart == null) || (dirNorm == null)) { //Debug.Assert(false, "Contour: RayAlmostNormal"); continue; } double angleRot = (rand.NextDouble() - 0.5) * (Math.PI / 5.0); double scale = 100.0; // TODO: make constant VecD dirRay = new VecD(scale * (Math.Cos(angleRot) * dirNorm.X - Math.Sin(angleRot) * dirNorm.Y), scale * (Math.Sin(angleRot) * dirNorm.X + Math.Cos(angleRot) * dirNorm.Y)); bool isChanged; dirRay.FURound(out isChanged); ray = new RayD(pntStart, pntStart + dirRay); parStartRay = new CParam(parVal, this.KnotByPoz(pozKnotStart)); isCurveOK = true; } } catch (ExceptionGMath) { } } return(isCurveOK); }
public bool RayParity(RayD ray, CParam parStartRay, out MConsts.TypeParity typeParity) { /* * ASSUMPTIONS * INPUT: * - (parStartRay==null) is the ray does not start at * the contour * RETURN VALUE; * - (false) in case of real failure; * (true)+(typeParity==Undef) in unclear cases * */ typeParity=MConsts.TypeParity.Undef; ListInfoInters linters=new ListInfoInters(); bool isStartIntersFound=false; for (int pozKnot=0; pozKnot<this.NumKnot; pozKnot++) { BCurve curve=this.CurveByPoz(pozKnot); if (curve!=null) { Knot knot=this.KnotByPoz(pozKnot); int numIntersBefore=linters.Count; if (!Inters.IntersectBL(curve,ray,linters)) { linters.ClearDestroy(); return false; } int numIntersAfter=linters.Count; if (numIntersAfter!=numIntersBefore) { InfoInters inters; if ((curve.IsDegen)||(curve.IsSelfInters(out inters))) { linters.ClearDestroy(); return true; } } bool isRayStartOnCurve=((parStartRay!=null)&& (parStartRay.IndKnot==knot.IndexKnot)); for (int iInters=numIntersBefore; iInters<numIntersAfter; iInters++) { InfoInters inters=linters[iInters] as InfoInters; if (inters.Dim==InfoInters.TypeDim.Dim1) { linters.ClearDestroy(); return true; } IntersD0 intersD0=inters as IntersD0; double parValCurve=intersD0.Ipi.Par(0).Val; double parValRay=intersD0.Ipi.Par(1).Val; if (Math.Abs(parValRay)<MConsts.EPS_DEC) { if ((!isRayStartOnCurve)||(isRayStartOnCurve&&isStartIntersFound)) { linters.ClearDestroy(); return true; } isStartIntersFound=true; } if ((Math.Abs(parValCurve)<MConsts.EPS_DEC_WEAK)|| (Math.Abs(1.0-parValCurve)<MConsts.EPS_DEC_WEAK)) { linters.ClearDestroy(); return true; } VecD dirTangCurve=curve.DirTang(parValCurve); VecD dirTangRay=(ray as LCurve).DirTang; if ((dirTangCurve==null)||(dirTangRay==null)) { linters.ClearDestroy(); return true; } if (Math.Abs(dirTangRay.Cross(dirTangCurve))<MConsts.EPS_DEC_WEAK) { linters.ClearDestroy(); return true; } } if ((isRayStartOnCurve)&&(!isStartIntersFound)) { linters.ClearDestroy(); return true; } } } int numIntersAll=(isStartIntersFound)? linters.Count-1: linters.Count; typeParity=(numIntersAll%2==0)? MConsts.TypeParity.Even: MConsts.TypeParity.Odd; linters.ClearDestroy(); return true; }
/* * METHODS: MISORIENTED */ public bool RayAlmostNormal(out RayD ray, out CParam parStartRay) { ray=null; parStartRay=null; bool isCurveOK=false; int numTrialMax=100; // TODO: make constant int numTrialCur=0; while ((!isCurveOK)&&(numTrialCur<numTrialMax)) { numTrialCur++; try { int pozKnotStart=rand.Next(this.NumKnot); BCurve curveStart=this.CurveByPoz(pozKnotStart); if (curveStart==null) { pozKnotStart=this.PozNext(pozKnotStart); curveStart=this.CurveByPoz(pozKnotStart); if (curveStart==null) { //Debug.Assert(false, "Contour: RayAlmostNormal"); continue; } } InfoInters inters; if ((!curveStart.IsDegen)&&(curveStart.BBox.Diag>=1-MConsts.EPS_DEC_WEAK)&& (!curveStart.IsSelfInters(out inters))) { double parVal=0.25*rand.Next(1,4); VecD pntStart=curveStart.Evaluate(parVal); VecD dirNorm=curveStart.DirNorm(parVal); if ((pntStart==null)||(dirNorm==null)) { //Debug.Assert(false, "Contour: RayAlmostNormal"); continue; } double angleRot=(rand.NextDouble()-0.5)*(Math.PI/5.0); double scale=100.0; // TODO: make constant VecD dirRay=new VecD(scale*(Math.Cos(angleRot)*dirNorm.X-Math.Sin(angleRot)*dirNorm.Y), scale*(Math.Sin(angleRot)*dirNorm.X+Math.Cos(angleRot)*dirNorm.Y)); bool isChanged; dirRay.FURound(out isChanged); ray=new RayD(pntStart,pntStart+dirRay); parStartRay=new CParam(parVal,this.KnotByPoz(pozKnotStart)); isCurveOK=true; } } catch (ExceptionGMath) { } } return isCurveOK; }
public RayD(RayD ray) : this() { this.cp[0]=new VecD(ray.Start); this.cp[1]=new VecD(ray.End); }
public RayD.TypeParity RayParity(RayD ray, bool isStartOnGeom) { throw new ExceptionGMath("RayD","RayParity","NOT IMPLEMENTED"); //return RayD.TypeParity.ParityUndef; }
public RayD.TypeParity RayParity(RayD ray, bool isStartOnGeom) { throw new ExceptionGMath("Bez2D", "RayParity", "NOT IMPLEMENTED"); //return RayD.TypeParity.ParityUndef; }
public RayD(RayD ray) : this() { this.cp[0] = new VecD(ray.Start); this.cp[1] = new VecD(ray.End); }
public bool RayParity(RayD ray, CParam parStartRay, out MConsts.TypeParity typeParity) { /* * ASSUMPTIONS * INPUT: * - (parStartRay==null) is the ray does not start at * the contour * RETURN VALUE; * - (false) in case of real failure; * (true)+(typeParity==Undef) in unclear cases * */ typeParity = MConsts.TypeParity.Undef; ListInfoInters linters = new ListInfoInters(); bool isStartIntersFound = false; for (int pozKnot = 0; pozKnot < this.NumKnot; pozKnot++) { BCurve curve = this.CurveByPoz(pozKnot); if (curve != null) { Knot knot = this.KnotByPoz(pozKnot); int numIntersBefore = linters.Count; if (!Inters.IntersectBL(curve, ray, linters)) { linters.ClearDestroy(); return(false); } int numIntersAfter = linters.Count; if (numIntersAfter != numIntersBefore) { InfoInters inters; if ((curve.IsDegen) || (curve.IsSelfInters(out inters))) { linters.ClearDestroy(); return(true); } } bool isRayStartOnCurve = ((parStartRay != null) && (parStartRay.IndKnot == knot.IndexKnot)); for (int iInters = numIntersBefore; iInters < numIntersAfter; iInters++) { InfoInters inters = linters[iInters] as InfoInters; if (inters.Dim == InfoInters.TypeDim.Dim1) { linters.ClearDestroy(); return(true); } IntersD0 intersD0 = inters as IntersD0; double parValCurve = intersD0.Ipi.Par(0).Val; double parValRay = intersD0.Ipi.Par(1).Val; if (Math.Abs(parValRay) < MConsts.EPS_DEC) { if ((!isRayStartOnCurve) || (isRayStartOnCurve && isStartIntersFound)) { linters.ClearDestroy(); return(true); } isStartIntersFound = true; } if ((Math.Abs(parValCurve) < MConsts.EPS_DEC_WEAK) || (Math.Abs(1.0 - parValCurve) < MConsts.EPS_DEC_WEAK)) { linters.ClearDestroy(); return(true); } VecD dirTangCurve = curve.DirTang(parValCurve); VecD dirTangRay = (ray as LCurve).DirTang; if ((dirTangCurve == null) || (dirTangRay == null)) { linters.ClearDestroy(); return(true); } if (Math.Abs(dirTangRay.Cross(dirTangCurve)) < MConsts.EPS_DEC_WEAK) { linters.ClearDestroy(); return(true); } } if ((isRayStartOnCurve) && (!isStartIntersFound)) { linters.ClearDestroy(); return(true); } } } int numIntersAll = (isStartIntersFound)? linters.Count - 1: linters.Count; typeParity = (numIntersAll % 2 == 0)? MConsts.TypeParity.Even: MConsts.TypeParity.Odd; linters.ClearDestroy(); return(true); }