41 inline double max (
double a,
double b,
double c)
44 return (b < c ? c : b);
46 return (a < c ? c : a);
49 inline double min (
double a,
double b,
double c)
52 return (b > c ? c : b);
54 return (a > c ? c : a);
57 #define REF(x,k,i) x(static_cast<octave_idx_type>(elem((k), (i))) - 1)
69 @deftypefn {Loadable Function} {@var{idx} =} tsearch (@var{x}, @var{y}, @var{t}, @var{xi}, @var{yi})\n\
70 Search for the enclosing Delaunay convex hull. For @code{@var{t} =\n\
71 delaunay (@var{x}, @var{y})}, finds the index in @var{t} containing the\n\
72 points @code{(@var{xi}, @var{yi})}. For points outside the convex hull,\n\
74 @seealso{delaunay, delaunayn}\n\
77 const double eps=1.0e-12;
80 const int nargin = args.
length ();
113 double x0 = 0.0, y0 = 0.0;
114 double a11 = 0.0, a12 = 0.0, a21 = 0.0, a22 = 0.0, det = 0.0;
119 const double xt =
xi(kp);
120 const double yt = yi(kp);
125 const double dx1 = xt - x0;
126 const double dx2 = yt - y0;
127 const double c1 = (a22 * dx1 - a21 * dx2) / det;
128 const double c2 = (-a12 * dx1 + a11 * dx2) / det;
129 if (c1 >= -eps && c2 >= -eps && (c1 + c2) <= (1 +
eps))
137 for (k = 0; k < nelem; k++)
140 if (xt >= minx(k) && xt <= maxx(k) && yt >= miny(k) && yt <= maxy(k))
145 a11 =
REF (x, k, 1) - x0;
146 a12 =
REF (y, k, 1) - y0;
147 a21 =
REF (x, k, 2) - x0;
148 a22 =
REF (y, k, 2) - y0;
149 det = a11 * a22 - a21 * a12;
152 const double dx1 = xt - x0;
153 const double dx2 = yt - y0;
154 const double c1 = (a22 * dx1 - a21 * dx2) / det;
155 const double c2 = (-a12 * dx1 + a11 * dx2) / det;
156 if ((c1 >= -eps) && (c2 >= -
eps) && ((c1 + c2) <= (1 +
eps)))