5
$\begingroup$

I have a numerical solution from a differential equation that is in the form of a list, in $(x,z)$-plane. I would like to rotate the 2D ListPlot around the $z$-axis to generate a 3D plot. The length of the list is $25\,000$; the step size between each point is $0.0003$.

I have tried rotate each point $36$ degrees for $9$ times to obtain a list of triples and then use ListPlot3D. This method, however, takes about $5$ minutes to generate a plot. Is there a more efficient way of rotating a 2D ListPlot?

I was thinking about cutting off the number of points being rotated. How many points can I omit to retain most of the features of the original plot?

$\endgroup$
  • $\begingroup$ You could use Interpolation to create an interpolating function and plot it using RevolutionPlot3D. Is this what you're looking for? $\endgroup$ – Szabolcs Dec 8 '13 at 2:13
  • $\begingroup$ If you take a list of 3D points and take the dot product with a rotation matrix, it should be fast, even for 25000 points, provided that the points are all machine precision numbers (apply N to the list to make them machine precision). $\endgroup$ – Szabolcs Dec 8 '13 at 2:16
  • 1
    $\begingroup$ 25000 is overkill: it is ~20 times more then pixels in your screen. Often ~1000 points is enough. $\endgroup$ – ybeltukov Dec 8 '13 at 2:18
  • $\begingroup$ Thanks a lot! I will try both methods. $\endgroup$ – SlipStream Dec 8 '13 at 2:21
5
$\begingroup$

You can use Interpolation to interpolate the data, then plot it using RevolutionPlot3D. The plotting command won't actually sample the interpolation function at 25000 different points (which as @ybeltukov said, is overkill), so plotting will be much faster.

Example:

Make sample data:

data = Table[{x, Sin[x]}, {x, 0., 2 Pi, 2 Pi/25000.}];

Interpolate:

if = Interpolation[data]

Plot:

RevolutionPlot3D[{if[x], x}, {x, 0, 2 Pi}]

enter image description here

Rotating the list of points by multiplying with a rotation matrix is not slow on my machine (it's much faster than plotting all $9\times 25000$ points):

rm = RotationMatrix[36. Degree, {1, 0, 0}]

ListPointPlot3D[Join @@ NestList[#.rm &, ArrayFlatten[{{data, 0}}], 9], BoxRatios -> Automatic]

enter image description here

When you do this, make sure that both the data and the rotation matrix are machine precision numbers (apply N to them to make sure this is the case).

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks a lot! The interpolation method works great. $\endgroup$ – SlipStream Dec 8 '13 at 2:37
  • $\begingroup$ @MichaelE2 I would definitely upvote this answer when I have enough reputation. $\endgroup$ – SlipStream Dec 8 '13 at 3:54
  • $\begingroup$ @SlipStream Ah, I didn't know about the rep. restriction. Sorry to trouble you. $\endgroup$ – Michael E2 Dec 8 '13 at 3:59

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.