GEOS 3.15.0dev
Angle.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2009-2011 Sandro Santilli <strk@kbt.io>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: algorithm/Angle.java r378 (JTS-1.12)
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/export.h>
22#include <geos/algorithm/Orientation.h> // for constants
23
24// Forward declarations
25namespace geos {
26namespace geom {
27class Coordinate;
28}
29}
30
31namespace geos {
32namespace algorithm { // geos::algorithm
33
35//
38class GEOS_DLL Angle {
39public:
40
41 static constexpr double PI_TIMES_2 = 2.0 * MATH_PI;
42 static constexpr double PI_OVER_2 = MATH_PI / 2.0;
43 static constexpr double PI_OVER_4 = MATH_PI / 4.0;
44
46 static const int COUNTERCLOCKWISE = Orientation::COUNTERCLOCKWISE;
47
49 static const int CLOCKWISE = Orientation::CLOCKWISE;
50
52 static const int NONE = Orientation::COLLINEAR;
53
59 static double toDegrees(double radians);
60
66 static double toRadians(double angleDegrees);
67
77 static double angle(const geom::CoordinateXY& p0,
78 const geom::CoordinateXY& p1);
79
83 //
89 static double angle(const geom::CoordinateXY& p);
90
102 static bool isAcute(const geom::CoordinateXY& p0,
103 const geom::CoordinateXY& p1,
104 const geom::CoordinateXY& p2);
105
117 static bool isObtuse(const geom::CoordinateXY& p0,
118 const geom::CoordinateXY& p1,
119 const geom::CoordinateXY& p2);
120
130 static double angleBetween(const geom::CoordinateXY& tip1,
131 const geom::CoordinateXY& tail,
132 const geom::CoordinateXY& tip2);
133
146 static double angleBetweenOriented(const geom::CoordinateXY& tip1,
147 const geom::CoordinateXY& tail,
148 const geom::CoordinateXY& tip2);
149
160 static double bisector(const geom::CoordinateXY& tip1,
161 const geom::CoordinateXY& tail,
162 const geom::CoordinateXY& tip2);
163
177 static double interiorAngle(const geom::CoordinateXY& p0,
178 const geom::CoordinateXY& p1,
179 const geom::CoordinateXY& p2);
180
190 static int getTurn(double ang1, double ang2);
191
199 static double normalize(double angle);
200
219 static double normalizePositive(double angle);
220
229 static bool isWithinCCW(double angle, double from, double to);
230
239 static double nextCCW(double from, double a, double b);
240
248 static double fractionCCW(double x, double a, double b);
249
260 static double diff(double ang1, double ang2);
261
274 static inline void sinCosSnap(const double ang, double& rSin, double& rCos) {
275 rSin = std::sin(ang);
276 rCos = std::cos(ang);
277 // snap near-zero values
278 if (std::fabs(rSin) < 5e-16) rSin = 0.0;
279 if (std::fabs(rCos) < 5e-16) rCos = 0.0;
280 }
281
289 static geom::CoordinateXY project(const geom::CoordinateXY& p,
290 double angle, double dist);
291
292};
293
294
295} // namespace geos::algorithm
296} // namespace geos
297
298
Utility functions for working with angles.
Definition Angle.h:38
static double angle(const geom::CoordinateXY &p)
Returns the angle that the vector from (0,0) to p, relative to the positive X-axis.
static double diff(double ang1, double ang2)
static double bisector(const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
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:274
static double angleBetween(const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
static int getTurn(double ang1, double ang2)
Returns whether an angle must turn clockwise or counterclockwise to overlap another angle.
static double nextCCW(double from, double a, double b)
static double interiorAngle(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
static geom::CoordinateXY project(const geom::CoordinateXY &p, double angle, double dist)
static bool isObtuse(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
static double toDegrees(double radians)
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.
static double normalizePositive(double angle)
Computes the normalized positive value of an angle, which is the equivalent angle in the range [ 0,...
static double fractionCCW(double x, double a, double b)
static double normalize(double angle)
Computes the normalized value of an angle, which is the equivalent angle in the range ( -Pi,...
static bool isAcute(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
static double toRadians(double angleDegrees)
static bool isWithinCCW(double angle, double from, double to)
static double angleBetweenOriented(const geom::CoordinateXY &tip1, const geom::CoordinateXY &tail, const geom::CoordinateXY &tip2)
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
Basic namespace for all GEOS functionalities.
Definition geos.h:38