# TSEARCH Replacing MATLAB's TSEARCH() Function

TSEARCH is a MATLAB library which compares several replacements for MATLAB's obsolete tsearch() function, which searched a Delaunay triangulation to find the triangle that encloses a given point.

Given a set of points P, it is possible to compute the Delaunay triangulation D(P), and then to very efficiently answer the question, what triangle T in D(P) contains a query point Q?

In earlier versions of MATLAB, this could be done by the following calls:

```        d = delaunay ( px, py );
t = tsearch ( px, py, d, qx, qy );
```

A MATLAB function mytsearch() was written, which allows the user to supply an initial guess for the triangle; if the guess is incorrect, then tsearch() is called to find the correct answer.

```        d = delaunay ( px, py );
t = guess values;
t = tsearch_mex ( px, py, d, qx, qy, t );
```

A C function has been made available, which follows MATLAB's MEX interface standards, and which can also be used for this computation:

```        d = delaunay ( px, py );
t = tsearch_mex ( px, py, d, qx, qy );
```

But now tsearch() has been deleted, and the recommended calls are:

```        d = DelaunayTri ( p );
t = PointLocation ( d, q);
```

The main purpose of the files in this directory is to examine the behavior of these various options.

### Languages:

TSEARCH is available in a MATLAB version.

### Related Data and Programs:

MESH2D, a MATLAB library which can automatically create a triangular mesh for a given polygonal region, by Darren Engwirda.

TRIANGULATION, a MATLAB library which performs various operations on order 3 (linear) or order 6 (quadratic) triangulations, including searching a Delaunay triangulation to find which triangle contains a given point.

### Source Code:

• mytsearch.m, a "front end" to MATLAB's tsearch(), intended to improve its performance. If the user supplies a valid initial guess for each query point, then mytsearch() can execute without calling tsearch(). This function was written by Darren Engwirda.
• r8mat_uniform_01.m, returns an array of random values; does not rely on MATLAB's random number generator, and is easy to run on different machines.
• timestamp.m, prints the current YMDHMS date as a time stamp.
• tsearch_stub.m, the "stub" file that was MATLAB's tsearch() function. It simply calls a compiled MEX file named "tsrchmx".
• tsearch_mex.c, a C function which follows MATLAB's MEX interface requirements, and so can be compiled with MATLAB's MEX utility and used as a substitute for tsearch().

### Examples and Tests:

You can go up one level to the MATLAB source codes.