Skip to main content

Questions tagged [nearest]

Questions on the usage of Nearest and creating a custom distance function for it; also on NearestNeighborGraph, RegionNearest, GeoNearest and related concepts.

Filter by
Sorted by
Tagged with
1 vote
1 answer
63 views

Problem with RegionNearest?

Consider the following region: ...
John Taylor's user avatar
  • 5,753
0 votes
0 answers
67 views

Compilable analog of Nearest?

Is there any analog of Nearest that is compilable? ...
John Taylor's user avatar
  • 5,753
1 vote
1 answer
86 views

Nearest inside Minimize

How to use Nearest inside Minimize? The following returns errors but if # - {a, b} is ...
azerbajdzan's user avatar
  • 17.5k
1 vote
1 answer
60 views

`FindMinimum` can't evaluate `Nearest` numerically

I'm trying to use Nearest as a function to minimize over: a toy example is ...
Adam's user avatar
  • 3,946
2 votes
1 answer
55 views

How to predict number from a set of data?

I have 2 sets of data. For example, ...
user8357568's user avatar
6 votes
1 answer
180 views

Fastest Way to Find nearest indices between two sorted lists

I have a sorted list of floats of length n and an n x n list of lists, where each nested ...
az123p's user avatar
  • 239
1 vote
1 answer
53 views

Issue with using complexplot with Nearest

I have been trying to create a certain fractal with Mathematica but the main issue is that if I try and do something like ...
Brandon Nadel's user avatar
2 votes
2 answers
150 views

Finding the minimal distance of a point from an interpolated function

I have an interpolating parametric function (solution of a set of differential equations) and I have an external point. I would like to find the minimal distance between this point and the ...
VDF's user avatar
  • 453
4 votes
2 answers
119 views

Selecting the Nearest First

Imagine I have the following list ...
sam wolfe's user avatar
  • 4,693
1 vote
1 answer
164 views

Finding the smallest bounding simplex [closed]

I would like to find the subset of points from a set of d-dimensional points that defines the smallest bounding simplex around a given point. For example, given a set of 3-dimensional points S1 and ...
Attila Sragli's user avatar
0 votes
1 answer
63 views

How to obtain the grouped separate line curves from the disorder data?

The sample point data and codes are listed as following. The point-image tells us that the data can be divided into nine groups. However, why are they divided into two groups by ...
likehust's user avatar
  • 693
3 votes
1 answer
141 views

How do I create an STL file from nearest neighbour graph edges?

I'm trying to figure out to deal with (and design) .stl files within Mathematica. As an example, I would like to generate a FCC lattice without the atoms (but connecting all nearest neighbours), and ...
Letshin's user avatar
  • 475
7 votes
2 answers
224 views

Why does Nearest not return both equally distant values?

Define the following three vectors: a = {0., 0., 0.}; b = {-0.5`, 0.4330127018922193`, 0.25`}; c = {-0.5`, 0.`, 0.`}; Note that the distance from a to c is the ...
abwatson's user avatar
  • 1,919
1 vote
2 answers
222 views

How to find the shortest distance between two regions?

I need to find the shortest distance between the two regions and the two points of the shortest distance, but the following code cannot achieve this requirement: ...
A little mouse on the pampas's user avatar
8 votes
1 answer
225 views

Furthest point from nearby objects, packing a sphere on a region interior

Suppose I have a boundary $\partial\Omega$ of a region $\Omega\subset \mathbb{R}^3$ and within this are some compact objects $B_i\subset\Omega$. They could be points, lines, polygons, complex 3D ...
flinty's user avatar
  • 25.3k
2 votes
1 answer
108 views

How to get a NearestNeighborGraph[] for a given radius with periodic boundaries?

I'm wondering if there's a way to use NearestNeighborGraph with periodic boundaries, using all nearest neighbors within some radius. I am aware of similar custom ...
TumbiSapichu's user avatar
  • 1,603
4 votes
2 answers
330 views

Position of Nearest in sublist

I want to get the position of nearest value or the position of the value in a certain range. When I have the list, such as ...
nancy's user avatar
  • 147
1 vote
0 answers
94 views

Nearest Region of a Point-cloud

For a given examplary set of points p(2D) with known NearestFunction nf ...
Ulrich Neumann's user avatar
9 votes
2 answers
572 views

Drawing lines between nearest neighbor points

I am reading a file with 4 columns (índex and 3 coordinates) and I want to plot spheres at these positions: ...
Oscar Iglesias Clotas's user avatar
6 votes
1 answer
65 views

NearestTo causes a kernel crash when applied to a list of SparseArrays [closed]

Nearest and NearestTo cause a kernel crash on Mathematica 12.0.0 for Mac OS X. (running on OS X 10.11.6) when operating on a list of SparseArray vectors. Here's my minimal breaking example: ...
Joshua Schrier's user avatar
2 votes
2 answers
129 views

How to Create an Efficient Step Function from Data

I have list of rules from where a DateListStepPlot can be created to visualize the problem: ...
Ariel Sepulveda's user avatar
4 votes
2 answers
771 views

Find the smallest and largest distance between two points distributed in 3D space

Suppose I have some 3D points, e.g. {{0, 0, 1}, {0, 0, 1.3}, {0, 1, 0}, {1.2, 0, 0}}. Now I want to find the smallest and largest distance between two points. A ...
Schrodinger's user avatar
10 votes
2 answers
251 views

Efficient multicolor search

I'm hoping someone can help me improve the following fun code-snippet, which takes a target color and searches through a set of images to find the ones that most closely match: ...
M.R.'s user avatar
  • 31.5k
0 votes
0 answers
32 views

Ordering a list of elements as shortest euclidean distance between two points [duplicate]

I've got a list of points: ...
prm's user avatar
  • 21
9 votes
2 answers
466 views

Speeding up Nearest with multiple distance thresholds

Consider the following example of using Nearest: ...
Szabolcs's user avatar
  • 235k
14 votes
3 answers
499 views

Is there a built-in function I can use to measure the similarity of two trees?

This is a higher level question, and I don't expect a full answer, but maybe a nudge in the right direction would help, or maybe there is a built in Mathematica function that does something very ...
Jmeeks29ig's user avatar
  • 1,447
4 votes
2 answers
290 views

How to use Nearest as a lookup function?

I have data1 and a target point targetPts, and want to find the closest point from the data. As you can see from below, the 29th ...
H42's user avatar
  • 3,479
9 votes
3 answers
323 views

How to connect all points in a graph generated by a set of given vertexes?

I am trying to construct a tree by looking at the nearest neighbors (or just approximately nearest for higher efficient) of a set of given vertexes. I first try this:- ...
H42's user avatar
  • 3,479
1 vote
0 answers
152 views

Estimating Lyapunov exponent from a time series problem [duplicate]

I am trying to use this code for estimating L.e.: ...
Mark Foster's user avatar
6 votes
2 answers
263 views

Find the element in a list of triples which has z-coordinate nearest a specified value

Here is my list coordinate {x,y,z} ...
SelfA's user avatar
  • 235
1 vote
2 answers
1k views

Finding the x-value corresponding to a y-value found using Nearest [closed]

I have a large 2d array of infinite precision named "data" of x values and y values. I am using Nearest to find the y-value closest to a specified number, say 0....
Zack Carson's user avatar
3 votes
0 answers
152 views

Getting Distances from Nearest Function [closed]

I am fairly new to mathematica. I am trying to find a way to mock python's KDTree.query function in mathematica. Basically I have 9 vectors (each length two). I want to know the three closest vectors ...
bnp's user avatar
  • 31
5 votes
4 answers
265 views

Forming tracks of coordinates depending on distance

I have a list that consists of certain number of coordinates sub-lists (here 8). (The following data are only an example to describe my problem.) ...
mrz's user avatar
  • 11.7k
1 vote
1 answer
163 views

Define a 3D surface for input in Region function

