# DeleteCases vs. DeleteDuplicates for removing points within a critical Euclidean distance

I'm attempting to remove all points in an array which are within a Euclidean distance "ThresDist" of one-another. Using the command:

DeleteDuplicates[List, EuclideanDistance[#1, #2] <= ThresDist &];


I can remove one point in a pair of points that fall within a distance "ThresDist" of one-another. However:

DeleteCases[List, EuclideanDistance[#1, #2] <= ThresDist  &];


Fails to work similarly. Is there something wrong with my approach?

Note : I made a typo earlier in writing DeleteCases, and also used a poor variable name. This was sloppy of me.

As for the actual question - how might I best accomplish my goal? I've searched through Mathematica's function directory, and I can't seem to find an appropriate way to prune not just a duplicate point, but all points that fall within a threshold distance of one-another?

• DeleteDCases is spelt incorrectly but assuming this is a typo. For DeleteCases you need to use a pattern and you will be parsing one argument to a function used as a pattern test or to a pattern condition – Mike Honeychurch Jul 18 '13 at 1:40
• I just updated my answer with relevant links; please read those and let us know if you have additional questions. – Mr.Wizard Jul 18 '13 at 2:22

## 1 Answer

You seem to be new around here so I am going to answer this, but others may close it as "a simple mistake."

• D is a reserved (System) Symbol; use d or dist etc. instead.

• DeleteDCases should be DeleteCases.

• DeleteCases looks at each element independently, not pairs of elements as does DeleteDuplicates (when using a custom equivalence function).

• DeleteCases requires a pattern, not a function, for the second argument.

Since you are making a number of mistakes I shall direct you to this massive omnibus collection of instructional resources:

Where can I find examples of good Mathematica programming practice?

In response to your updated question, specifically:

As for the actual question - how might I best accomplish my goal?

Please see:

Also related:

• I changed the actual variable name when I wrote this question to simplify things, and I have now fixed the problem. There was a typo for DeleteCases, and that has been fixed. – Intemediocre Jul 18 '13 at 1:47
• @Intemediocre Okay. I believe the other points still apply; I hope you find them helpful. – Mr.Wizard Jul 18 '13 at 1:50
• Yes, it's very helpful to know that DeleteCases and DeleteDuplicates don't work in the same manner! – Intemediocre Jul 18 '13 at 1:52
• Personally, I find these types of questions and answers beneficial to newcomers, so long as there are sufficient keywords to provide positive search results for future newcomers. – bobthechemist Jul 18 '13 at 2:37
• @bobthechemist I have no problem with these myself, so long as they are not frequent or persisting, but I am trying to respect community opinion as well. I only meant to warn the user that such questions might be closed by those who feel that they are too basic. – Mr.Wizard Jul 18 '13 at 7:15