inside.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. double
  20. dig_x_intersect(double beg_x,
  21. double end_x, double beg_y, double end_y, double Y)
  22. {
  23. double b;
  24. /* solve simple linear equation to get X = a + b * Y
  25. * with
  26. * b = (end_x - beg_x) / (end_y - beg_y)
  27. * a = beg_x - b * beg_y
  28. *
  29. * simplify a + b * Y:
  30. * a + b * Y = beg_x - b * beg_y + b * Y
  31. * a + b * Y = beg_x + b * (Y - beg_y) */
  32. b = (end_x - beg_x) / (end_y - beg_y);
  33. return beg_x + b * (Y - beg_y);
  34. }