1# Checks whether theCurve has a loop/bend 2# Use: CheckLoops curve CosMaxAngle [theNbPoints]} 3# theNbPoints sets the interval of discretization; 4# theCosMaxAngle sets the maximal rotation angle between two adjacent segments. This value must be equal to the cosine of this angle. 5 6help CheckLoops {curve CosMaxAngle theNbPoints } 7proc CheckLoops {theCurve {theCosMaxAngle 0.8} {theNbPoints 1000.0}} { 8 upvar #0 $theCurve aCurve 9 bounds aCurve U1 U2 10 11 set delta [dval (U2-U1)/$theNbPoints] 12 cvalue aCurve [dval U1] xp yp zp dx1 dy1 dz1 13 14 for {set p [dval U1]} {$p <= [dval U2]} {set p [expr $p + $delta]} { 15 cvalue aCurve $p xp yp zp dx2 dy2 dz2 16 17 #Check if the angle between the vectors {dx1 dy1 dz1} and {dx2 dy2 dz2} is less than 30deg. 18 set nv1 [ dval dx1*dx1+dy1*dy1+dz1*dz1 ] 19 set nv2 [ dval dx2*dx2+dy2*dy2+dz2*dz2 ] 20 set dp [ dval dx1*dx2+dy2*dy2+dz1*dz2 ] 21 22 if {$dp < [ expr $theCosMaxAngle * sqrt($nv1 * $nv2) ] } { 23 puts "Error: The curve $theCurve is possible to have a bend at parameter $p. Please check carefully" 24 } 25 26 dset dx1 dx2 27 dset dy1 dy2 28 dset dz1 dz2 29 } 30} 31 32# General check of the result of geometrical intersection 33help CheckIntersectionResult { surf1 surf2 ListOfCurves NbPoints TolerS1 TolerS2 } 34proc CheckIntersectionResult {theSurf1 theSurf2 theListOfCurves theNbPoints theTolerS1 theTolerS2} { 35 upvar #0 $theSurf1 s1 36 upvar #0 $theSurf2 s2 37 38 foreach a $theListOfCurves { 39 puts "** Check of $a **" 40 upvar #0 $a aCurve 41 bounds aCurve U1 U2 42 43 if {[dval U2-U1] < 1.0e-9} { 44 puts "Error: Wrong range of $a" 45 } 46 47 xdistcs aCurve s1 U1 U2 $theNbPoints $theTolerS1 48 xdistcs aCurve s2 U1 U2 $theNbPoints $theTolerS2 49 } 50} 51 52# Check whether given list contain overlapped curves 53help CheckOverlapIntCurves { theListOfCurves } 54proc CheckOverlapIntCurves { theListOfCurves {theTolerance 1.0e-7} } { 55 set NbEdges [expr [llength $theListOfCurves] - 1 ] 56 for { set i1 0 } { $i1 < $NbEdges } { incr i1 } { 57 for { set i2 [expr $i1 + 1] } { $i2 <= $NbEdges } { incr i2 } { 58 upvar #0 [ lindex $theListOfCurves $i1 ] aCurve1 59 upvar #0 [ lindex $theListOfCurves $i2 ] aCurve2 60 61 mkedge e1 aCurve1 62 mkedge e2 aCurve2 63 64 set coe [ checkoverlapedges e1 e2 $theTolerance ] 65 66 if { [regexp "Edges are not overlapped" $coe] != 1 } { 67 set cIdx1 [ expr $i1 + 1 ] 68 set cIdx2 [ expr $i2 + 1 ] 69 70 puts "Error: Curves $cIdx1 and $cIdx2 are overlapped" 71 } 72 } 73 } 74} 75