home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / 3d / irit / scripts / symbolic.irt < prev    next >
Encoding:
Text File  |  1994-09-17  |  7.5 KB  |  270 lines

  1. #
  2. # Some tests for symbolic computation.
  3. #
  4. #                        Gershon Elber, Nov. 1992
  5. #
  6.  
  7. #
  8. # Set display to on to view some results, off to view nothing.
  9. #
  10. display = on;
  11.  
  12. #
  13. # The symbolic computation below is faster this way.
  14. #
  15. iritstate( "InterpProd", off );
  16.  
  17. #
  18. # Control the surface to polygons subdivison resolution, and isolines gen.
  19. #
  20. save_res = resolution;
  21. resolution = 20;
  22. if ( machine == msdos, (resolution = 5) );
  23.  
  24. s45 = sin( pi / 4 );
  25.  
  26. #
  27. # Simple polynomial surface.
  28. #
  29. sbsp = list ( list( ctlpt( E3, 0.0, 0.0, 1.0 ),
  30.                 ctlpt( E3, 0.0, 1.0, 0.8 ),
  31.                 ctlpt( E3, 0.0, 2.1, 1.0 ) ),
  32.               list( ctlpt( E3, 1.0, 0.0, 2.0 ),
  33.                 ctlpt( E3, 1.1, 1.0, 1.0 ),
  34.                 ctlpt( E3, 1.0, 2.1, 2.0 ) ),
  35.               list( ctlpt( E3, 2.0, 0.0, 1.0 ),
  36.                 ctlpt( E3, 2.0, 1.0, 0.8 ),
  37.                 ctlpt( E3, 2.0, 2.1, 1.0 ) ),
  38.               list( ctlpt( E3, 3.0, 0.0, 2.0 ),
  39.                 ctlpt( E3, 3.1, 1.0, 1.8 ),
  40.                 ctlpt( E3, 3.0, 2.1, 2.0 ) ) );
  41. s = sbspline( 3, 4, sbsp, list( list( KV_OPEN ),
  42.                 list( KV_OPEN ) ) );
  43. color( s, white );
  44.  
  45. dus = sderive( s, ROW ) * scale( vector( 0.5, 0.5, 0.5 ) );
  46. color( dus, green );
  47. dvs = sderive( s, COL ) * scale( vector( 0.5, 0.5, 0.5 ) );
  48. color( dvs, magenta );
  49. if ( display == on, viewobj( axes ):
  50.             viewstate( "DSrfMesh" ):
  51.             interact( list( axes, s, dus, dvs ) ) );
  52.  
  53. ns = snrmlsrf(s) * scale( vector( 0.3, 0.3, 0.3 ) );
  54. color( ns, green );
  55. if ( display == on, interact( list( axes, s, ns ) ) );
  56.  
  57. # Compute the normal at the center of the surface, in three ways.
  58. coerce( seval( dus, 0.5, 0.5 ), VECTOR_TYPE ) ^
  59. coerce( seval( dvs, 0.5, 0.5 ), VECTOR_TYPE );
  60. coerce( seval( ns, 0.5, 0.5 ), VECTOR_TYPE );
  61. snormal( s, 0.5, 0.5 );
  62.  
  63. #
  64. # A (portion of) sphere (rational surface).
  65. #
  66. halfcirc = cbspline( 3,
  67.              list( ctlpt( P3, 1.0,  0.0, 0.0,  1.0 ),
  68.                    ctlpt( P3, s45, -s45, 0.0,  s45 ),
  69.                    ctlpt( P3, 1.0, -1.0, 0.0,  0.0 ),
  70.                    ctlpt( P3, s45, -s45, 0.0, -s45 ),
  71.                ctlpt( P3, 1.0,  0.0, 0.0, -1.0 ) ),
  72.              list( 0, 0, 0, 1, 1, 2, 2, 2 ) );
  73. color( halfcirc, white );
  74.  
  75. s = surfrev( halfcirc );
  76. color( s, white );
  77.  
  78. dus = sderive(s, ROW);
  79. color( dus, green );
  80. dvs = sderive(s, COL);
  81. color( dvs, magenta );
  82. if ( display == on, interact( list( axes, s, dus, dvs ) ) );
  83.  
  84. ns = snrmlsrf(s);
  85. color( ns, green );
  86. if ( display == on, interact( list( axes, s, ns ) ) );
  87.  
  88. s = sregion( sregion( s, ROW, 0.2, 0.5 ), COL, 0.0, 2.0 );
  89. color( s, white );
  90.  
  91. dus = sderive(s, ROW);
  92. color( dus, green );
  93. dvs = sderive(s, COL);
  94. color( dvs, magenta );
  95. if ( display == on, interact( list( axes, s, dus, dvs ) ) );
  96.  
  97. ns = snrmlsrf(s);
  98. color( ns, green );
  99. if ( display == on, interact( list( axes, s, ns ) ) );
  100.  
  101. #
  102. # A Glass.
  103. #
  104. gcross = cbspline( 3,
  105.            list( ctlpt( E3, 0.3, 0.0, 0.0 ),
  106.                  ctlpt( E3, 0.3, 0.0, 0.05 ),
  107.                  ctlpt( E3, 0.1, 0.0, 0.05 ),
  108.                  ctlpt( E3, 0.1, 0.0, 0.4 ),
  109.                  ctlpt( E3, 0.5, 0.0, 0.4 ),
  110.                  ctlpt( E3, 0.6, 0.0, 0.8 ) ),
  111.            list( 0, 0, 0, 1, 2, 3, 4, 4, 4 ) );
  112. color( gcross, white );
  113. s = surfrev( gcross );
  114. color( s, white );
  115.  
  116. dus = sderive(s, ROW);
  117. color( dus, green );
  118. dvs = sderive(s, COL);
  119. color( dvs, magenta );
  120. if ( display == on, interact( list( axes, s, dus, dvs ) ) );
  121.  
  122. ns = snrmlsrf(s);
  123. color( ns, green );
  124. if ( display == on, interact( list( axes, s, ns ) ) );
  125.  
  126. #
  127. # Compute two surfaces, one is an offset approximation to the surface and
  128. # the other is just a translation. Then compute the distance square scalar
  129. # surface between them and the original surface. With the data below both
  130. # Should have a distance square of 3 (if exact, the offset is obviously not).
  131. #
  132. s1 = s * trans( vector( 1, -1, 1 ) );
  133. color( s1, green );
  134.  
  135. s2 = offset( s, sqrt( 3 ), 1.0, off );
  136. color( s2, yellow );
  137.  
  138. iritState("DumpLevel", 2);
  139. distsqr1 = symbdprod( symbdiff( s, s1 ), symbdiff( s, s1 ) );
  140. distsqr2 = symbdprod( symbdiff( s, s2 ), symbdiff( s, s2 ) );
  141. distsqr1;
  142. distsqr2;
  143. iritState("DumpLevel", 1);
  144.  
  145. free( s );
  146. free( s1 );
  147. free( s2 );
  148. free( distsqr1 );
  149. free( distsqr2 );
  150. free( dus );
  151. free( dvs );
  152. free( ns );
  153.  
  154. #
  155. # Curve curve composition.
  156. #
  157. iritState("DumpLevel", 9);
  158. viewstate( "DSrfMesh" );
  159.  
  160. crv1 = circle( vector( 0.0, 0.0, 0.0 ), 0.8 );
  161.  
  162. crv2 = cbspline( 5,
  163.          list( ctlpt( E1, 0.0 ),
  164.                ctlpt( E1, 1.0 ),
  165.                ctlpt( E1, 2.0 ),
  166.                ctlpt( E1, 3.0 ),
  167.                ctlpt( E1, 4.0 ) ),
  168.          list( KV_OPEN ) );
  169. crv1c = compose( crv1, crv2 );
  170. crvsWsegs = nil();
  171. crvsBsegs = nil();
  172. NumSegs = 10.0;
  173. for ( i = 1, 1, NumSegs,
  174.     snoc( cregion( crv1c, ( i - 1.0 ) / NumSegs, ( i - 0.5 ) / NumSegs ),
  175.           crvsWsegs ): 
  176.     snoc( cregion( crv1c, ( i - 0.5 ) / NumSegs, ( i - 0.0 ) / NumSegs ),
  177.           crvsBsegs )
  178.     );
  179. color( crvsWsegs, red );
  180. color( crvsBsegs, yellow );
  181. if ( display == on, interact( list( crvsBsegs, crvsWsegs ) ) );
  182.  
  183. crv2 = cbspline( 5,
  184.          list( ctlpt( E1, 0.0 ),
  185.                ctlpt( E1, 0.0 ),
  186.                ctlpt( E1, 0.0 ),
  187.                ctlpt( E1, 0.0 ),
  188.                ctlpt( E1, 4.0 ) ),
  189.          list( KV_OPEN ) );
  190. crvs = list( crv1, crv2 );
  191. crv1c = compose( crv1, crv2 );
  192. crvsWsegs = nil();
  193. crvsBsegs = nil();
  194. NumSegs = 10.0;
  195. for ( i = 1, 1, NumSegs,
  196.     snoc( cregion( crv1c, ( i - 1.0 ) / NumSegs, ( i - 0.5 ) / NumSegs ),
  197.           crvsWsegs ): 
  198.         snoc( cregion( crv1c, ( i - 0.5 ) / NumSegs, ( i - 0.0 ) / NumSegs ),
  199.           crvsBsegs )
  200.     );
  201. color( crvsWsegs, red );
  202. color( crvsBsegs, yellow );
  203. if ( display == on, interact( list( crvsBsegs, crvsWsegs ) ) );
  204.  
  205. crv2 = cbspline( 5,
  206.          list( ctlpt( E1, 0.0 ),
  207.                ctlpt( E1, 4.0 ),
  208.                ctlpt( E1, 4.0 ),
  209.                ctlpt( E1, 4.0 ),
  210.                ctlpt( E1, 4.0 ) ),
  211.          list( KV_OPEN ) );
  212. crv1c = compose( crv1, crv2 );
  213. crvsWsegs = nil();
  214. crvsBsegs = nil();
  215. NumSegs = 10.0;
  216. for ( i = 1, 1, NumSegs,
  217.     snoc( cregion( crv1c, ( i - 1.0 ) / NumSegs, ( i - 0.5 ) / NumSegs ),
  218.           crvsWsegs ): 
  219.     snoc( cregion( crv1c, ( i - 0.5 ) / NumSegs, ( i - 0.0 ) / NumSegs ),
  220.           crvsBsegs )
  221.     );
  222. color( crvsWsegs, red );
  223. color( crvsBsegs, yellow );
  224. if ( display == on, interact( list( crvsBsegs, crvsWsegs ) ) );
  225.  
  226. srf = sbezier( list( list( ctlpt( E3, 0.0, 0.0, 0.0 ),
  227.                    ctlpt( E3, 0.0, 0.5, 1.0 ),
  228.                    ctlpt( E3, 0.0, 1.0, 0.0 ) ),
  229.                  list( ctlpt( E3, 0.5, 0.0, 1.0 ),
  230.                    ctlpt( E3, 0.5, 0.5, 0.0 ),
  231.                    ctlpt( E3, 0.5, 1.0, 1.0 ) ),
  232.                  list( ctlpt( E3, 1.0, 0.0, 1.0 ),
  233.                    ctlpt( E3, 1.0, 0.5, 0.0 ),
  234.                    ctlpt( E3, 1.0, 1.0, 1.0 ) ) ) );
  235. crv = circle( vector( 0.0, 0.0, 1.0 ), 0.4 );
  236. crv = coerce( crv * trans( vector( 0.5, 0.5, 0.0 ) ), p2 );
  237. ccrv = compose( srf, crv );
  238. if ( display == on, interact( list( srf, crv, ccrv ) ) );
  239. crv = circle( vector( 0.0, 0.0, 1.0 ), 0.4 );
  240. crv = coerce( crv * trans( vector( 0.5, 0.5, 0.0 ) ), e2 );
  241. ccrv = compose( srf, crv );
  242. if ( display == on, interact( list( srf, crv, ccrv ) ) );
  243.  
  244. srf = sbezier( list( list( ctlpt( E3, 0.0, 0.0, 0.0 ),
  245.                    ctlpt( E3, 0.0, 0.5, 1.0 ),
  246.                    ctlpt( E3, 0.0, 1.0, 0.0 ) ),
  247.                  list( ctlpt( E3, 0.5, 0.0, 1.0 ),
  248.                    ctlpt( E3, 0.5, 0.5, 0.0 ),
  249.                    ctlpt( E3, 0.5, 1.0, 1.0 ) ),
  250.                  list( ctlpt( E3, 1.0, 0.0, 1.0 ),
  251.                    ctlpt( E3, 1.0, 0.5, 0.0 ),
  252.                    ctlpt( E3, 1.0, 1.0, 1.0 ) ),
  253.                  list( ctlpt( E3, 1.5, 0.0, 0.0 ),
  254.                    ctlpt( E3, 1.5, 0.5, 1.0 ),
  255.                    ctlpt( E3, 1.5, 1.0, 0.0 ) ) ) );
  256. crv = circle( vector( 0.0, 0.0, 1.0 ), 0.4 );
  257. crv = coerce( crv * trans( vector( 0.5, 0.5, 0.0 ) ), p2 );
  258. ccrv = compose( srf, crv );
  259. if ( display == on, interact( list( srf, crv, ccrv ) ) );
  260.  
  261. free(srf);
  262. free(crv);
  263. free(crv1);
  264. free(crv1c);
  265. free(crv2);
  266. free(ccrv);
  267. free(crvsWsegs);
  268. free(crvsBsegs);
  269. iritState("DumpLevel", 1);
  270.