Exercise 1

Write a Circle class.

Background

The equation of a circle centered at the point $\displaystyle \left(x_{c}, y_{c}\right)$ is given by \begin{align} \left(x - x_{c}\right)^{2} + \left(y - y_{c}\right)^{2} = r^{2} \end{align} where $r$ is the radius of the circle.

Requirements:

  • An instance of the Circle class should be initialized with two points: $\left(x_{c}, y_{c}\right)$ and $\left(x, y\right)$. The first point is the point at which the circle is centered and the second point is any point that the circle should pass through.
  • You must include the initializer constructor (__init__).
  • Include methods to compute the radius, area, and circumference of the circle.
  • Demo your Circle class.

Comments

  • You can write the class however you want, as long as it follows the interface outlined above. For example, you could pass the points in as tuples or a list or a bunch of scalars or something else entirely.
  • You should test for and handle exceptions where necessary.

Deliverables

Save your solution as L6E1.py. Your submission file should include the class definition and the demo.