Angle.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2009-2011 Sandro Santilli <strk@kbt.io>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: algorithm/Angle.java r378 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/algorithm/Orientation.h> // for constants
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
}
}
namespace geos {
namespace algorithm { // geos::algorithm
//
class GEOS_DLL Angle {
public:
static constexpr double PI_TIMES_2 = 2.0 * MATH_PI;
static constexpr double PI_OVER_2 = MATH_PI / 2.0;
static constexpr double PI_OVER_4 = MATH_PI / 4.0;
static const int COUNTERCLOCKWISE = Orientation::COUNTERCLOCKWISE;
static const int CLOCKWISE = Orientation::CLOCKWISE;
static const int NONE = Orientation::COLLINEAR;
static double toDegrees(double radians);
static double toRadians(double angleDegrees);
static double angle(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1);
//
static double angle(const geom::CoordinateXY& p);
static bool isAcute(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2);
static bool isObtuse(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2);
static double angleBetween(const geom::CoordinateXY& tip1,
const geom::CoordinateXY& tail,
const geom::CoordinateXY& tip2);
static double angleBetweenOriented(const geom::CoordinateXY& tip1,
const geom::CoordinateXY& tail,
const geom::CoordinateXY& tip2);
static double bisector(const geom::CoordinateXY& tip1,
const geom::CoordinateXY& tail,
const geom::CoordinateXY& tip2);
static double interiorAngle(const geom::CoordinateXY& p0,
const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2);
static int getTurn(double ang1, double ang2);
static double normalize(double angle);
static double normalizePositive(double angle);
static double diff(double ang1, double ang2);
static inline void sinCosSnap(const double ang, double& rSin, double& rCos) {
rSin = std::sin(ang);
rCos = std::cos(ang);
// snap near-zero values
if (std::fabs(rSin) < 5e-16) rSin = 0.0;
if (std::fabs(rCos) < 5e-16) rCos = 0.0;
}
static geom::CoordinateXY project(const geom::CoordinateXY& p,
double angle, double dist);
};
} // namespace geos::algorithm
} // namespace geos
geos::algorithm::Angle
Utility functions for working with angles.
Definition Angle.h:38
geos::algorithm::Angle::angle
static double angle(const geom::CoordinateXY &p)
Returns the angle that the vector from (0,0) to p, relative to the positive X-axis.
geos::algorithm::Angle::diff
static double diff(double ang1, double ang2)
geos::algorithm::Angle::bisector
static double bisector(const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
geos::algorithm::Angle::sinCosSnap
static void sinCosSnap(const double ang, double &rSin, double &rCos)
Computes both sin and cos of an angle, snapping near-zero values to zero.
Definition Angle.h:246
geos::algorithm::Angle::angleBetween
static double angleBetween(const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
geos::algorithm::Angle::getTurn
static int getTurn(double ang1, double ang2)
Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.
geos::algorithm::Angle::CLOCKWISE
static const int CLOCKWISE
Constant representing clockwise orientation.
Definition Angle.h:49
geos::algorithm::Angle::interiorAngle
static double interiorAngle(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
geos::algorithm::Angle::COUNTERCLOCKWISE
static const int COUNTERCLOCKWISE
Constant representing counterclockwise orientation.
Definition Angle.h:46
geos::algorithm::Angle::NONE
static const int NONE
Constant representing no orientation.
Definition Angle.h:52
geos::algorithm::Angle::project
static geom::CoordinateXY project(const geom::CoordinateXY &p, double angle, double dist)
geos::algorithm::Angle::isObtuse
static bool isObtuse(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
geos::algorithm::Angle::toDegrees
static double toDegrees(double radians)
geos::algorithm::Angle::angle
static double angle(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1)
Returns the angle of the vector from p0 to p1, relative to the positive X-axis.
geos::algorithm::Angle::normalizePositive
static double normalizePositive(double angle)
Computes the normalized positive value of an angle, which is the equivalent angle in the range [ 0,...
geos::algorithm::Angle::normalize
static double normalize(double angle)
Computes the normalized value of an angle, which is the equivalent angle in the range ( -Pi,...
geos::algorithm::Angle::isAcute
static bool isAcute(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
geos::algorithm::Angle::toRadians
static double toRadians(double angleDegrees)
geos::algorithm::Angle::angleBetweenOriented
static double angleBetweenOriented(const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38