MCPcopy Create free account
hub / github.com/OSGeo/gdal / horizontalIntersect

Function horizontalIntersect

alg/viewshed/util.cpp:41–62  ·  view source on GitHub ↗

Compute the X intersect position on the line Y = y with a ray extending from (nX, nY) along `angle`. @param angle Angle in radians, standard arrangement. @param nX X coordinate of ray endpoint. @param nY Y coordinate of ray endpoint. @param y Horizontal line where Y = y. @return X intersect or NaN

Source from the content-addressed store, hash-verified

39/// @param y Horizontal line where Y = y.
40/// @return X intersect or NaN
41double horizontalIntersect(double angle, int nX, int nY, int y)
42{
43 double x = std::numeric_limits<double>::quiet_NaN();
44
45 if (nY == y)
46 x = nX;
47 else if (nY > y)
48 {
49 if (ARE_REAL_EQUAL(angle, M_PI / 2))
50 x = nX;
51 else if (angle > 0 && angle < M_PI)
52 x = nX + (nY - y) / std::tan(angle);
53 }
54 else // nY < y
55 {
56 if (ARE_REAL_EQUAL(angle, 3 * M_PI / 2))
57 x = nX;
58 else if (angle > M_PI)
59 x = nX - (y - nY) / std::tan(angle);
60 }
61 return x;
62}
63
64/// Compute the X intersect position on the line Y = y with a ray extending
65/// from (nX, nY) along `angle`.

Callers 2

TESTFunction · 0.85
hIntersectFunction · 0.85

Calls 1

ARE_REAL_EQUALFunction · 0.50

Tested by 1

TESTFunction · 0.68