# # Bezier clipping examples. # # Gershon Elber and Diana Pekerman, March 2003. # EvalSrfRayInter = function( RayPt, RayDir, Srf ): NumInters: RayGeom: InterPts: InterE3: i: RayGeom = list( coerce( RayPt, E3 ) + coerce( RayPt + RayDir, E3 ), RayPt ): color( RayGeom, magenta ): InterPts = SRayClip( RayPt, RayDir, Srf ): NumInters = nth( InterPts, 1 ): InterE3 = nil(): for ( i = 1, 1, NumInters, snoc( nth( InterPts, i * 2 + 1 ), InterE3 ) ): color( interE3, yellow ): return = list( RayGeom, InterE3 ); #------------------------------------------------ # SADDLE #------------------------------------------------ Saddle = sbezier( list( list( ctlpt( E3, 0, 0, 0 ), ctlpt( E3, 0.05, 0.2, 0.1 ), ctlpt( E3, 0.1, 0.05, 0.2 ) ), list( ctlpt( E3, 0.1, -0.2, 0 ), ctlpt( E3, 0.15, 0.05, 0.1 ), ctlpt( E3, 0.2, -0.1, 0.2 ) ), list( ctlpt( E3, 0.2, 0, 0 ), ctlpt( E3, 0.25, 0.2, 0.1 ), ctlpt( E3, 0.3, 0.05, 0.2 ) ) ) ) * sc( 4 ); attrib( Saddle, "rgb", "55, 255, 255" ); All1 = list( Saddle, axes, EvalSrfRayInter( point( 0, -0.5, 0 ), vector( 1, 1, 1 ), Saddle ) ); interact( All1 ); All2 = list( Saddle, axes, EvalSrfRayInter( point( -0.5, 0.1, 0.2 ), vector( 2, 0.2, 0.2 ), Saddle ) ); interact( All2 ); free( Saddle ); save( "bez1clip", list( All1, All2 ) ); #------------------------------------------------ # TEAPOT END #------------------------------------------------ TeapotSpout1 = sbezier( list( list( ctlpt( E3, 1.7, 1.275, 0 ), ctlpt( E3, 2.6, 1.275, 0 ), ctlpt( E3, 2.3, 1.95, 0 ), ctlpt( E3, 2.7, 2.25, 0 ) ), list( ctlpt( E3, 1.7, 1.275, 0.66 ), ctlpt( E3, 2.6, 1.275, 0.66 ), ctlpt( E3, 2.3, 1.95, 0.25 ), ctlpt( E3, 2.7, 2.25, 0.25 ) ), list( ctlpt( E3, 1.7, 0.45, 0.66 ), ctlpt( E3, 3.1, 0.675, 0.66 ), ctlpt( E3, 2.4, 1.875, 0.25 ), ctlpt( E3, 3.3, 2.25, 0.25 ) ), list( ctlpt( E3, 1.7, 0.45, 0 ), ctlpt( E3, 3.1, 0.675, 0 ), ctlpt( E3, 2.4, 1.875, 0 ), ctlpt( E3, 3.3, 2.25, 0 ) ) ) ) * sc ( 0.4 ); TeapotSpout2 = sbezier( list( list( ctlpt( E3, 1.7, 0.45, 0 ), ctlpt( E3, 3.1, 0.675, 0 ), ctlpt( E3, 2.4, 1.875, 0 ), ctlpt( E3, 3.3, 2.25, 0 ) ), list( ctlpt( E3, 1.7, 0.45, -0.66 ), ctlpt( E3, 3.1, 0.675, -0.66 ), ctlpt( E3, 2.4, 1.875, -0.25 ), ctlpt( E3, 3.3, 2.25, -0.25 ) ), list( ctlpt( E3, 1.7, 1.275, -0.66 ), ctlpt( E3, 2.6, 1.275, -0.66 ), ctlpt( E3, 2.3, 1.95, -0.25 ), ctlpt( E3, 2.7, 2.25, -0.25 ) ), list( ctlpt( E3, 1.7, 1.275, 0 ), ctlpt( E3, 2.6, 1.275, 0 ), ctlpt( E3, 2.3, 1.95, 0 ), ctlpt( E3, 2.7, 2.25, 0 ) ) ) ) * sc ( 0.4 ) ; attrib( TeapotSpout1, "rgb", "55, 55, 255" ); attrib( TeapotSpout2, "rgb", "55, 55, 255" ); All1 = list( TeapotSpout1, TeapotSpout2, axes, EvalSrfRayInter( point( 0, 0, 0 ), vector( 1.5, 1, 0 ), TeapotSpout1 ), EvalSrfRayInter( point( 0, 0, 0 ), vector( 1.5, 1, 0 ), TeapotSpout2 ) ); interact( All1 ); All2 = list( TeapotSpout1, TeapotSpout2, axes, EvalSrfRayInter( point( 0.3, 0.6, 0 ), vector( 10, 0.2, 0.1 ), TeapotSpout1 ), EvalSrfRayInter( point( 0.3, 0.6, 0 ), vector( 10, 0.2, 0.1 ), TeapotSpout2 ) ); interact( All2 ); All3 = list( TeapotSpout1, TeapotSpout2, axes, EvalSrfRayInter( point( 0.5, -0.3, 0.3 ), vector( 0.7, 0.9, -0.55 ), TeapotSpout1 ), EvalSrfRayInter( point( 0.5, -0.3, 0.3 ), vector( 0.7, 0.9, -0.55 ), TeapotSpout2 ) ); interact( All3 ); All4 = list( TeapotSpout1, TeapotSpout2, axes, EvalSrfRayInter( point( 0.5, -0.3, 0.3), vector( 0.54, 0.72, -0.44), TeapotSpout1 ), EvalSrfRayInter( point( 0.5, -0.3, 0.3 ), vector( 0.54, 0.72, -0.44), TeapotSpout2 ) ); interact( All4 ); All5 = list( TeapotSpout1, TeapotSpout2, axes, EvalSrfRayInter( point( 0.5, -0.3, 0.3), vector( 0.5365, 0.7204, -0.4393), TeapotSpout1 ), EvalSrfRayInter( point( 0.5, -0.3, 0.3 ), vector( 0.5365, 0.7204, -0.4393), TeapotSpout2 ) ); interact( All5 ); free( TeapotSpout1 ); free( TeapotSpout2 ); save( "bez2clip", list( All1, All2, All3, All4, All5 ) ); #------------------------------------------------ # Spiral surface #------------------------------------------------ SpiralSrf = sbezier( list( list( ctlpt( E3, 0.16, 0.49, 0.88 ), ctlpt( E3, 0.40, 0.83, 0.91 ), ctlpt( E3, 0.66, 0.81, 0.95 ), ctlpt( E3, 0.78, 0.50, 0.97 ), ctlpt( E3, 0.50, 0.15, 0.93 ), ctlpt( E3, 0.22, 0.21, 0.88 ), ctlpt( E3, 0.37, 0.62, 0.91 ), ctlpt( E3, 0.58, 0.52, 0.94 )), list( ctlpt( E3, 0.21, 0.48, 0.50 ), ctlpt( E3, 0.31, 0.76, 0.45 ), ctlpt( E3, 0.54, 0.78, 0.45 ), ctlpt( E3, 0.79, 0.80, 0.46 ), ctlpt( E3, 0.82, 0.36, 0.56 ), ctlpt( E3, 0.36, 0.15, 0.58 ), ctlpt( E3, 0.21, 0.25, 0.55 ), ctlpt( E3, 0.47, 0.52, 0.50 )), list( ctlpt( E3, 0.22, 0.61, 0.09 ), ctlpt( E3, 0.50, 0.94, 0.13 ), ctlpt( E3, 0.77, 0.93, 0.13 ), ctlpt( E3, 0.77, 0.65, 0.09 ), ctlpt( E3, 0.96, 0.33, 0.05 ), ctlpt( E3, 0.48, 0.21, 0.03 ), ctlpt( E3, 0.35, 0.28, 0.04 ), ctlpt( E3, 0.17, 0.18, 0.03 ) ) ) ) ; attrib( SpiralSrf, "rgb", "255, 0, 55" ); All1 = list( SpiralSrf, axes, EvalSrfRayInter( point( 0, 0, 0 ), vector( 1, 1, 1 ), SpiralSrf ) ); interact( All1 ); All2 = list( SpiralSrf, axes, EvalSrfRayInter( point( 0, 0.8, 0.5 ), vector( 1.5, -0.9, 0.7 ), SpiralSrf ) ); interact( All2 ); free( SpiralSrf ); save( "bez3clip", list( All1, All2 ) ); free( All1 ); free( All2 ); free( All3 ); free( All4 ); free( All5 );