Category : OS/2 Files
Archive   : IRIT-OS2.ZIP
Filename : BEZIER.IRT

 
Output of file : BEZIER.IRT contained in archive : IRIT-OS2.ZIP
#
# Some routines to test bezier curves/surfaces.
#

#
# Set display to on to view some results, off to view nothing.
#
display = on;

resolution = 10;
if ( machine, "=", msdos, (resolution = 5));

s45 = sin( pi / 4 );
cbzr = list( ctlpt( P2, 1.0, 1.0, 0.0 ),
ctlpt( P2, s45, s45, s45 ),
ctlpt( P2, 1.0, 0.0, 1.0 ) );
sbzr = list ( list( ctlpt( E3, 0.0, 0.0, 1.0 ),
ctlpt( E3, 0.0, 1.0, 0.0 ),
ctlpt( E3, 0.0, 2.0, 1.0 ) ),
list( ctlpt( E3, 1.0, 0.0, 0.0 ),
ctlpt( E3, 1.0, 1.0, 2.0 ),
ctlpt( E3, 1.0, 2.0, 0.0 ) ),
list( ctlpt( E3, 2.0, 0.0, 2.0 ),
ctlpt( E3, 2.0, 1.0, 0.0 ),
ctlpt( E3, 2.0, 2.0, 2.0 ) ),
list( ctlpt( E3, 3.0, 0.0, 0.0 ),
ctlpt( E3, 3.0, 1.0, 2.0 ),
ctlpt( E3, 3.0, 2.0, 0.0 ) ),
list( ctlpt( E3, 4.0, 0.0, 1.0 ),
ctlpt( E3, 4.0, 1.0, 0.0 ),
ctlpt( E3, 4.0, 2.0, 1.0 ) ) );


cb = cbezier( cbzr );
color( cb, red );
sb = sbezier( sbzr );
color( sb, red );

drawctlpt = 0;
if ( display, "=", on, interact( list( axes, cb, sb ), 0 ) );
drawctlpt = blue;
if ( display, "=", on, interact( list( axes, cb, sb ), 0 ) );
drawctlpt = 0;

#
# Curve refinement (note the returned curve is a bspline curve).
#
cb_ref = crefine( cb, false, list( 0.25, 0.5, 0.75 ) );
color( cb_ref, yellow );
if ( display, "=", on, interact( list( axes, cb, cb_ref ), 0 ) );
free( cb_ref );

#
# Curve subdivision.
#
cb_lst = cdivide( cb, 0.5 );
cb1 = nth( cb_lst, 1 );
color( cb1, green );
cb2 = nth( cb_lst, 2 );
color( cb2, yellow );
free( cb_lst );
if ( display, "=", on, interact( list( axes, cb, cb1, cb2 ), 0 ) );
free( cb1 ); free( cb2 );

#
# Region from curve.
#
cbr1 = cregion( cb, 0.3, 0.6 );
color( cbr1, yellow );
cbr2 = cregion( cb, 0.5, 1.0 );
color( cbr2, green );
cbr3 = cregion( cb, 0.3, 0.0 );
color( cbr3, blue );
interact( list( cb, cbr1, cbr2, cbr3 ), 0 );
free( cbr1 ); free( cbr2 ); free( cbr3 );

#
# Surface subdivision.
#
sb_lst = sdivide( sb, COL, 0.4 );
sb1 = nth( sb_lst, 1 );
color( sb1, green );
sb2 = nth( sb_lst, 2 );
color( sb2, yellow );
free( sb_lst );
if ( display, "=", on, interact( list( axes, sb, sb1, sb2 ), 0 ) );
free( sb1 );
free( sb2 );
sb_lst = sdivide( sb, ROW, 0.8 );
sb1 = nth( sb_lst, 1 );
color( sb1, green );
sb2 = nth( sb_lst, 2 );
color( sb2, yellow );
free( sb_lst );
if ( display, "=", on, interact( list( axes, sb, sb1, sb2 ), 0 ) );
free( sb1 ); free( sb2 );

#
# Region from surface.
#
sbr1 = sregion( sb, COL, 0.3, 0.6 );
color( sbr1, yellow );
sbr2 = sregion( sb, COL, 0.8, 1.0 );
color( sbr2, green );
sbr3 = sregion( sb, ROW, 0.1, 0.4 );
color( sbr3, blue );
interact( list( sb, sbr1, sbr2, sbr3 ), 0);
free( sbr1 ); free( sbr2 ); free( sbr3 );

