point.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /****************************************************************
  2. *
  3. * MODULE: v.generalize
  4. *
  5. * AUTHOR(S): Daniel Bundala
  6. *
  7. * PURPOSE: Definition of a point in 3D and basic operations
  8. * with points
  9. *
  10. * COPYRIGHT: (C) 2002-2005 by the GRASS Development Team
  11. *
  12. * This program is free software under the
  13. * GNU General Public License (>=v2).
  14. * Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. ****************************************************************/
  18. #ifndef POINT_H
  19. #define POINT_H
  20. #include <grass/vector.h>
  21. typedef struct
  22. {
  23. double x, y, z;
  24. } POINT;
  25. typedef struct Point_list
  26. {
  27. POINT p;
  28. struct Point_list *next;
  29. } POINT_LIST;
  30. /* res = a - b */
  31. extern inline void point_subtract(POINT a, POINT b, POINT * res);
  32. /* res = a + b */
  33. extern inline void point_add(POINT a, POINT b, POINT * res);
  34. /* dot product of two vectors: ax * bx + ay * by + az * bz */
  35. extern double point_dot(POINT a, POINT b);
  36. /* squared distance from the origin */
  37. extern inline double point_dist2(POINT a);
  38. /* assign point Points[index] to the res
  39. * if with z = 0 then res.z = 0
  40. */
  41. extern inline void point_assign(struct line_pnts *Points, int index,
  42. int with_z, POINT * res, int is_loop);
  43. /* assign point Points[index] to the res
  44. * if with z = 0 then res.z = 0
  45. * loop to infinite
  46. */
  47. /* res = k * a */
  48. extern inline void point_scalar(POINT a, double k, POINT * res);
  49. /* copy the last point of Points to Points[pos] */
  50. extern inline void points_copy_last(struct line_pnts *Points, int pos);
  51. /* distance between two points */
  52. extern inline double point_dist(POINT a, POINT b);
  53. /* squared distance between two points */
  54. extern inline double point_dist_square(POINT a, POINT b);
  55. /* angle in radians between vectors ab and bc */
  56. extern inline double point_angle_between(POINT a, POINT b, POINT c);
  57. /* distance squared between a and segment bc */
  58. extern inline double point_dist_segment_square(POINT a, POINT b, POINT c,
  59. int with_z);
  60. /* creates empty list of points */
  61. extern POINT_LIST *point_list_new(POINT p);
  62. /* insert new value to the list just after the l. i.e l->next.p = p */
  63. extern void point_list_add(POINT_LIST * l, POINT p);
  64. /* copy POINT_LIST structure into line_pnts structure
  65. * return 0 on success, -1 on out of memory
  66. */
  67. extern int point_list_copy_to_line_pnts(POINT_LIST l,
  68. struct line_pnts *Points);
  69. /*free the momory occupied by the list at l.next */
  70. extern void point_list_free(POINT_LIST l);
  71. /*delete the p->next element and set the pointers appropriatelly */
  72. extern void point_list_delete_next(POINT_LIST * p);
  73. #endif