SOCR ≫ TCIU Website ≫ TCIU GitHub ≫

1 Two cones reresenting space (\(R^3\)) - kime (\(R^2\))

Complex-time (kime) can be defined using polar coordinates.

# parameter space sweep for the spherical cordinates
phi <- seq(from = 0, to = 2*pi, by = ((2*pi - 0)/(200 - 1)))
psi <- seq(from = 0, to = pi, by = ((pi - 0)/(200 - 1)))

# shape=="cone1")
    # rendering (u,v) parametric surfaces requires x,y,z arguments to be 2D arrays
    # In out case, the three coordinates have to be 200*200 parameterized tensors/arrays
    h1= 10   # cone height
    r1 = seq(from = 0, to = h1, by = ((h1 - 0)/(200 - 1)))  # r = radius
    x1 = 20* ((h1 - r1)/h1 ) %o% rep(1, 200)             # x = 3*r
    y1 = 3* ((h1 - r1)/h1 ) %o% sin(phi)   # y = r*sin(phi)
    z1 = 3* ((h1 - r1)/h1 ) %o% cos(phi)   # z = r*cos(phi)

    # circle1 bundary
    x11 = rep(20, 200) %o% rep(1, 200)             # x = 20
    y11 = 3* ((h1 - r1)/h1 ) %o% sin(phi)   # y = r*sin(phi)
    z11 = 3* ((h1 - r1)/h1 ) %o% cos(phi)   # z = r*cos(phi)

# shape=="cone2")
    h2= 10   # cone height
    r2 = seq(from = 0, to = h2, by = ((h2 - 0)/(200 - 1)))  # r = radius
    x2 = 20* ((h2 - r2)/h2 ) %o% rep(1, 200)             # x = 3*r
    y2 = 2* ((h2 - r2)/h2 ) %o% sin(phi)   # y = r*sin(phi)
    z2 = 2* ((h2 - r2)/h2 ) %o% cos(phi)   # z = r*cos(phi)

    # circle2 bundary
    x21 = rep(20, 200) %o% rep(1, 200)             # x = 20
    y21 = 2* ((h2 - r2)/h2 ) %o% sin(phi)   # y = r*sin(phi)
    z21 = 2* ((h2 - r2)/h2 ) %o% cos(phi)   # z = r*cos(phi)
    
# shape=="cone3")
    h3= 10   # cone height
    r3 = seq(from = 0, to = h3, by = ((h3 - 0)/(200 - 1)))  # r = radius
    x3 = 15* ((h3 - r3)/h3 ) %o% rep(1, 200)             # x = 3*r
    y3 = 3* ((h3 - r3)/h3 ) %o% sin(phi)   # y = r*sin(phi)
    z3 = 3* ((h3 - r3)/h3 ) %o% cos(phi)   # z = r*cos(phi)

    # circle3 bundary
    x31 = rep(15, 200) %o% rep(1, 200)             # x = 15
    y31 = 3* ((h3 - r3)/h3) %o% sin(phi)   # y = r*sin(phi)
    z31 = 3* ((h3 - r3)/h3) %o% cos(phi)   # z = r*cos(phi)

shape_names <- c("cone1", "cone2", "cone3")

# https://plot.ly/r/custom-buttons/

# updatemenus component
updatemenus <- list(
  list(
    active = -1,
    type = 'buttons',
    buttons = list(
      list(
        label = shape_names[1],
        method = "update",
        args = list(list(visible = c(TRUE, FALSE, FALSE)),
                    list(title = shape_names[1]))),
      list(
        label = shape_names[2],
        method = "update",
        args = list(list(visible = c(FALSE, TRUE, FALSE)),
                    list(title = shape_names[2]))),
      list(
        label = shape_names[3],
        method = "update",
        args = list(list(visible = c(FALSE, FALSE, TRUE)),
                    list(title = shape_names[3])))
    )
  )
)

p <- 
  plot_ly(hoverinfo="none", legendshow=FALSE, showscale = FALSE) %>%
  # add cone1
  add_trace(x = ~x1, y = ~y1, z = ~z1, type = 'surface', opacity=0.3, visible=T,
             contour=list(show=F, color="#000", width=15, lwd=10,
                          opacity=0.5, hoverinfo="none", legendshow=F)) %>%
  # add cone2
  add_trace(x = ~x2, y = ~y2, z = ~z2, type='surface', opacity=0.4,visible=T,
             contour=list(show=F, color="#000", width=15, lwd=10,
                          opacity=0.5, hoverinfo="none", legendshow=F)) %>%
  # add cone3
  add_trace(x = ~x3, y = ~y3, z = ~z3, type='surface', opacity=0.5,visible=T,
             contour=list(show=F, color="#000", width=15, lwd=10,
                          opacity=0.5, hoverinfo="none", legendshow=F)) %>%
  #
  #
  # trace the x-axis
  add_trace(x=~1.1*x1[,1], y=0, z=0, type="scatter3d", mode="lines", 
              line = list(width = 10, color="light blue"), name="Z",
              hoverinfo="none", legendshow=F) %>%
  #
  #
  # trace the boundary of cone1 surface
  add_trace(x=~x1[1,], y=~y11[1,], z=~z11[1,], type="scatter3d", mode="lines", 
              line = list(width = 10, color="red"), name="Surface Boundary",
              hoverinfo="none", legendshow=F) %>%
  # add center for cime circle1 at location x1
  add_trace(x=~x1[1,1], y=0, z=0, type="scatter3d", mode="markers", 
              line = list(width = 10, color="navy blue"), name="Z",
              hoverinfo="none", legendshow=F) %>%
  # trace the boundary of cone2 surface
  add_trace(x=~x2[1,], y=~y21[1,], z=~z21[1,], type="scatter3d", mode="lines", 
              line = list(width = 10, color="green"), name="Surface Boundary",
              hoverinfo="none", legendshow=F) %>%
  # trace the boundary of cone3 surface
  add_trace(x=~x3[1,], y=~y31[1,], z=~z31[1,], type="scatter3d", mode="lines", 
              line = list(width = 10, color="blue"), name="Surface Boundary",
              hoverinfo="none", legendshow=F) %>%
  # add center for cime circle3 at location x3
  add_trace(x=~x3[1,1], y=0, z=0, type="scatter3d", mode="markers", 
              line = list(width = 10, color="navy blue"), name="Z",
              hoverinfo="none", legendshow=F) %>%
  layout(title = "Choose a Cime Cone", showlegend = FALSE,
         updatemenus = updatemenus)
p