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