#
# Iso curves extraction from surface.
#
cb_all = list( axes );
snoc( sb, cb_all );
cb1 = 0; # Define a dummy variable to use in loop.
for ( (t = 0.1), 0.1, 0.9,
(
( cb1 = csurface( sb, COL, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
for ( (t = 0.1), 0.1, 0.9,
(
( cb1 = csurface( sb, ROW, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
if ( display, "=", on, interact( cb_all, 0 ) );
free( cb_all );


#
# curves extraction from surface mesh. Note curves may be not on the surface.
#
cb_all = list( axes );
snoc( sb, cb_all );
cb1 = 0; # Define a dummy variable to use in loop.
for ( (t = 0), 1, 2,
(
( cb1 = cmesh( sb, COL, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
for ( (t = 0), 1, 4,
(
( cb1 = cmesh( sb, ROW, t ) ):
color( cb1, green ):
snoc( cb1, cb_all )
)
);
drawctlpt = blue;
if ( display, "=", on, interact( cb_all, 0 ) );
drawctlpt = 0;
free( cb_all );

#
# convert into polygons/polylines (using default resolution).
#
dumplvl = 1;
resolution;

p = gpolyline( list( sb, cb ) );
if ( display, "=", on, interact( list( p, axes ), 0 ) );

p = gpolygon( sb );
if ( display, "=", on, interact( list( p, axes ), 0 ) );

#
# reverse surface ( flip normals ).
#
q = gpolygon( -sb );
normal( on, 0.1, green );
if ( display, "=", on, interact( list( p, q, axes ), 0 ) );
normal( off, 0.1, green );
free(p);
free(q);

#
# Offset approximation by translation of srf/crv in normal direction.
#
cbo = offset(cb, 0.1);
if ( display, "=", on, interact( list( axes, cb, cbo ), 0 ) );
free(cbo);

sbo = offset(sb, 0.2);
if ( display, "=", on, interact( list( axes, sb, sbo ), 0 ) );
free(sbo);

#
# Surface and Curve evaluation.
#
v1 = ceval( cb, 0.0 );
v2 = ceval( cb, 0.1 );
v3 = ceval( cb, 0.3 );
v4 = ceval( cb, 0.5 );
v5 = ceval( cb, 0.9 );
v6 = ceval( cb, 1.0 );
v7 = ceval( cb, 1.5 );
v1;
v2;
v3;
v4;
v5;
v6;
v7;

pause(1);

w1 = seval( sb, 0.0, 0.0 );
w2 = seval( sb, 0.1, 0.0 );
w3 = seval( sb, 0.3, 0.0 );
w4 = seval( sb, 0.5, 0.5 );
w5 = seval( sb, 0.9, 0.1 );
w6 = seval( sb, 1.0, 1.0 );
w7 = seval( sb, 1.5, 9.0 );
w1;
w2;
w3;
w4;
w5;
w6;
w7;

pause(1);

#
# Surface and Curve tangents.
#
v1 = ctangent( cb, 0.0 );
v2 = ctangent( cb, 0.1 );
v3 = ctangent( cb, 0.3 );
v4 = ctangent( cb, 0.5 );
v5 = ctangent( cb, 0.9 );
v6 = ctangent( cb, 1.0 );
v7 = ctangent( cb, 1.5 );
v1;
v2;
v3;
v4;
v5;
v6;
v7;

pause(1);

w1 = stangent( sb, 1, 0.0, 0.0 );
w2 = stangent( sb, 2, 0.1, 0.0 );
w3 = stangent( sb, 1, 0.3, 0.0 );
w4 = stangent( sb, 2, 0.5, 0.5 );
w5 = stangent( sb, 1, 0.9, 0.1 );
w6 = stangent( sb, 2, 1.0, 1.0 );
w7 = stangent( sb, 2, 1.5, 9.0 );
w1;
w2;
w3;
w4;
w5;
w6;
w7;

pause(1);

#
# Surface normals.
#
w1 = snormal( sb, 0.0, 0.0 );
w2 = snormal( sb, 0.1, 0.0 );
w3 = snormal( sb, 0.3, 0.0 );
w4 = snormal( sb, 0.5, 0.5 );
w5 = snormal( sb, 0.9, 0.1 );
w6 = snormal( sb, 1.0, 1.0 );
w7 = snormal( sb, 1.5, 9.0 );
w1;
w2;
w3;
w4;
w5;
w6;
w7;

pause(1);


#
# save("cb", cb);
# save("sb", sb);
#
# cb1 = load("cb.crv");
# sb1 = load("sb.srf");
#
# save("cb1", cb1);
# save("sb1", sb1);
#
#

  3 Responses to “Category : OS/2 Files
Archive   : IRIT-OS2.ZIP
Filename : BEZIER.IRT

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/