papyrus logo

Regular Polygons

A regular polygon is "a plane polygon which is both equilateral and equiangular." [1]

A regular polygon is specified by a combination of the number of sides and either of the radius (the distance from the center to a vertex), the apothem (the perpendicular from the center to an edge), or the length of the edges.

A regular polygon may also be specified as ZERO_RADIUS or ZERO_APOTHEM, which will result in the radius or apothem respectively being draw at 0 radians.

The following contains an example that will add a hexagon polygon to a canvas, with the radius drawn at 0 radians.

The blue lines represent the x and y axes, and show through since an alpha value of 0.9 is used.

regularpolygon_radius.png

Regular polygon with six sides (hexagon) and radius at 0 radians drawn by example code below

void add_regularpolygon_radius( Papyrus::Canvas::pointer canvas ) {
  // Create a filled hexagon (sides=6, radius=75)
  Papyrus::RegularPolygon::pointer hexagon = Papyrus::RegularPolygon::create(6, 75);

  // Add the hexagon to the canvas
  canvas->add( hexagon );

  // Set the fill color to red, with an alpha value of 0.9
  hexagon->set_fill( Papyrus::RGBA(1.0, 0.0, 1.0, 0.9) );

  // To color the lines of a hexagon shape, set the stroke paint
  hexagon->set_stroke( Papyrus::RGBA(0.0, 0.0, 0.0, 0.9) );
}

The following contains an example that will add a hexagon polygon to a canvas, with the apothem drawn at 0 radians.

The blue lines represent the x and y axes, and show through since an alpha value of 0.9 is used.

regularpolygon_apothem.png

Regular polygon with six sides (hexagon) and apothem at 0 radians drawn by example code below

void add_regularpolygon_apothem( Papyrus::Canvas::pointer canvas ) {
  // Create a filled hexagon (sides=6, radius=75)
  Papyrus::RegularPolygon::pointer hexagon =
    Papyrus::RegularPolygon::create(6, 75, Papyrus::RegularPolygon::ZERO_APOTHEM);

  // Add the hexagon to the canvas
  canvas->add( hexagon );

  // Set the fill color to red, with an alpha value of 0.9
  hexagon->set_fill( Papyrus::RGBA(0.0, 1.0, 1.0, 0.9) );

  // To color the lines of a hexagon shape, set the stroke paint
  hexagon->set_stroke( Papyrus::RGBA(0.0, 0.0, 0.0, 0.9) );
}

[1] 1913 Webster


Generated on Fri Apr 16 12:41:04 2010 for papyrus by doxygen 1.6.1