1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
// $Id: Angle.hh,v 1.2 2002/10/04 13:44:00 flaterco Exp $
// Angle: abstraction to partially alleviate degrees versus radians debate.
// All angles are "normalized" to the 0-2pi rad (0-360 degree) range.
/*
Copyright (C) 1997 David Flater.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
class Angle {
public:
enum units {DEGREES, RADIANS};
// FIXME: Alternatives to "degrees true?"
enum qualifier {NONE, TRU};
// "TRUE" avoided due to likely reserved word conflicts.
Angle ();
Angle (units u, double v);
Angle (units u, qualifier q, double v);
// As of now, the qualifier does nothing for Angle but is used in
// output routines to decide whether to print degrees true or just
// plain old degrees.
// Return value in whichever units.
double deg();
double rad();
qualifier qual();
// Pretty-print degrees with specified number of digits after decimal.
// Uses static internal buffer. Field width is precision plus 4 if
// precision is greater than 0; if precision is 0, width is 3. This
// does not append a degrees symbol or qualifier.
Dstr &ppdeg (unsigned precision);
// This appends a degrees symbol and possibly a qualifier, and does not
// have fixed field width.
Dstr &ppqdeg (unsigned precision);
// Operations.
Angle &operator+= (Angle a);
Angle &operator-= (Angle a);
Angle &operator*= (double a);
protected:
// The preferred unit is radians since that is what is supported
// most efficiently by libm.
double radians;
qualifier myqual;
void normalize();
void setup(units u, qualifier q, double v);
};
class Degrees: public Angle {
public:
Degrees (double v);
};
class Radians: public Angle {
public:
Radians (double v);
};
// Operations.
Angle operator+ (Angle a, Angle b);
Angle operator- (Angle a, Angle b);
Angle operator* (double a, Angle b);
Angle operator* (Angle a, double b);
int operator> (Angle a, Angle b);
int operator< (Angle a, Angle b);
int operator>= (Angle a, Angle b);
int operator<= (Angle a, Angle b);
int operator== (Angle a, Angle b);
int operator!= (Angle a, Angle b);
// Trig functions.
double sin (Angle a);
double cos (Angle a);
double tan (Angle a);
double cot (Angle a);
|