angle.h revision e4369b05aaa20df73a37f4d319ce456865cc74f3
/**
* \file
* \brief Various trigoniometric helper functions
*//*
* Authors:
* Johan Engelen <goejendaagh@zonnet.nl>
* Marco Cecchetti <mrcekets at gmail.com>
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright (C) 2007-2010 Authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
*/
#ifndef LIB2GEOM_SEEN_ANGLE_H
#define LIB2GEOM_SEEN_ANGLE_H
#include <cmath>
#include <boost/operators.hpp>
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
#ifndef M_1_2PI
# define M_1_2PI 0.159154943091895335768883763373
#endif
/** @brief Wrapper for angular values.
*
* This class is a convenience wrapper that implements the behavior generally expected of angles,
* like addition modulo \f$2\pi\f$. The value returned from the default conversion
* to <tt>double</tt> is in the range \f$[-\pi, \pi)\f$ - the convention used by C's
* math library.
*
* This class holds only a single floating point value, so passing it by value will generally
* be faster than passing it by const reference.
*
* @ingroup Primitives
*/
> > > >
{
_normalize();
return *this;
}
_normalize();
return *this;
}
return *this;
}
return *this;
}
}
}
/** @brief Get the angle as radians.
* @return Number in range \f$[-\pi, \pi)\f$. */
}
/** @brief Get the angle as positive radians.
* @return Number in range \f$[0, 2\pi)\f$. */
return _angle;
}
/** @brief Get the angle as degrees in math convention.
* @return Number in range [-180, 180) obtained by scaling the result of radians()
* by \f$180/\pi\f$. */
/** @brief Get the angle as degrees in clock convention.
* This method converts the angle to the "clock convention": angles start from the +Y axis
* and grow clockwise. This means that 0 corresponds to \f$\pi/2\f$ radians,
* 90 to 0 radians, 180 to \f$-\pi/2\f$ radians, and 270 to \f$\pi\f$ radians.
* @return A number in the range [0, 360).
*/
Coord degreesClock() const {
return ret;
}
/** @brief Create an angle from its measure in radians. */
Angle a(d);
return a;
}
/** @brief Create an angle from its measure in degrees. */
return a;
}
/** @brief Create an angle from its measure in degrees in clock convention.
* @see Angle::degreesClock() */
// first make sure d is in [0, 360)
if (d < 0) d += 360.0;
Angle a;
return a;
}
void _normalize() {
//_angle -= floor(_angle * (1.0/(2*M_PI))) * 2*M_PI;
}
};
// the distance cannot be larger than M_PI.
}
/** @brief Directed angular interval.
*
* Wrapper for directed angles with defined start and end values. Useful e.g. for representing
* the portion of an ellipse in an elliptical arc. Both extreme angles are contained
* in the interval (it is a closed interval). Angular intervals can also be interptered
* as functions \f$f: [0, 1] \to [-\pi, \pi)\f$, which return the start angle for 0,
* the end angle for 1, and interpolate linearly for other values. Note that such functions
* are not continuous if the interval crosses the angle \f$\pi\f$.
*
* This class can represent all directed angular intervals, including empty ones.
* However, not all possible intervals can be created with the constructors.
* For full control, use the setInitial(), setFinal() and setAngles() methods.
*
* @ingroup Primitives
*/
{
AngleInterval() {}
/** @brief Create an angular interval from two angles and direction.
* If the initial and final angle are the same, a degenerate interval
* (containing only one angle) will be created.
* @param s Starting angle
* @param e Ending angle
* @param cw Which direction the interval goes. True means that it goes
* in the direction of increasing angles, while false means in the direction
* of decreasing angles. */
{}
AngleInterval(double s, double e, bool cw = false)
{}
/** @brief Create an angular interval from three angles.
* If the inner angle is exactly equal to initial or final angle,
* the sweep flag will be set to true, i.e. the interval will go
* in the direction of increasing angles.
*
* If the initial and final angle are the same, but the inner angle
* is different, a full angle in the direction of increasing angles
* will be created.
*
* @param s Initial angle
* @param inner Angle contained in the interval
* @param e Final angle */
: _start_angle(s)
, _end_angle(e)
{
if (_full) {
_sweep = true;
}
}
/// Get the start angle.
/// Get the end angle.
/// Check whether the interval goes in the direction of increasing angles.
/// Check whether the interval contains only a single angle.
bool isDegenerate() const {
}
/// Check whether the interval contains all angles.
bool isFull() const {
}
/** @brief Set the initial angle.
* @param a Angle to set
* @param prefer_full Whether to set a full angular interval when
* the initial angle is set to the final angle */
_start_angle = a;
}
/** @brief Set the final angle.
* @param a Angle to set
* @param prefer_full Whether to set a full angular interval when
* the initial angle is set to the final angle */
_end_angle = a;
}
/** @brief Set both angles at once.
* The direction (sweep flag) is left unchanged.
* @param s Initial angle
* @param e Final angle
* @param prefer_full Whether to set a full interval when the passed
* initial and final angle are the same */
_start_angle = s;
_end_angle = e;
_full = prefer_full && s == e;
}
/// Set whether the interval goes in the direction of increasing angles.
/// Reverse the direction of the interval while keeping contained values the same.
void reverse() {
}
/// Get a new interval with reversed direction.
AngleInterval reversed() const {
return result;
}
/// Get an angle corresponding to the specified time value.
return ret;
}
/** @brief Compute a time value that would evaluate to the given angle.
* If the start and end angle are exactly the same, NaN will be returned.
* Negative values will be returned for angles between the initial angle
* and the angle exactly opposite the midpoint of the interval. */
if (_full) {
}
if (_sweep) {
} else {
}
} else {
} else {
}
}
}
/// Check whether the interval includes the given angle.
if (_full) return true;
if (_sweep) {
if (s < e) return x >= s && x <= e;
return x >= s || x <= e;
} else {
if (s > e) return x <= s && x >= e;
return x <= s || x >= e;
}
}
/** @brief Extent of the angle interval.
* Equivalent to the absolute value of the sweep angle.
* @return Extent in range \f$[0, 2\pi)\f$. */
return _sweep
}
/** @brief Get the sweep angle of the interval.
* This is the value you need to add to the initial angle to get the final angle.
* It is positive when sweep is true. Denoted as \f$\Delta\theta\f$ in the SVG
* elliptical arc implementation notes. */
Coord sweepAngle() const {
return sa;
}
/// Check another interval for equality.
return true;
}
return result;
}
bool _sweep;
bool _full;
};
/** @brief Given an angle in degrees, return radians
* @relates Angle */
/** @brief Given an angle in radians, return degrees
* @relates Angle */
} // end namespace Geom
}
#endif // LIB2GEOM_SEEN_ANGLE_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :