Node: Drawing Points Intro, Next: , Previous: Drawing and Labeling Points, Up: Drawing and Labeling Points



Drawing Points

It's all very well to declare Points, place them at particular locations, print their locations to standard output, and transform them, but none of these operations produce any MetaPost output. In order to do this, the first step is to use drawing and filling commands. The drawing and filling commands in 3DLDF are modelled on those in Metafont.

The following example demonstrates how to draw a dot specifying a Color (see Color Reference) and a pen1.

     Point P(0, 1);
     P.drawdot(Colors::black, "pencircle scaled 3mm");
     


[Figure 3. Not displayed.]

Fig. 3.

In drawdot(), a Color argument precedes the string argument for the pen, so "Colors::black" must be specified as a placeholder in the call to drawdot().2

The following example "undraws" a dot at the same location using a smaller pen. undraw() does not take a Color argument.

     p.undrawdot("pencircle scaled 2mm");
     


[Figure 4. Not displayed.]

Fig. 4.

For complete descriptions of drawdot() and undrawdot(), see Point Reference; Drawing.

Drawing and undrawing dots is not very exciting. In order to make a proper drawing it is necessary to connect the Points. The most basic way of doing this is to use the Point member function draw() with a Point argument:

     Point p0;
     Point p1(2, 2);
     p0.draw(p1);
     


[Figure 5. Not displayed.]

Fig. 5.

p0.draw(p1) is equivalent in its effect to p1.draw(p0).

The function Point::draw() takes a required Point& argument (a reference3 to a Point) an optional Color argument, and optional string arguments for the dash pattern and the pen. The string arguments, if present, are passed unchanged to the output file. The empty string following the argument p1 is a placeholder for the dash pattern argument, which isn't used here.

     p0.draw(p1, Colors::gray, "", "pensquare scaled .5cm rotated 45");
     


[Figure 6. Not displayed.]

Fig. 6.

The function Point::undraw() takes a required Point& argument and optional string arguments for the dash pattern and the pen. Unlike Point::draw(), a Color argument would have no meaning for Point::undraw(). The string arguments are passed unchanged to the output file.

undraw() can be used to "hollow out" the region drawn in [the previous figure] . Since a dash pattern is used, portions of the middle of the region are not undrawn.

     p0.undraw(p1, "evenly scaled 6", "pencircle scaled .2cm");
     


[Figure 7. Not displayed.]

Fig. 7.

For complete descriptions of draw() and undraw(), see Point Reference; Drawing.


Footnotes

  1. Pens are a concept from Metafont. In 3DLDF, there is currently no type ``Pen''. Pen arguments to functions are simply strings, and are written unaltered to out_stream. For more information about Metafont's pens, see Knuth, The Metafontbook, Chapter 4.

  2. Colors are declared in the namespace Colors, so if you have a ``using'' declaration in the function where you use drawdot(), you can write ``black'' instead of ``Colors::black''. For more information about namespaces, see Stroustrup, The C++ Programming Language, Chapter 8.

  3. ``A reference is an alternative name for an object. The main use of references is for specifying arguments and return values for functions in general and for overloaded operators (Chapter 11) in particular.'' Stroustrup, The C++ Programming Language, section 5.5, p. 97.