GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
inside.c
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * MODULE: Vector library
5  *
6  * AUTHOR(S): Original author CERL, probably Dave Gerdes.
7  * Update to GRASS 5.7 Radim Blazek.
8  *
9  * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
10  *
11  * COPYRIGHT: (C) 2001 by the GRASS Development Team
12  *
13  * This program is free software under the GNU General Public
14  * License (>=v2). Read the file COPYING that comes with GRASS
15  * for details.
16  *
17  *****************************************************************************/
18 #include <grass/vector.h>
19 
20 double
21 dig_x_intersect(double beg_x,
22  double end_x, double beg_y, double end_y, double Y)
23 {
24  double b;
25 
26  /* assumes beg_y != end_y */
27 
28  /* sort for numerical stability */
29  if (end_x < beg_x || (end_x == beg_x && end_y < beg_y)) {
30  b = end_x;
31  end_x = beg_x;
32  beg_x = b;
33 
34  b = end_y;
35  end_y = beg_y;
36  beg_y = b;
37  }
38 
39  /* solve simple linear equation to get X = a + b * Y
40  * with
41  * b = (end_x - beg_x) / (end_y - beg_y)
42  * a = beg_x - b * beg_y
43  *
44  * simplify a + b * Y:
45  * a + b * Y = beg_x - b * beg_y + b * Y
46  * a + b * Y = beg_x + b * (Y - beg_y) */
47 
48  b = (end_x - beg_x) / (end_y - beg_y);
49 
50  return beg_x + b * (Y - beg_y);
51 }
double dig_x_intersect(double beg_x, double end_x, double beg_y, double end_y, double Y)
Definition: inside.c:21
double b
Definition: r_raster.c:39
#define Y
Definition: ogsf.h:138