I am looking for the shortest distance from a 3D surface to a random point, and also for the exact point on the surface. These are the definitions and visualization. ...
Thomas Rademaker's user avatar
5 votes
1 answer
418 views

Nearest non-collinear/non-coplanar points

This is a long post. Most of it is just an introduction so the question itself is understandable. The question is in bold. Just skip to it if you want to hear the point. Everything below the question ...
user16320's user avatar
  • 2,396
2 votes
1 answer
97 views

How can I get get index and distance in Nearest functions in Low Version [closed]

Nearest[{"I'm", "sorry", "Dave"} -> All, "David"] {<|"Element" -> "Dave", "Index" -> 3, "Distance" -> 2|>} However, in a WolframScript.wl file, ...
HyperGroups's user avatar
  • 8,619
4 votes
1 answer
459 views

Opposite of Nearest?

There is an useful function Nearest in Mathematica, which finds the element in the aggregate given as its 1st argument that is nearest to its 2nd argument. It is ...
Mike's user avatar
  • 297
1 vote
0 answers
116 views

A question for Nearest [closed]

Assume that I want to get nearest 10 points of a thousand random points in a given area to original point in three-dimensional coordinate system. Does anyone know how the ...
吴剑涛's user avatar
  • 123
1 vote
2 answers
257 views

Using Nearest with periodic boundary conditions of a list

Take the list e = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} I want to get the nearest points but with a wraparound condition. So lets say I want to find the 5 nearest ...
Luca Pontiggia's user avatar
5 votes
1 answer
823 views

How to rapidly find the nearest pairs of points in different clusters

Background For speed up this question or this question,I have such need. Current try: Suppose I have $3$ clusters of points: ...
yode's user avatar
  • 26.8k
6 votes
2 answers
296 views

How to find the index of a facet of a boundary mesh region closest to a given point?

Using the RegionNearest[] function, it is possible to calculate the point, $p_{mesh}$, on a mesh region that is nearest to some input point, $p_{input}$. My ...
Dunlop's user avatar
  • 4,023
3 votes
1 answer
1k views

Better way to use Nearest

I'm trying to write a snippet of code that, given an input value (value), checks a list of arbitrary length (data) for the ...
Nate's user avatar
  • 103
2 votes
3 answers
330 views

Finding nearest element to a line in a two-dimensional array

I have a 2-dimensional list of data of $x$ and $y$ coordinates. I am looking for a way to get the element of the list which has the closest $y$ value to a given $y$ value. I tried using ...
Suppenkasper's user avatar
3 votes
3 answers
297 views

Question about Nearest [duplicate]

In the following example Nearest finds the nearest values between list1 and list2 and ...
mrz's user avatar
  • 11.7k
4 votes
3 answers
786 views

Remove 2D points where nearest neighbor exceeds certain distance

I have the following 2D points: ...
mrz's user avatar
  • 11.7k
5 votes
3 answers
472 views

Mean distance beween nearest 2 coordinates

I have as an example the following 2d-coordinates: ...
mrz's user avatar
  • 11.7k
4 votes
2 answers
378 views

Tracing 2d coordinates by using Nearest function

In 5 digital images I have determined the 2d coordinates of detected objects. The resulting coordinate list can be downloaded from here: http://pastebin.com/7bE0CEJ5 ...
mrz's user avatar
  • 11.7k
1 vote
3 answers
261 views

Why won't DiscretizeRegion work with a custom distance function?

I am trying (in 10.0) to create a region from a list of data points. I have created myDistance to use as the boolean test for whether or not a point should be included in the region ...
djphd's user avatar
  • 362
4 votes
1 answer
313 views

Draw lines between all neighbours

I have seen this question, but what I want is a bit different. I have a set of data (blue points) and I would like to end up with something like this: , i.e. joining each site with all its (nearest)...
SuperCiocia's user avatar
  • 1,472
1 vote
1 answer
287 views

precision and speed inefficiency issues of Nearest function with sqrt expression [closed]

Recently, Nearest has been attacked for many bugs. Some are already fixed. I am going to show some issues when Nearest applied ...
matheorem's user avatar
  • 17.1k