feisty meow concerns codebase  2.140
circle.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : circle *
4 * Author : Chris Koeritz *
5 * *
6 *******************************************************************************
7 * Copyright (c) 1992-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
14 
15 #include "circle.h"
16 #include "cartesian_objects.h"
17 #include "line.h"
18 #include "rectangle.h"
19 
20 #include <basis/functions.h>
21 
22 #include <math.h>
23 
24 using namespace basis;
25 
26 namespace geometric {
27 
28 circle::circle() : _radius(1), _center(cartesian_point::origin()) {}
29 
30 circle::circle(double a_radius, const cartesian_point &a_center)
31 : _radius(a_radius), _center(a_center) {}
32 
34 
35 double circle::area() const { return PI_APPROX * square(_radius); }
36 
37 double circle::diameter() const { return 2.0 * _radius; }
38 
39 double circle::circumference() const { return 2.0 * PI_APPROX * _radius; }
40 
42 {
43  double rotation = where.get(RADIANS);
44  cartesian_point second(cos(rotation) * _radius, sin(rotation) * _radius);
45  return _center + second;
46 }
47 
48 bool circle::inside(const cartesian_point &where) const
49 {
50  double dist = where.distance(_center);
51  return dist <= _radius? true : false;
52 }
53 
55 {
56  const double deg0 = 0;
57  const double deg90 = 0.5 * PI_APPROX;
58  const double deg180 = PI_APPROX;
59  const double deg270 = 1.5 * PI_APPROX;
60 
61  cartesian_point right(location(deg0));
62  cartesian_point top(location(deg90));
63  cartesian_point left(location(deg180));
64  cartesian_point bottom(location(deg270));
65  return cartesian_rectangle(left.x(), bottom.y(), right.x(), top.y());
66 }
67 
68 double circle::radius() const { return _radius; }
69 
70 void circle::radius(double to_set) { _radius = to_set; }
71 
72 cartesian_point circle::center() const { return _center; }
73 
74 void circle::center(const cartesian_point &to_set) { _center = to_set; }
75 
76 } // namespace.
77 
contents get(angular_units unit) const
retrieves the current angular measure.
Definition: angle.h:202
Provides a geometric point that use double floating points numbers.
Provides a geometric rectangle that use double floating points numbers.
double circumference() const
Returns the perimeter for the circle.
Definition: circle.cpp:39
cartesian_rectangle dimensions() const
Returns a bounding box around the circle.
Definition: circle.cpp:54
double radius() const
Half of the circle's diameter.
Definition: circle.cpp:68
bool inside(const cartesian_point &where) const
Returns true if the point is inside the circle.
Definition: circle.cpp:48
double area() const
Returns the area occupied by the circle.
Definition: circle.cpp:35
cartesian_point center() const
The point at the center of the circle.
Definition: circle.cpp:72
cartesian_point location(const double_angle &where) const
Returns the point on the circle that is at the angle "where".
Definition: circle.cpp:41
double diameter() const
Returns the length of the circle's bisecting line.
Definition: circle.cpp:37
double_angle provides a non-templated class for forward declarations.
Definition: angle.h:97
numeric_type distance(const point &p2) const
Returns the distance between ‘this’ and the second point ‘p2’.
Definition: point.h:133
numeric_type x() const
Definition: point.h:47
numeric_type y() const
Definition: point.h:48
#define PI_APPROX
An approximation of the fundamental circular constant.
Definition: definitions.h:41
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
type square(const type &a)
Returns the square of the object (which is a * a).
Definition: functions.h:92
Contains all of our objects for geometry and avoids name clashes.
Definition: angle.h:25
@ RADIANS
Definition: angle.h:30