next up previous contents index
Next: Spheres Up: Geometric Data Structures Previous: Segments   Contents   Index

Circles

A circle data structure consists of a center, radius, and a perpendicular unit vector. Three constructors are provided:

  circle(P center, double radius, P normal);
  circle(P center, P point);
  circle(P p1, P p2, P p3);
Unspecified trailing arguments in the first constructor take the following defaults: If normal is not given, it is set to E_3; if in addition, the radius is unspecified, it is unity; finally, the center is the origin if no arguments are supplied. As usual in C++, only trailing arguments may be left implicit; the call circle(center, normal) does not create a unit circle with the given center and normal.

The second creates a circle parallel to the $ (x_1,x_2)$-plane with the given center and passing through the given point. The third returns the circle passing through the given points. Exceptions are thrown if the center and point do not lie in a plane parallel to the $ (x_1,x_2)$ plane, or if the three points $ p_i$ are collinear.

A circle may be translated by a P with the $ +$ operator, or scaled by a double using the $ *$ operator:

  circle C1=circle();      // unit circle
  circle C2 = C1+P(1,0.5); // translate up and right
  C2 *= 1.5;               // multiply radius by 1.5
  C1.draw(); C2.draw();    // view handiwork
  (C1*C2).draw();          // draw segment of intersection



Andrew D. Hwang 2004-09-04