7
$\begingroup$

If I have a group of points that are aligned along some vector. For example:

points = Table[{i + 10 RandomReal[{-1, 1}], 
    i + 10 RandomReal[{-1, 1}], i + 10 RandomReal[{-1, 1}]}, {i, 1, 
    30, 0.5}];
points = Table[points[[i]] - Mean[points], {i, 1, Length[points]}];

How can I take advantage of the built in rotation functions to rotate it so that the long axis of the data is oriented along the vector {0,1,0}?

$\endgroup$
8
$\begingroup$

Using points as given, you can use RotationMatrix,e.g. :

  Animate[Show[
  ListPointPlot3D[RotationMatrix[a, {0, 1, 0}].# & /@ points, 
   PlotStyle -> {Yellow, PointSize[0.02]}, 
   PlotRange -> Table[{-30, 30}, {3}], Background -> Black, 
   BoxRatios -> 1], 
  Graphics3D[{Red, Thickness[0.01], 
    Arrow[{{0, -30, 0}, {0, 30, 0}}]}]], {a, 0, 2 Pi}]

enter image description here

See comment below by @J.M.:

The rotation can be coded more directly using RotationTransform:, i.e.

RotationTransform[a,{0,1,0}]/@points
$\endgroup$
  • 1
    $\begingroup$ More directly, you can do RotationTransform[a, {0, 1, 0}] /@ points. $\endgroup$ – J. M.'s technical difficulties May 13 '16 at 9:14
  • $\begingroup$ @J.M. thank you I will edit post. :) $\endgroup$ – ubpdqn May 13 '16 at 9:15

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.