#
# More examples of animated 3d bisector computations of 3-space crv and pt.
#
#			Gershon Elber, August 1996.
#

speed = 5;
FileCount = 1000;

view_mat = view_mat * sc( 0.4 );
viewobj( view_mat );

viewstate( "DepthCue", 0 );

polesFree = function( Srf, Dpth, TMin, TMax ):
     return = nil();
polesFree = function( Srf, Dpth, TMin, TMax ): Srfs: t:
     if ( !ffpoles( Srf ),
	  return = list( Srf ),
	  if ( Dpth <= 0,
	       return = nil(),
	       t = ( TMin + TMax ) / 2:
	       Srfs = sdivide( Srf, row, t ):
	       return = polesFree( nth( Srfs, 1 ), Dpth - 1, TMin, t ) +
		        polesFree( nth( Srfs, 2 ), Dpth - 1, t, TMax ) ) );

#
# Save the sequence into files for high quality rendering.
#
comment $

save( "view", list( view_mat, prsp_mat ) );

DisplayCirc = circle( vector( 0.0, 0.0, 0.0 ), 0.015 );

display = procedure( c1, pt, BiSrf ): s1: s2: BiSrfIsos:
    attrib( BiSrf, "transp", 0.25 ):
    color( BiSrf, red ):
    attrib( BiSrf, "v_resolution", 0.01 ):
    BiSrfIsos = GetIsoCurveTubes( BiSrf, 15, 15, 0.005 ):
    attrib( BiSrfIsos, "u_resolution", 0.01 ):
    color( BiSrfIsos, magenta ):
    s1 = sweepsrf( DisplayCirc, c1, off ):
    s2 = sphere( pt, 0.045 ):
    attrib( s1, "u_resolution", 0.2 ):
    color( s1, yellow ):
    color( s2, green ):
    save( "c" + FileCount + ".itd.Z", list( s1, s2, BiSrf, BiSrfIsos ) ):
    FileCount = FileCount + 1;
$

#
# Display the sequence into the current display device, real time.
#
display = procedure( c1, pt, BiSrf ):
    color( c1, yellow ):
    adwidth( c1, 3 ):
    color( pt, green ):
    adwidth( pt, 3 ):
    color( BiSrf, magenta ):
    view( list( c1, pt, BiSrf ), true );

#############################################################################
#
# A line
#

for ( b = 2.0, -0.005 * speed, 0.0,
    pt = point( 0, 0, 0 ):
    c1 = cbezier( list( ctlpt( E3,  0.0, -0.2 - b, -1.0 ),
		        ctlpt( E3,  0.0, -0.2 - b,  1.0 ) ) ):
    BisectSrf = cbisector( list( c1, pt ), -1, 1, true, false ):
    display( c1, pt, BisectSrf ) );

for ( b = 0.0, 0.0025 * speed, 2.0,
    pt = point( b, 0, 0 ):
    c1 = cbezier( list( ctlpt( E3,  0.0, -0.2, -1.0 ),
		        ctlpt( E3,  0.0, -0.2,  1.0 ) ) ):
    BisectSrf = cbisector( list( c1, pt ), -1, 1, true, false ):
    display( c1, pt, BisectSrf ) );

for ( b = 2.0, -0.0025 * speed, 0.0,
    pt = point( b, 0, 0 ):
    c1 = cbezier( list( ctlpt( E3,  0.0, -0.2, -1.0 ),
		        ctlpt( E3,  0.0, -0.2,  1.0 ) ) ):
    BisectSrf = cbisector( list( c1, pt ), -1, 1, true, false ):
    display( c1, pt, BisectSrf ) );

#############################################################################
#
# A quadratic
#

for ( a = 0.0, 0.005 * speed, 3.0,
    pt = point( 0, 0, 0 ):
    c1 = cbezier( list( ctlpt( E3,  0.0, -0.2,     -1.0 ),
		        ctlpt( E3,  0.0, -0.2 - a,  0.0 ),
		        ctlpt( E3,  0.0, -0.2,      1.0 ) ) ):
    BisectSrf = cbisector( list( c1, pt ), -1, 0.3, true, false ):
    display( c1, pt, BisectSrf ) );

