Selecting points on either side of a curve

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite












I have the following array of data. Suppose I want only to keep data within the two lines. I can achieve my result using the following code:



data = Table[i, RandomReal[-10, 10], i, 0, 100];
line1[x_] := 0.1 x - 10;
line2[x_] := -0.1 x + 10;


enter image description here



rf = RegionMember[Polygon[0, line1[0], 0, line2[0], 100,line1[100]]];
bool1 = rf[data];
notbool1 = Not[#] & /@ bool1
datain = Pick[data, bool1];
dataout = Pick[data, notbool1];


This has the desired effect.



enter image description here



Now suppose I only have one line, since I can't make a closed region what would be the best way to select points either above or below a line? What if the curve is not a straight line? Any ideas?










share|improve this question























  • Related: mathematica.stackexchange.com/questions/97299/…
    – Michael E2
    Sep 10 at 16:04






  • 2




    Pick[data, RegionMember[HalfPlane[line1[0], line1[1], 0, -1], data]]
    – Michael E2
    Sep 10 at 16:09














up vote
5
down vote

favorite












I have the following array of data. Suppose I want only to keep data within the two lines. I can achieve my result using the following code:



data = Table[i, RandomReal[-10, 10], i, 0, 100];
line1[x_] := 0.1 x - 10;
line2[x_] := -0.1 x + 10;


enter image description here



rf = RegionMember[Polygon[0, line1[0], 0, line2[0], 100,line1[100]]];
bool1 = rf[data];
notbool1 = Not[#] & /@ bool1
datain = Pick[data, bool1];
dataout = Pick[data, notbool1];


This has the desired effect.



enter image description here



Now suppose I only have one line, since I can't make a closed region what would be the best way to select points either above or below a line? What if the curve is not a straight line? Any ideas?










share|improve this question























  • Related: mathematica.stackexchange.com/questions/97299/…
    – Michael E2
    Sep 10 at 16:04






  • 2




    Pick[data, RegionMember[HalfPlane[line1[0], line1[1], 0, -1], data]]
    – Michael E2
    Sep 10 at 16:09












up vote
5
down vote

favorite









up vote
5
down vote

favorite











I have the following array of data. Suppose I want only to keep data within the two lines. I can achieve my result using the following code:



data = Table[i, RandomReal[-10, 10], i, 0, 100];
line1[x_] := 0.1 x - 10;
line2[x_] := -0.1 x + 10;


enter image description here



rf = RegionMember[Polygon[0, line1[0], 0, line2[0], 100,line1[100]]];
bool1 = rf[data];
notbool1 = Not[#] & /@ bool1
datain = Pick[data, bool1];
dataout = Pick[data, notbool1];


This has the desired effect.



enter image description here



Now suppose I only have one line, since I can't make a closed region what would be the best way to select points either above or below a line? What if the curve is not a straight line? Any ideas?










share|improve this question















I have the following array of data. Suppose I want only to keep data within the two lines. I can achieve my result using the following code:



data = Table[i, RandomReal[-10, 10], i, 0, 100];
line1[x_] := 0.1 x - 10;
line2[x_] := -0.1 x + 10;


enter image description here



rf = RegionMember[Polygon[0, line1[0], 0, line2[0], 100,line1[100]]];
bool1 = rf[data];
notbool1 = Not[#] & /@ bool1
datain = Pick[data, bool1];
dataout = Pick[data, notbool1];


This has the desired effect.



enter image description here



Now suppose I only have one line, since I can't make a closed region what would be the best way to select points either above or below a line? What if the curve is not a straight line? Any ideas?







list-manipulation data






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 10 at 16:16









Henrik Schumacher

40k255120




40k255120










asked Sep 10 at 15:51









Giovanni Baez

470111




470111











  • Related: mathematica.stackexchange.com/questions/97299/…
    – Michael E2
    Sep 10 at 16:04






  • 2




    Pick[data, RegionMember[HalfPlane[line1[0], line1[1], 0, -1], data]]
    – Michael E2
    Sep 10 at 16:09
















  • Related: mathematica.stackexchange.com/questions/97299/…
    – Michael E2
    Sep 10 at 16:04






  • 2




    Pick[data, RegionMember[HalfPlane[line1[0], line1[1], 0, -1], data]]
    – Michael E2
    Sep 10 at 16:09















Related: mathematica.stackexchange.com/questions/97299/…
– Michael E2
Sep 10 at 16:04




Related: mathematica.stackexchange.com/questions/97299/…
– Michael E2
Sep 10 at 16:04




2




2




Pick[data, RegionMember[HalfPlane[line1[0], line1[1], 0, -1], data]]
– Michael E2
Sep 10 at 16:09




Pick[data, RegionMember[HalfPlane[line1[0], line1[1], 0, -1], data]]
– Michael E2
Sep 10 at 16:09










2 Answers
2






active

oldest

votes

















up vote
5
down vote



accepted










Some knowledge about (planar) analytic geometry facilitates this problem. Suppose now you only have line1, this



Select[data, line1[ #[[1]] ] < #[[2]] &]


selects out the points above line1; the key lies in the inequality. If it is connected by >, then the points below line1 you will get.






share|improve this answer





























    up vote
    3
    down vote













    in, out = GeneralUtilities`SelectDiscard[data, line1[#[[1]]]<=#[[2]]<=line2[#[[1]]]&];

    Show[ListPlot[in, out, PlotStyle -> Green, Red],
    Plot[line1@x, line2@x, x, 0, 100,
    Filling -> 1 -> 2, Opacity[.5, LightBlue], None]]


    enter image description here



    above1, below1 = GeneralUtilities`SelectDiscard[data, line1[#[[1]]] <= #[[2]] &];
    above2, below2 = GeneralUtilities`SelectDiscard[data, line2[#[[1]]] <= #[[2]] &];

    plt1, plt2 = Show[ListPlot[#, PlotStyle -> Green, Red],
    Plot[line1@x, line2@x, x, 0, 100,
    Filling -> 1 -> 2, Opacity[.5, LightBlue], None]] & /@
    above1,below1, above2, below2 ;
    Row[plt1, plt2, Spacer[5]]


    enter image description here



      
      






    share|improve this answer






















      Your Answer




      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "387"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181620%2fselecting-points-on-either-side-of-a-curve%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      5
      down vote



      accepted










      Some knowledge about (planar) analytic geometry facilitates this problem. Suppose now you only have line1, this



      Select[data, line1[ #[[1]] ] < #[[2]] &]


      selects out the points above line1; the key lies in the inequality. If it is connected by >, then the points below line1 you will get.






      share|improve this answer


























        up vote
        5
        down vote



        accepted










        Some knowledge about (planar) analytic geometry facilitates this problem. Suppose now you only have line1, this



        Select[data, line1[ #[[1]] ] < #[[2]] &]


        selects out the points above line1; the key lies in the inequality. If it is connected by >, then the points below line1 you will get.






        share|improve this answer
























          up vote
          5
          down vote



          accepted







          up vote
          5
          down vote



          accepted






          Some knowledge about (planar) analytic geometry facilitates this problem. Suppose now you only have line1, this



          Select[data, line1[ #[[1]] ] < #[[2]] &]


          selects out the points above line1; the key lies in the inequality. If it is connected by >, then the points below line1 you will get.






          share|improve this answer














          Some knowledge about (planar) analytic geometry facilitates this problem. Suppose now you only have line1, this



          Select[data, line1[ #[[1]] ] < #[[2]] &]


          selects out the points above line1; the key lies in the inequality. If it is connected by >, then the points below line1 you will get.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 10 at 16:11

























          answered Sep 10 at 16:01









          Αλέξανδρος Ζεγγ

          2,264725




          2,264725




















              up vote
              3
              down vote













              in, out = GeneralUtilities`SelectDiscard[data, line1[#[[1]]]<=#[[2]]<=line2[#[[1]]]&];

              Show[ListPlot[in, out, PlotStyle -> Green, Red],
              Plot[line1@x, line2@x, x, 0, 100,
              Filling -> 1 -> 2, Opacity[.5, LightBlue], None]]


              enter image description here



              above1, below1 = GeneralUtilities`SelectDiscard[data, line1[#[[1]]] <= #[[2]] &];
              above2, below2 = GeneralUtilities`SelectDiscard[data, line2[#[[1]]] <= #[[2]] &];

              plt1, plt2 = Show[ListPlot[#, PlotStyle -> Green, Red],
              Plot[line1@x, line2@x, x, 0, 100,
              Filling -> 1 -> 2, Opacity[.5, LightBlue], None]] & /@
              above1,below1, above2, below2 ;
              Row[plt1, plt2, Spacer[5]]


              enter image description here



                
                






              share|improve this answer


























                up vote
                3
                down vote













                in, out = GeneralUtilities`SelectDiscard[data, line1[#[[1]]]<=#[[2]]<=line2[#[[1]]]&];

                Show[ListPlot[in, out, PlotStyle -> Green, Red],
                Plot[line1@x, line2@x, x, 0, 100,
                Filling -> 1 -> 2, Opacity[.5, LightBlue], None]]


                enter image description here



                above1, below1 = GeneralUtilities`SelectDiscard[data, line1[#[[1]]] <= #[[2]] &];
                above2, below2 = GeneralUtilities`SelectDiscard[data, line2[#[[1]]] <= #[[2]] &];

                plt1, plt2 = Show[ListPlot[#, PlotStyle -> Green, Red],
                Plot[line1@x, line2@x, x, 0, 100,
                Filling -> 1 -> 2, Opacity[.5, LightBlue], None]] & /@
                above1,below1, above2, below2 ;
                Row[plt1, plt2, Spacer[5]]


                enter image description here



                  
                  






                share|improve this answer
























                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  in, out = GeneralUtilities`SelectDiscard[data, line1[#[[1]]]<=#[[2]]<=line2[#[[1]]]&];

                  Show[ListPlot[in, out, PlotStyle -> Green, Red],
                  Plot[line1@x, line2@x, x, 0, 100,
                  Filling -> 1 -> 2, Opacity[.5, LightBlue], None]]


                  enter image description here



                  above1, below1 = GeneralUtilities`SelectDiscard[data, line1[#[[1]]] <= #[[2]] &];
                  above2, below2 = GeneralUtilities`SelectDiscard[data, line2[#[[1]]] <= #[[2]] &];

                  plt1, plt2 = Show[ListPlot[#, PlotStyle -> Green, Red],
                  Plot[line1@x, line2@x, x, 0, 100,
                  Filling -> 1 -> 2, Opacity[.5, LightBlue], None]] & /@
                  above1,below1, above2, below2 ;
                  Row[plt1, plt2, Spacer[5]]


                  enter image description here



                    
                    






                  share|improve this answer














                  in, out = GeneralUtilities`SelectDiscard[data, line1[#[[1]]]<=#[[2]]<=line2[#[[1]]]&];

                  Show[ListPlot[in, out, PlotStyle -> Green, Red],
                  Plot[line1@x, line2@x, x, 0, 100,
                  Filling -> 1 -> 2, Opacity[.5, LightBlue], None]]


                  enter image description here



                  above1, below1 = GeneralUtilities`SelectDiscard[data, line1[#[[1]]] <= #[[2]] &];
                  above2, below2 = GeneralUtilities`SelectDiscard[data, line2[#[[1]]] <= #[[2]] &];

                  plt1, plt2 = Show[ListPlot[#, PlotStyle -> Green, Red],
                  Plot[line1@x, line2@x, x, 0, 100,
                  Filling -> 1 -> 2, Opacity[.5, LightBlue], None]] & /@
                  above1,below1, above2, below2 ;
                  Row[plt1, plt2, Spacer[5]]


                  enter image description here



                    
                    







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 11 at 3:23

























                  answered Sep 10 at 21:10









                  kglr

                  162k8187386




                  162k8187386



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181620%2fselecting-points-on-either-side-of-a-curve%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)