Curve examples

These examples create and draw curves and loops to give you an idea of how the appearance of the curve or loop changes when control points, curve order, or knot vectors are varied. Figure 45 shows the results at runtime when the code examples execute.


Quadratic curve with TGPoint

This code fragment draws a quadratic curve that has 3 control points and an order of 3. This curve is shown in the top-left corner of Figure 45.

      TGCurve aQuadraticCurve(    TGPoint( 25, 25 ), 
                                  TGPoint( 45, 100 ),
                                  TGPoint( 95, 75 ) );
      
      TFrameBundle aBundle( TRGBColor( 0, 0, 0), 5.0 );
      thePort.Draw( aQuadraticCurve, aBundle );

Cubic curve with TGPoint

This code fragment draws a cubic curve that has 4 control points and an order of 4. This curve is shown in the bottom-left corner of Figure 45.

      TGCurve aCubicCurve(        TGPoint( 25, 125 ), 
                                  TGPoint( 45, 200 ),
                                  TGPoint( 95, 175 ),
                                  TGPoint( 70, 150 ) );
      
      TFrameBundle aBundle( TRGBColor( 0, 0, 0), 5.0 );
      thePort.Draw( aCubicCurve, aBundle );

Cubic curve with TGRPointArray

This code fragment draws a cubic curve that has 4 control points and an order of 4 using a TGRPointArray. You can easily increase or decrease the number of points in the array and the curve order. The number of control points must always be equal to or greater than the order of the curve. This curve is shown in the top-right corner of Figure 45.

      static const TGRPoint curvePointArray[ 4 ] = {
                                  TGRPoint( 175, 25, 1 ), 
                                  TGRPoint( 195, 100, 1 ),
                                  TGRPoint( 245, 75, 1 ),
                                  TGRPoint( 220, 50, 1 ) 
                                                  };
      
      TGRPointArray aCurveArray( 4 );
      for( long m = 0; m < 4; m++ )
          aCurveArray.SetPoint( m, curvePointArray[ m ] );
      
      TGCurve aGeneralCurve( 4, aCurveArray );
      TFrameBundle aBundle( TRGBColor( 0, 0, 0), 5.0 );
      thePort.Draw( aGeneralCurve, aBundle );

Quadratic curve with knot vectors

This code fragment draws a quadratic (order 3) curve with a piecewise Bézier knot vector. There are 7 control points, and 10 knot vectors (7 + 3). The knot vector helps this curve be joined smoothly with another curve; it does not smooth the sharp joint that is a result of the curve's own points. This curve is shown in the bottom-right corner of Figure 45
.

      static const TGRPoint curvePointArray2[ 7 ] = {
                                  TGRPoint( 175, 125, 1 ), 
                                  TGRPoint( 195, 200, 1 ),
                                  TGRPoint( 245, 175, 1 ),
                                  TGRPoint( 220, 150, 1 ),
                                  TGRPoint( 250, 150, 1 ),
                                  TGRPoint( 275, 100, 1 ),
                                  TGRPoint( 260, 50, 1 ) 
                                                  };
      
      TGRPointArray aCurveArray2( 4 );
      for( long n = 0; n < 4; n++ )
          aCurveArray2.SetPoint( n, curvePointArray2[ n ] );
      
      static const GCoordinate knotArray[ 10 ] = {
                  ( 0 ), ( 0 ), ( 0 ), ( 1 ), ( 1 ),
                  ( 2 ), ( 2 ), ( 3 ), ( 3 ), ( 3 )
                                                  };  
      
      TRawArray< GParametric > knots( 10);
      for( long o = 0; o < 10; o++ )
          knots.SetValue( o, knotArray[ o ] );
      
      TGCurve aGeneralCurve2( 3, aCurveArray2, knots );
      TFrameBundle aBundle( TRGBColor( 0, 0, 0), 5.0 );
      thePort.Draw( aGeneralCurve2, aBundle );

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker