6
$\begingroup$

I have the following list of points

L = {
    {-0.980187,-1.07694}, {-0.980187,1.07694},
    {-0.788396,-1.81236},{-0.788396,1.81236},
    {-0.437793,-1.07694},{-0.437793,1.07694},
    {-0.157935,-1.81236},{-0.157935,1.81236},
    {0.157935,-1.81236},{0.157935,1.81236},
    {0.437793,-1.07694},{0.437793,1.07694},
    {0.788396,-1.81236},{0.788396,1.81236},
    {0.980187,-1.07694},{0.980187,1.07694}
}

Which are distributed in four symmetric sets each having the points $(x,y), (-x,y),(x,-y),(-x,-y)$

(see image below). enter image description here

I'd like to group the points based in their symmetry in a new list L1 in the following way

$L1 = \{l1,l2,l3,l4\},$ where $l_i = \{\{x_i, y_i\},\{-x_i, y_i\},\{x_i, -y_i\},\{-x_i, -y_i\}\}, i=1,2,3,4$

$\endgroup$

4 Answers 4

9
$\begingroup$

I would use GatherBy[data,Abs]

ClearAll[L, l];

L = GatherBy[data, Abs];

l[n_] := L[[n]]

ListPlot[ L ]

enter image description here

$\endgroup$
1
  • $\begingroup$ This is really amazing and works for any list what ever the length is. Thank you :) $\endgroup$
    – A. PI
    Commented Feb 1, 2023 at 11:37
3
$\begingroup$

Just another way:

Map[Extract[L, #] &, Reverse@Partition[List /@ OrderingBy[L, Abs], {4}]] // ListPlot

enter image description here

$\endgroup$
2
$\begingroup$
l1 = Select[L, #[[1]] > 0 && #[[2]] > 0 &]
l2 = Select[L, #[[1]] < 0 && #[[2]] > 0 &]
l3 = Select[L, #[[1]] > 0 && #[[2]] < 0 &]
l4 = Select[L, #[[1]] < 0 && #[[2]] < 0 &]

Visualization

ListPlot[{l1, l2, l3, l4}, PlotRange -> {{-1.1, 1.1}, {-2.1, 2.1}}]

lp

$\endgroup$
2
  • $\begingroup$ Thank you for this answer. GatherBy seems to be easier. $\endgroup$
    – A. PI
    Commented Feb 1, 2023 at 11:39
  • 4
    $\begingroup$ I interpreted this question similarly. $\endgroup$
    – Syed
    Commented Feb 1, 2023 at 11:39
2
$\begingroup$
list = {
    {-0.980187,-1.07694}, {-0.980187,1.07694},
    {-0.788396,-1.81236}, {-0.788396,1.81236},
    {-0.437793,-1.07694}, {-0.437793,1.07694},
    {-0.157935,-1.81236}, {-0.157935,1.81236},
    {0.157935,-1.81236}, {0.157935,1.81236},
    {0.437793,-1.07694}, {0.437793,1.07694},
    {0.788396,-1.81236}, {0.788396,1.81236},
    {0.980187,-1.07694}, {0.980187,1.07694}};

Using SequenceCases and SortBy

ListPlot @ Reverse @ SequenceCases[SortBy[list, Abs], {_, _, _, _}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.