0
\$\begingroup\$

inspired by this blog: http://alstatr.blogspot.co.uk/2014/02/r-animating-2d-and-3d-plots.html I made a 2D gif of a heart with:

library(animation)
saveGIF({
for(i in 1:150){
dat<- data.frame(t=seq(0, 2*pi, by=0.1) )
xhrt <- function(t) 16*sin(t)^3
 yhrt <- function(t) 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)
dat$y=yhrt(dat$t)
dat$x=xhrt(dat$t)
with(plot(x,y, type="l", xlim = c(-100  , i ^ 2 / 10 )) ) 
} 
}, interval = 0.1, ani.width = 550, ani.height = 550)

I wonder if anyone out there could show me how to do this in 3D!

\$\endgroup\$
  • 1
    \$\begingroup\$ pepsimax I added three tags that seem relevant to your question. Hope that's ok. \$\endgroup\$ – DavidC Feb 14 '14 at 2:10
  • 2
    \$\begingroup\$ @pepsimax You may want to add an objective winning criterion before this questions gets closed because its off-topic. \$\endgroup\$ – Howard Feb 14 '14 at 10:30
  • 2
    \$\begingroup\$ Btw, if you remove the R tag, so other languages can compete, you may find that more folks take part. \$\endgroup\$ – DavidC Feb 14 '14 at 13:12
6
\$\begingroup\$

Mathematica

This is done in Mathematica, but it may give you some ideas as to how to implement it in R.

hearts = Table[
  With[{v = RotationTransform[\[Theta], {0, 0, 1}][{3, 0, -.2}]},
   ContourPlot3D[(2 (4/3 x)^2 + 2 y^2 + z^2 - 1)^3 - (4/3 x)^2 z^3/
       10 - y^2 z^3, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, 
    MaxRecursion -> 6, Mesh -> None,
    BoxRatios -> {.3, 1, 1},
    SphericalRegion -> True,
    Contours -> {0}, Boxed -> False, PlotRange -> All, Axes -> False, 
    ViewPoint :> v, ContourStyle -> Red, 
    ImageSize -> 300]], {\[Theta], 0, 2 Pi, Pi/24}]

heart 3D

\$\endgroup\$

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