Plot gif of 3 dimensional heart in R

0

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!

cianius

Posted 2014-02-14T00:42:03.083

Reputation: 103

Question was closed 2014-02-14T14:06:59.157

1pepsimax I added three tags that seem relevant to your question. Hope that's ok. – DavidC – 2014-02-14T02:10:17.110

2@pepsimax You may want to add an objective winning criterion before this questions gets closed because its off-topic. – Howard – 2014-02-14T10:30:13.393

2Btw, if you remove the R tag, so other languages can compete, you may find that more folks take part. – DavidC – 2014-02-14T13:12:33.410

Answers

6

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

DavidC

Posted 2014-02-14T00:42:03.083

Reputation: 24 524