Circle
A circle is defined by a point in space and a Radius. The circle is an extremely simple shape as shown in the following diagram:
Getting ready
Intersection algorithms for the circle are as simple as its definition. For this reason, a circle is often the first choice to approximate the bounding volume of objects. Arguably, the circle is the most commonly used 2D primitive.
How to do it…
Follow these steps to implement a two-dimensional circle:
Start the declaration of the
Circle
structure inGeometry2D.h
by creating the variables that make up a circle:typedef struct Circle { Point2D position; float radius;
Next, declare an inline constructor that will create a circle at origin with a radius of 1:
inline Circle() : radius(1.0f) {}
Finish the declaration of the
Circle
structure by creating an inline constructor that lets us specify the position and radius of the circle being created:inline Circle(const Point2D& p, float r): position(p), radius(r) {} } Circle;