Next: Getting Shapes Solids, Previous: Returning Elements and Information Solids, Up: Returning Elements and Information Solids
const
virtual function: const Point& get_shape_center (const unsigned short shape_type, const unsigned short s)Returns the
center
of aShape
belonging to theSolid
. Currently, the object can be aCircle
,Ellipse
,Rectangle
, orReg_Polygon
, and it is accessed through a pointer on one of the following vectors of pointers toShape
:circles
,ellipses
,rectangles
, orreg_polygons
. The type of object is specified using the shape_type argument. The followingpublic static const
data members ofSolid
can (and probably should) be passed as the shape_type argument:CIRCLE
,ELLIPSE
,RECTANGLE
, andREG_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()
, andget_reg_polygon_center()
. I don't expect it to be needed in user code very often.Dodecahedron d(origin, 3); d.filldraw(); Point C = d.get_shape_center(Solid::REG_POLYGON, 1); C.dotlabel("C");
![]()
Fig. 182.
Note that this function will have to be changed, if new vectors of
Shape
pointers are added toclass Solid
!
const
virtual functions: const Point& get_circle_center (const unsigned short s)These functions all return the center of the
Shape
pointed to by a pointer on one of the vectors ofShapes
belonging to theSolid
. The argument s indicates which element on the vector is to be accessed. For example,get_rectangle_center(2)
returns the center of theRectangle
pointed to byrectangles[2]
.Cuboid c(origin, 3, 4, 5, 0, 30); c.draw(); for (int i = 0; i < 6; ++i) c.get_rectangle_center(i).label(i, "");
![]()
Fig. 183.