2

Consider the first example in the documentation of CrossingDetect:

CrossingDetect[{4, 0, 1, -2, 1, -2, -3, -1, 3}] // Normal

Let's plot the list:

ListLinePlot[{4, 0, 1, -2, 1, -2, -3, -1, 3}]

enter image description here

The red line obviously crosses (strictly!) the $x$-axis at least four times. Why does the Mathematica return the following, with only three 1, and at the given positions?

ListLinePlot[{4, 0, 1, -2, 1, -2, -3, -1, 3}] // Normal

(* {0, 0, 1, 0, 1, 0, 0, 0, 1} *)
anderstood
  • 14,301
  • 2
  • 29
  • 80
  • 1
    CrossingDetect "finds pixels [values in this case] with positive values that have at least one negative neighbor" - 1 on position 3 has; 1 at pos 5 has; 3 at pos 9 has - hence the output. So it finds points based on their neighbourhood, not crossings (that might happen between points, like here). – corey979 Sep 28 '16 at 17:02
  • @corey979 Mmmh I see. Not very intuitive for lists, given the name of the function! – anderstood Sep 28 '16 at 17:04
  • 2
    You can nevertheless detect all crossing with the option CornerNeighbors -> None - it works everytime except when a point is exactly 0 – Julien Kluge Sep 28 '16 at 17:14
  • @JulienKluge Would you like to write an answer? – anderstood Sep 28 '16 at 19:18
  • Okay, i did. ~~ – Julien Kluge Sep 28 '16 at 19:47

1 Answers1

3

via comments

First line of details from the documentation reveals:

CrossingDetect finds pixels with positive values that have at least one negative neighbor.

Pixels in our case are values of the array. So the search depends on the neighbors, not the crossings (in contradiction with the Name of the Function).

You can nevertheless bring the function to work if you specify the CornerNeighbors option.

CrossingDetect[points,CornerNeighbors->None]

This will work as intended with one exception: a crossing will not be detected if a point of the crossing-line is exactly 0.

Julien Kluge
  • 5,335
  • 1
  • 17
  • 29