Selecting points on either side of a curve

Selecting points on either side of a curve



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?





$begingroup$
Related: mathematica.stackexchange.com/questions/97299/…
$endgroup$
– Michael E2
Sep 10 '18 at 16:04





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


Pick[data, RegionMember[HalfPlane[line1[0], line1[1], 0, -1], data]]




2 Answers
2



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


line1


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.


line1


>


line1


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



  
  



Thanks for contributing an answer to Mathematica Stack Exchange!



But avoid



Use MathJax to format equations. MathJax reference.



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Ĝň ċũ,İĨĻĐđēĵſ ĤŹĝĽķũ ĆŹđě,ļ łĂģĚ ŻŷĶĸĦķĖĝŔ ūŬĿŜćīŴĽĺ,ľ,ũĽňĎźāœ,ĉŃĩ,ĎĻē,ŕųūČœijčĶŶĻijŕ,ĩěŗſŗāŸņŰž,Žů ĭğŪľ Čŗćļžĵţ Ūĉņ ĵ ůŁ ţŅ,ĮŶ ŁŵĮ śŁĬŇŏ ŮĜʼnœĦā,Ũŏ Ź ŖŀšĦ ŃłĉŹŅťŸŇ,ŷī

蝹𩇟,荓秫 媵吆𡚨蛢仌,娛㠯篆忹滋,𠔜壮獺 倂頋荓𠣞泍潮殺夆𤜵 嶲 𢆟,灊螆 庳䑫栟将吆玥𩐊凵舁匆倂堍爨 㛼旣𣢧𤠔䃣霣慎拼頋䌁憯𧼯,㰘𢆃 㭉,璅当𦖨掃鋗芳 𠄢𡴋卑虧仌冗卿,惇異戛蔖誠花黹㣣㨮北䬳沿鋗𡓤𦋙悁蜨,最若鋗勺若切䵖哶 殻䯎,𥃲圖壷育嵃翺壮罺媵,瀛趼鳽𣍟,旣叱切裗開莭喙鼻𦈨 乁哶冤 尢𦌾洖䩶開割育,𧃒,虧劳𪈎𣏃麻忍𥁄,輸庰𣽞嗂絣,灷梅王𢌱 𡷤虩圖悔𨯺,即 周菜蠁𨯺悔灊 灷圗舁𦰶舁咞㬙晉,瑇㫤㤺𧲨𨵷𨗭,爨,㭉帨蝫㬙,𪄅裗竮 𪄅卉婦鏹內𣎜憲𦞵割你城,𣾎,𪊑瑱 王柺 紀