for ( a = 0.0, 0.005 * speed, 2.0,
    pt = point( a, 0, 0 ):
    c1 = cbezier( list( ctlpt( E3,  0.0, -0.2, -1.0 ),
		        ctlpt( E3,  0.0, -3.2,  0.0 ),
		        ctlpt( E3,  0.0, -0.2,  1.0 ) ) ):
    BisectSrf = cbisector( list( c1, pt ), -1, 0.3, true, false ):
    display( c1, pt, BisectSrf ) );

for ( a = 2.0, -0.005 * speed, -2.0,
    pt = point( a, 0, 0 ):
    c1 = cbezier( list( ctlpt( E3,  0.0, -0.2, -1.0 ),
		        ctlpt( E3,  0.0, -3.2,  0.0 ),
		        ctlpt( E3,  0.0, -0.2,  1.0 ) ) ):
    BisectSrf = cbisector( list( c1, pt ), -1, 0.3, true, false ):
    display( c1, pt, BisectSrf ) );

for ( a = -2.0, 0.005 * speed, 0.0,
    pt = point( a, 0, 0 ):
    c1 = cbezier( list( ctlpt( E3,  0.0, -0.2, -1.0 ),
		        ctlpt( E3,  0.0, -3.2,  0.0 ),
		        ctlpt( E3,  0.0, -0.2,  1.0 ) ) ):
    BisectSrf = cbisector( list( c1, pt ), -1, 0.3, true, false ):
    display( c1, pt, BisectSrf ) );

#############################################################################
#
# A cubic
#

circ = pcircle( vector( 0.0, 0.0, 0.0 ), 1 ) * rz( 90 ) * ry( -90 );
ffcompat( c1, circ );

pt = point( 0, 0, 0 );

for ( a = 0.0, 0.01 * speed, 1.0,
    c1x = cmorph( c1, circ, 0, a ):
    BisectSrf = cbisector( list( c1x, pt ), -1, 0.3, true, false ):
    display( c1x, pt, BisectSrf ) );

for ( a = 0.0, 0.01 * speed, 0.9,
    pt = point( 0, a, 0 ):
    BisectSrf = cbisector( list( circ, pt ), -1, 0.3, true, false ):
    display( circ, pt, BisectSrf ) );

for ( a = 0.9, -0.01 * speed, 0.0,
    pt = point( 0.9 - a, a, 0 ):
    BisectSrf = cbisector( list( circ, pt ), -1, 0.3, true, false ):
    display( circ, pt, BisectSrf ) );

#############################################################################
#
# A Helix
#
pt = point( 0.9, 0, 0 );

Helix = circ * rotx( 0 );

for ( i = 0, 1, sizeof( Helix ) - 1,
    PtH = coord( Helix, i ):
    Helix = cEditPt( Helix,
		     ctlpt( E3, i / 4, coord( PtH, 2 ), coord( PtH, 3 ) ),
		     i ) );

for ( a = 0.0, 0.1 * speed, 1.0,
    c1y = cmorph( circ, Helix, 0, a ):
    BisectSrf = cbisector( list( c1y, pt ), -1, 0.3, true, false ):
    display( c1y, pt, BisectSrf ) );

for ( a = 1.0, -0.02 * speed, 0.0,
    Hel = cregion( Helix, 0, 0.999 * a + 0.0001 ) * ty( 1.1 * ( 1.0 - a ) ):
    pt = point( -0.9 * a, 2.1 * a - 2.1, 0.0 ):
    BisectSrf = cbisector( list( Hel, pt ), -1, 0.3, true, false ):
    display( Hel, pt, BisectSrf ) );


#############################################################################

free( a );
free( c1 );
free( BisectSrf );
free( Pt );
free( c1x );
free( c1y );
free( circ );
free( FileCount );
free( Speed );
free( Hel );
free( PtH );
free( i );
free( Helix );
free( b );
