Node:Rectangles Getstart, Next:Ellipses Getstart, Previous:Regular Polygons Getstart, Up:Plane Figures
A Rectangle
can be constructed in the x-z plane by specifying a
center Point
, the width, and the height:
Rectangle r(origin, 2, 3); r.draw();
Fig. 27.
Three additional arguments can be used to specify rotation about the x, y, and z-axes respectively:
Rectangle r(origin, 2, 3, 30, 45, 15); r.draw();
Fig. 28.
If a Point
p other than the origin is specified as the center of
the Rectangle
, the latter is first created in the x-z plane,
centered about the origin, as above. Then, any rotations specified are
performed. Finally, the Rectangle
is shifted such that its center
comes to lie at p:
Point p0(.5, 1, 3); Rectangle r(p0, 4, 2, 30, 30, 30); r.draw();
Fig. 29.
This constructor has a corresponding setting function:
Rectangle r; for (int i = 0; i < 180; i += 30) { r.set(origin, 4, 2, i); r.draw(); }
Fig. 30.
Rectangles
can also be specified using four Points
as
arguments, whereby they must be ordered so that they are contiguous in
the resulting Rectangle
:
Point pt[4]; pt[0].shift(-1, -2); pt[2] = pt[1] = pt[0]; pt[1].rotate(180); pt[3] = pt[1]; pt[2] *= pt[3].rotate(0, 180); Rectangle r(pt[0], pt[2], pt[3], pt[1]); r.draw();
Fig. 31.
This constructor checks whether the Point
arguments are coplanar,
however, it does not check whether they are really the corners of a
valid rectangle; the user, or the code that calls this function, must
ensure that they are. In the following
example, r
, although not rectangular, is a Rectangle
, as
far as 3DLDF is concerned:
pt[0].shift(0, -1); pt[3].shift(0, 1); Rectangle q(pt[0], pt[2], pt[3], pt[1]); q.draw();
Fig. 32.
This constructor is not really intended to be used directly, but should
mostly be called from within other functions, that should ensure that
the arguments produce a rectangular Rectangle
. There is also no
guarantee that transformations or other functions called on
Rectangle
, Circle
, or other classes representing
geometric figures won't cause them to become non-rectangular,
non-circular, or otherwise irregular. Sometimes, this might even be
desirable. I plan to add the function
Rectangle::is_rectangular()
soon, so that users can test
Rectangles
for rectangularity.