GRASS 8 Programmer's Manual 8.6.0dev(2026)-f808a6d29a
Loading...
Searching...
No Matches
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
20double 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 * ray along X for given Y -> sort by Y */
29 if (end_y < beg_y || (end_y == beg_y && end_x < beg_x)) {
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 * a + b * Y = beg_x + (end_x - beg_x) * (Y - beg_y) / (end_y - beg_y) */
48
49 b = (Y - beg_y) / (end_y - beg_y); /* always within [0, 1] */
50
51 return beg_x + b * (end_x - beg_x);
52}
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