1 /*****************************************************************************\
4 * Author : Chris Koeritz *
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 \*****************************************************************************/
16 #include "cartesian_objects.h"
18 #include "rectangle.h"
20 #include <basis/functions.h>
24 using namespace basis;
28 circle::circle() : _radius(1), _center(cartesian_point::origin()) {}
30 circle::circle(double a_radius, const cartesian_point &a_center)
31 : _radius(a_radius), _center(a_center) {}
35 double circle::area() const { return PI_APPROX * square(_radius); }
37 double circle::diameter() const { return 2.0 * _radius; }
39 double circle::circumference() const { return 2.0 * PI_APPROX * _radius; }
41 cartesian_point circle::location(const double_angle &where) const
43 double rotation = where.get(RADIANS);
44 cartesian_point second(cos(rotation) * _radius, sin(rotation) * _radius);
45 return _center + second;
48 bool circle::inside(const cartesian_point &where) const
50 double dist = where.distance(_center);
51 return dist <= _radius? true : false;
54 cartesian_rectangle circle::dimensions() const
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;
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());
68 double circle::radius() const { return _radius; }
70 void circle::radius(double to_set) { _radius = to_set; }
72 cartesian_point circle::center() const { return _center; }
74 void circle::center(const cartesian_point &to_set) { _center = to_set; }