GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
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 * SPDX-FileCopyrightText: 2001 GRASS Development Team
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
13 *****************************************************************************/
14
15#include <grass/vector.h>
16
17double dig_x_intersect(double beg_x, double end_x, double beg_y, double end_y,
18 double Y)
19{
20 double b;
21
22 /* assumes beg_y != end_y */
23
24 /* sort for numerical stability
25 * ray along X for given Y -> sort by Y */
26 if (end_y < beg_y || (end_y == beg_y && end_x < beg_x)) {
27 b = end_x;
28 end_x = beg_x;
29 beg_x = b;
30
31 b = end_y;
32 end_y = beg_y;
33 beg_y = b;
34 }
35
36 /* solve simple linear equation to get X = a + b * Y
37 * with
38 * b = (end_x - beg_x) / (end_y - beg_y)
39 * a = beg_x - b * beg_y
40 *
41 * simplify a + b * Y:
42 * a + b * Y = beg_x - b * beg_y + b * Y
43 * a + b * Y = beg_x + b * (Y - beg_y)
44 * a + b * Y = beg_x + (end_x - beg_x) * (Y - beg_y) / (end_y - beg_y) */
45
46 b = (Y - beg_y) / (end_y - beg_y); /* always within [0, 1] */
47
48 return beg_x + b * (end_x - beg_x);
49}
double dig_x_intersect(double beg_x, double end_x, double beg_y, double end_y, double Y)
Definition inside.c:17
#define Y
Definition ogsf.h:142
double b
Definition r_raster.c:37