1
$\begingroup$

If we have a pair of coordinates $(x,y)$, let's say

pt = {1,2}

then we can easily rotate the coordinates, by an angle $\theta$, by using the rotation matrix

R = {{Cos[\[Theta]], -Sin[\[Theta]]}, {Sin[\[Theta]], Cos[\[Theta]]}};

as

pt2 = pt.R;

Now let's assume that we have a collection of points in the form

data = {{1}, {-0.3, 1}, {2, -0.2}, {2}, {-2, 1}, {4,-2}, {3}, {1, 1}, {-0.2, -0.3}}

where the integers 1, 2 and 3 count the subsets of the list data.

My question: how can we rotate the $(x,y)$ coordinates of the list data by and angle, let's say $2\pi/3$ and create a new list, data2 of the form

data2 = {{1}, {rotated x, rotated y}, {rotated x, rotated y}, {2}, {rotated x, rotated y}, {roatetd x, rotated y}, ...}

Any suggestions?

$\endgroup$
3
$\begingroup$

This should give what you want:

data2=data/.{x_?NumericQ,y_?NumericQ}:>RotationMatrix[\[Theta]].{x,y}
| improve this answer | |
$\endgroup$
2
$\begingroup$

Maybe this way?

data = {{1}, {-0.3, 1}, {2, -0.2}, {2}, {-2, 1}, {4, -2}, {3}, {1, 1}, {-0.2, -0.3}};
R = {{Cos[\[Theta]], -Sin[\[Theta]]}, {Sin[\[Theta]], Cos[\[Theta]]}};
data2 = data;
data2[[2 ;; ;; 3]] = data[[2 ;; ;; 3]].Transpose[R];
data2[[3 ;; ;; 3]] = data[[3 ;; ;; 3]].Transpose[R];

However, I advice not to store your data this way because, as a ragged list, it cannot be packed.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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