2
$\begingroup$

I have a list of points {{4,5},{6,7},{9,8},...} in two-dimensions. I'd like to rotate these points some number of degrees $\theta$ around an arbitrary anchor point in a two-dimensional plane, and recover the transformed point list. Is there a straightforward way to do this? How about for three-dimensional rotations around an arbitrary point?

$\endgroup$
5
  • $\begingroup$ Have you checked the documentation center? is is very very easy to find in documentation and this question shows no research effort :/ $\endgroup$
    – Kuba
    Sep 8, 2013 at 15:04
  • $\begingroup$ @Kuba I've looked at Rotate, GeometricTransform, etc. but they all seem to apply to rotating graphical objects as opposed to point sets. $\endgroup$
    – ZWei
    Sep 8, 2013 at 15:08
  • $\begingroup$ If type in "rotation" the second result is RotationTransform. It is always good idea to check related links at the bottom of each documentation page because RotationTranform appears for example in Rotate page. $\endgroup$
    – Kuba
    Sep 8, 2013 at 15:12
  • $\begingroup$ @Kuba Is it necessary for me to manually enter in and multiply each point by the appropriate rotation matrix? Shouldn't there be a function that takes the point set, a rotation anchor, and then some rotation parameter? I can't seem to find it. $\endgroup$
    – ZWei
    Sep 8, 2013 at 15:13
  • $\begingroup$ RotationTransform[angle \[Degree], anchor] /@ set $\endgroup$
    – Kuba
    Sep 8, 2013 at 15:15

1 Answer 1

6
$\begingroup$

I think RotationTransform is what you are looking for.

data = {{4, 5}, {6, 7}, {9, 8}};
r[angle_?NumericQ, pivot:{_?NumericQ, _?NumericQ}] = RotationTransform[angle Degree, pivot];
r[45, {1, 1}] /@ data // N
{{0.292893, 5.94975}, {0.292893, 8.77817}, {1.70711, 11.6066}}

Update

As Carl Woll points out in his comment below, the transformation function returned by RotationTransform acts if it has the Listable property, so

r[45, {1, 1}] /* N @ data

also works.

$\endgroup$
7
  • $\begingroup$ Thanks. For the purposes of my understanding, what is the purpose of angle?NumericQ? $\endgroup$
    – ZWei
    Sep 8, 2013 at 15:15
  • $\begingroup$ @Kuba. Thanks for pointing out the typos. I have corrected them. $\endgroup$
    – m_goldberg
    Sep 8, 2013 at 15:28
  • 1
    $\begingroup$ @ZWei angle_?NumericQ is a pattern test which will run the function only if you pass Numeric variable for the first argumen $\endgroup$
    – Kuba
    Sep 8, 2013 at 15:29
  • $\begingroup$ No need for Map, you can just use r[45, {1, 1}][data]. $\endgroup$
    – Carl Woll
    Feb 21, 2018 at 19:11
  • 1
    $\begingroup$ @anderstood. It is RightComposition $\endgroup$
    – m_goldberg
    Feb 22, 2018 at 0:28

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.