Node: Getting Shape Centers Solids, Next: , Previous: Returning Elements and Information Solids, Up: Returning Elements and Information Solids

Getting Shape Centers

const Point& get_shape_center (const unsigned short shape_type, const unsigned short s) const virtual function
Returns the center of a Shape belonging to the Solid. Currently, the object can be a Circle, Ellipse, Rectangle, or Reg_Polygon, and it is accessed through a pointer on one of the following vectors of pointers to Shape: circles, ellipses, rectangles, or reg_polygons. The type of object is specified using the shape_type argument. The following public static const data members of Solid can (and probably should) be passed as the shape_type argument: CIRCLE, ELLIPSE, RECTANGLE, and REG_POLYGON.

The argument s is used to index the vector.

This function is called within the more specialized functions in this section, namely: get_circle_center(), get_ellipse_center(), get_rectangle_center(), and get_reg_polygon_center(). I don't expect it to be needed in user code very often.

          Dodecahedron d(origin, 3);
          Point C = d.get_shape_center(Solid::REG_POLYGON, 1);

[Figure 182. Not displayed.]

Fig. 182.

Note that this function will have to be changed, if new vectors of Shape pointers are added to class Solid!

const Point& get_circle_center (const unsigned short s) const virtual functions
const Point& get_ellipse_center (const unsigned short s)
const Point& get_rectangle_center (const unsigned short s)
const Point& get_reg_polygon_center (const unsigned short s)
These functions all return the center of the Shape pointed to by a pointer on one of the vectors of Shapes belonging to the Solid. The argument s indicates which element on the vector is to be accessed. For example, get_rectangle_center(2) returns the center of the Rectangle pointed to by rectangles[2].
          Cuboid c(origin, 3, 4, 5, 0, 30);
          for (int i = 0; i < 6; ++i)
            c.get_rectangle_center(i).label(i, "");

[Figure 183. Not displayed.]

Fig. 183.