home *** CD-ROM | disk | FTP | other *** search
- #
- # Some tests for symbolic computation.
- #
- # Gershon Elber, Nov. 1992
- #
-
- #
- # Set display to on to view some results, off to view nothing.
- #
- display = on;
-
- #
- # The symbolic computation below is faster this way.
- #
- iritstate( "InterpProd", off );
-
- #
- # Control the surface to polygons subdivison resolution, and isolines gen.
- #
- save_res = resolution;
- resolution = 20;
- if ( machine == msdos, (resolution = 5) );
-
- s45 = sin( pi / 4 );
-
- #
- # Simple polynomial surface.
- #
- sbsp = list ( list( ctlpt( E3, 0.0, 0.0, 1.0 ),
- ctlpt( E3, 0.0, 1.0, 0.8 ),
- ctlpt( E3, 0.0, 2.1, 1.0 ) ),
- list( ctlpt( E3, 1.0, 0.0, 2.0 ),
- ctlpt( E3, 1.1, 1.0, 1.0 ),
- ctlpt( E3, 1.0, 2.1, 2.0 ) ),
- list( ctlpt( E3, 2.0, 0.0, 1.0 ),
- ctlpt( E3, 2.0, 1.0, 0.8 ),
- ctlpt( E3, 2.0, 2.1, 1.0 ) ),
- list( ctlpt( E3, 3.0, 0.0, 2.0 ),
- ctlpt( E3, 3.1, 1.0, 1.8 ),
- ctlpt( E3, 3.0, 2.1, 2.0 ) ) );
- s = sbspline( 3, 4, sbsp, list( list( KV_OPEN ),
- list( KV_OPEN ) ) );
- color( s, white );
-
- dus = sderive( s, ROW ) * scale( vector( 0.5, 0.5, 0.5 ) );
- color( dus, green );
- dvs = sderive( s, COL ) * scale( vector( 0.5, 0.5, 0.5 ) );
- color( dvs, magenta );
- if ( display == on, viewobj( axes ):
- viewstate( "DSrfMesh" ):
- interact( list( axes, s, dus, dvs ) ) );
-
- ns = snrmlsrf(s) * scale( vector( 0.3, 0.3, 0.3 ) );
- color( ns, green );
- if ( display == on, interact( list( axes, s, ns ) ) );
-
- # Compute the normal at the center of the surface, in three ways.
- coerce( seval( dus, 0.5, 0.5 ), VECTOR_TYPE ) ^
- coerce( seval( dvs, 0.5, 0.5 ), VECTOR_TYPE );
- coerce( seval( ns, 0.5, 0.5 ), VECTOR_TYPE );
- snormal( s, 0.5, 0.5 );
-
- #
- # A (portion of) sphere (rational surface).
- #
- halfcirc = cbspline( 3,
- list( ctlpt( P3, 1.0, 0.0, 0.0, 1.0 ),
- ctlpt( P3, s45, -s45, 0.0, s45 ),
- ctlpt( P3, 1.0, -1.0, 0.0, 0.0 ),
- ctlpt( P3, s45, -s45, 0.0, -s45 ),
- ctlpt( P3, 1.0, 0.0, 0.0, -1.0 ) ),
- list( 0, 0, 0, 1, 1, 2, 2, 2 ) );
- color( halfcirc, white );
-
- s = surfrev( halfcirc );
- color( s, white );
-
- dus = sderive(s, ROW);
- color( dus, green );
- dvs = sderive(s, COL);
- color( dvs, magenta );
- if ( display == on, interact( list( axes, s, dus, dvs ) ) );
-
- ns = snrmlsrf(s);
- color( ns, green );
- if ( display == on, interact( list( axes, s, ns ) ) );
-
- s = sregion( sregion( s, ROW, 0.2, 0.5 ), COL, 0.0, 2.0 );
- color( s, white );
-
- dus = sderive(s, ROW);
- color( dus, green );
- dvs = sderive(s, COL);
- color( dvs, magenta );
- if ( display == on, interact( list( axes, s, dus, dvs ) ) );
-
- ns = snrmlsrf(s);
- color( ns, green );
- if ( display == on, interact( list( axes, s, ns ) ) );
-
- #
- # A Glass.
- #
- gcross = cbspline( 3,
- list( ctlpt( E3, 0.3, 0.0, 0.0 ),
- ctlpt( E3, 0.3, 0.0, 0.05 ),
- ctlpt( E3, 0.1, 0.0, 0.05 ),
- ctlpt( E3, 0.1, 0.0, 0.4 ),
- ctlpt( E3, 0.5, 0.0, 0.4 ),
- ctlpt( E3, 0.6, 0.0, 0.8 ) ),
- list( 0, 0, 0, 1, 2, 3, 4, 4, 4 ) );
- color( gcross, white );
- s = surfrev( gcross );
- color( s, white );
-
- dus = sderive(s, ROW);
- color( dus, green );
- dvs = sderive(s, COL);
- color( dvs, magenta );
- if ( display == on, interact( list( axes, s, dus, dvs ) ) );
-
- ns = snrmlsrf(s);
- color( ns, green );
- if ( display == on, interact( list( axes, s, ns ) ) );
-
- #
- # Compute two surfaces, one is an offset approximation to the surface and
- # the other is just a translation. Then compute the distance square scalar
- # surface between them and the original surface. With the data below both
- # Should have a distance square of 3 (if exact, the offset is obviously not).
- #
- s1 = s * trans( vector( 1, -1, 1 ) );
- color( s1, green );
-
- s2 = offset( s, sqrt( 3 ), 1.0, off );
- color( s2, yellow );
-
- iritState("DumpLevel", 2);
- distsqr1 = symbdprod( symbdiff( s, s1 ), symbdiff( s, s1 ) );
- distsqr2 = symbdprod( symbdiff( s, s2 ), symbdiff( s, s2 ) );
- distsqr1;
- distsqr2;
- iritState("DumpLevel", 1);
-
- free( s );
- free( s1 );
- free( s2 );
- free( distsqr1 );
- free( distsqr2 );
- free( dus );
- free( dvs );
- free( ns );
-
- #
- # Curve curve composition.
- #
- iritState("DumpLevel", 9);
- viewstate( "DSrfMesh" );
-
- crv1 = circle( vector( 0.0, 0.0, 0.0 ), 0.8 );
-
- crv2 = cbspline( 5,
- list( ctlpt( E1, 0.0 ),
- ctlpt( E1, 1.0 ),
- ctlpt( E1, 2.0 ),
- ctlpt( E1, 3.0 ),
- ctlpt( E1, 4.0 ) ),
- list( KV_OPEN ) );
- crv1c = compose( crv1, crv2 );
- crvsWsegs = nil();
- crvsBsegs = nil();
- NumSegs = 10.0;
- for ( i = 1, 1, NumSegs,
- snoc( cregion( crv1c, ( i - 1.0 ) / NumSegs, ( i - 0.5 ) / NumSegs ),
- crvsWsegs ):
- snoc( cregion( crv1c, ( i - 0.5 ) / NumSegs, ( i - 0.0 ) / NumSegs ),
- crvsBsegs )
- );
- color( crvsWsegs, red );
- color( crvsBsegs, yellow );
- if ( display == on, interact( list( crvsBsegs, crvsWsegs ) ) );
-
- crv2 = cbspline( 5,
- list( ctlpt( E1, 0.0 ),
- ctlpt( E1, 0.0 ),
- ctlpt( E1, 0.0 ),
- ctlpt( E1, 0.0 ),
- ctlpt( E1, 4.0 ) ),
- list( KV_OPEN ) );
- crvs = list( crv1, crv2 );
- crv1c = compose( crv1, crv2 );
- crvsWsegs = nil();
- crvsBsegs = nil();
- NumSegs = 10.0;
- for ( i = 1, 1, NumSegs,
- snoc( cregion( crv1c, ( i - 1.0 ) / NumSegs, ( i - 0.5 ) / NumSegs ),
- crvsWsegs ):
- snoc( cregion( crv1c, ( i - 0.5 ) / NumSegs, ( i - 0.0 ) / NumSegs ),
- crvsBsegs )
- );
- color( crvsWsegs, red );
- color( crvsBsegs, yellow );
- if ( display == on, interact( list( crvsBsegs, crvsWsegs ) ) );
-
- crv2 = cbspline( 5,
- list( ctlpt( E1, 0.0 ),
- ctlpt( E1, 4.0 ),
- ctlpt( E1, 4.0 ),
- ctlpt( E1, 4.0 ),
- ctlpt( E1, 4.0 ) ),
- list( KV_OPEN ) );
- crv1c = compose( crv1, crv2 );
- crvsWsegs = nil();
- crvsBsegs = nil();
- NumSegs = 10.0;
- for ( i = 1, 1, NumSegs,
- snoc( cregion( crv1c, ( i - 1.0 ) / NumSegs, ( i - 0.5 ) / NumSegs ),
- crvsWsegs ):
- snoc( cregion( crv1c, ( i - 0.5 ) / NumSegs, ( i - 0.0 ) / NumSegs ),
- crvsBsegs )
- );
- color( crvsWsegs, red );
- color( crvsBsegs, yellow );
- if ( display == on, interact( list( crvsBsegs, crvsWsegs ) ) );
-
- srf = sbezier( list( list( ctlpt( E3, 0.0, 0.0, 0.0 ),
- ctlpt( E3, 0.0, 0.5, 1.0 ),
- ctlpt( E3, 0.0, 1.0, 0.0 ) ),
- list( ctlpt( E3, 0.5, 0.0, 1.0 ),
- ctlpt( E3, 0.5, 0.5, 0.0 ),
- ctlpt( E3, 0.5, 1.0, 1.0 ) ),
- list( ctlpt( E3, 1.0, 0.0, 1.0 ),
- ctlpt( E3, 1.0, 0.5, 0.0 ),
- ctlpt( E3, 1.0, 1.0, 1.0 ) ) ) );
- crv = circle( vector( 0.0, 0.0, 1.0 ), 0.4 );
- crv = coerce( crv * trans( vector( 0.5, 0.5, 0.0 ) ), p2 );
- ccrv = compose( srf, crv );
- if ( display == on, interact( list( srf, crv, ccrv ) ) );
- crv = circle( vector( 0.0, 0.0, 1.0 ), 0.4 );
- crv = coerce( crv * trans( vector( 0.5, 0.5, 0.0 ) ), e2 );
- ccrv = compose( srf, crv );
- if ( display == on, interact( list( srf, crv, ccrv ) ) );
-
- srf = sbezier( list( list( ctlpt( E3, 0.0, 0.0, 0.0 ),
- ctlpt( E3, 0.0, 0.5, 1.0 ),
- ctlpt( E3, 0.0, 1.0, 0.0 ) ),
- list( ctlpt( E3, 0.5, 0.0, 1.0 ),
- ctlpt( E3, 0.5, 0.5, 0.0 ),
- ctlpt( E3, 0.5, 1.0, 1.0 ) ),
- list( ctlpt( E3, 1.0, 0.0, 1.0 ),
- ctlpt( E3, 1.0, 0.5, 0.0 ),
- ctlpt( E3, 1.0, 1.0, 1.0 ) ),
- list( ctlpt( E3, 1.5, 0.0, 0.0 ),
- ctlpt( E3, 1.5, 0.5, 1.0 ),
- ctlpt( E3, 1.5, 1.0, 0.0 ) ) ) );
- crv = circle( vector( 0.0, 0.0, 1.0 ), 0.4 );
- crv = coerce( crv * trans( vector( 0.5, 0.5, 0.0 ) ), p2 );
- ccrv = compose( srf, crv );
- if ( display == on, interact( list( srf, crv, ccrv ) ) );
-
- free(srf);
- free(crv);
- free(crv1);
- free(crv1c);
- free(crv2);
- free(ccrv);
- free(crvsWsegs);
- free(crvsBsegs);
- iritState("DumpLevel", 1);
-