0028599: Replacement of old Boolean operations with new ones in BRepProj_Projection...
[occt.git] / tests / lowalgos / extcs / circ_sph_touch
1 puts "======================="
2 puts "Test for Circle/Sphere extrema algorithm"
3 puts "Touch case (circle is just touching the sphere)"
4 puts "======================="
5 puts ""
6
7 # Make sphere
8 set x0 0.
9 set y0 0.
10 set z0 0.
11 set sph_radius 10.
12 sphere s $x0 $y0 $z0 $sph_radius
13
14 # Initially the circle will be made at the same place as sphere with different radius
15 # and will shifted many times to touch the sphere.
16 # The distance should always be close to zero.
17
18 # Number of different radius of initial circle
19 set nb_radius 7
20 # Number of circle's rotations 
21 set nbstep 8
22 set angle [expr 180. / $nbstep]
23
24 # Iteration step
25 set iStep 1
26
27 for {set i 1} {$i < $nb_radius} {incr i} {
28   set circ_radius [expr $i*2.]
29   if {$circ_radius == $sph_radius} {
30     set circ_radius [expr $circ_radius + 0.1]
31   }
32   circle c $x0 $y0 $z0 0 0 1 $circ_radius
33
34   # Circle will be rotated around the line
35   line rotation_line $x0 $y0 $z0 1 0 0
36   # Line rotation
37   for {set j 1} {$j <= $nbstep} {incr j} {
38     rotate rotation_line $x0 $y0 $z0 0 0 1 $angle
39     
40     # Get direction for circle's rotation
41     regexp {Axis   :([-0-9.+eE]*), ([-0-9.+eE]*), ([-0-9.+eE]*)} [dump rotation_line] full dx dy dz
42     
43     # Circle rotation
44     copy c c_rotated
45     for {set k 1} {$k <= $nbstep} {incr k} {
46       rotate c_rotated $x0 $y0 $z0 $dx $dy $dz $angle
47       
48       # Get translation axis for the circle
49       regexp {XAxis  :([-0-9.+eE]*), ([-0-9.+eE]*), ([-0-9.+eE]*)} [dump c_rotated] full dxx dxy dxz
50       
51       # Get rotation plane for translation line
52       regexp {YAxis  :([-0-9.+eE]*), ([-0-9.+eE]*), ([-0-9.+eE]*)} [dump c_rotated] full dyx dyy dyz
53       
54       line translation_line $x0 $y0 $z0 $dxx $dxy $dxz
55       
56       for {set n 1} {$n <= $nbstep} {incr n} {
57         rotate translation_line $x0 $y0 $z0 $dyx $dyy $dyz $angle
58         
59         # Get direction for circle's translation
60         regexp {Axis   :([-0-9.+eE]*), ([-0-9.+eE]*), ([-0-9.+eE]*)} [dump translation_line] full dtx dty dtz
61         
62         # Circle's translation
63         copy c_rotated c_shifted
64         translate c_shifted $sph_radius*$dtx $sph_radius*$dty $sph_radius*$dtz 
65     
66         # Shift circle to touch sphere
67         set shift -1
68         repeat 2 {
69           copy c_shifted c_touch
70           translate c_touch $shift*$circ_radius*$dxx $shift*$circ_radius*$dxy $shift*$circ_radius*$dxz
71
72           set log [extrema c_touch s]
73
74           # save each circle if necessary
75           # copy c_touch c_$iStep
76
77           if {![regexp "ext_1" $log]} {
78             if {![regexp "Extrema 1 is point" $log]} {
79               puts "Error: Extrema has not detected the touching case on step $iStep"
80             } else {
81               puts "Check of Step $iStep, min distance  OK"
82             }              
83           } else {
84             set ext_dist [lindex [length ext_1] end]
85             checkreal "Step $iStep, min distance " $ext_dist 0 1.e-7 1.e-7
86           }
87           incr iStep
88           set shift 1
89         }
90       }
91     }
92   }
93 }