---
title: "Non-Euclidean Kime Manifold"
subtitle: "[Back To TCIU Contents](http://tciu.predictive.space/)"
author: "SOCR Team "
date: "`r format(Sys.time(),'%m/%d/%Y')`"
output: 
  html_document:
    theme: spacelab
    highlight: tango
    includes:
      before_body: TCIU_header.html
    toc: true
    number_sections: true
    toc_depth: 2
    toc_float:
      collapsed: false
      smooth_scroll: true
    code_folding: hide
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Non-Euclidean Kime Manifold

So far, we considered spacekime as 5D Euclidean space where the 2D kime is a flat space. Does it make sense to generalize kime to non-Euclidean manifold and what is the rationale and meaning of a curved kime manifold?

We saw earlier the geometric representation of the flat spacekime using conical shapes. Let's start with some visualization of the non-Euclidean 2D kime manifold representing the axial (transverse) planes, and the spatial dimensions are compressed into the 1D vertical axis.

```{r message=FALSE, warning=FALSE, error=F}
library(plotly)
library(ggplot2)

# Define a vase-generating function (2D), which will be rotated to form curved kime manifold
kime.manifold <- data.frame( s=seq(0, 1.3, length.out = 200) )
kime.manifold$theta <- seq(0, 2*pi, length.out = 200)
g <- function (t) { sqrt(t^3-2.09*t^2+1.097*t) }
h <- function (t) { t }

# rendering (u==s, v==theta) 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
x2 <- g(kime.manifold$s) %o% cos(kime.manifold$theta)
y2 <- g(kime.manifold$s) %o% sin(kime.manifold$theta)
z2 <- h(kime.manifold$s) %o% rep(1, 200)
#2D plot data
xx2 <- g(kime.manifold$s) %o% cos(kime.manifold$theta)
yy2 <- rep(0,200*200)
zz2 <- h(kime.manifold$s) %o% rep(1, 200)

# calculate the diameter of every circle
xxx2<-as.vector(xx2)
zzz2<-as.vector(zz2)
newdata<-data.frame(zzz2,xxx2)
zzzz2<-as.matrix(zzz2)

#calculate every diameter
a=vector()
for(i in 1:200){
  t=max(newdata[which(zzz2==zzzz2[i,]),2])
  a=c(a,t)
}
#text the diameter and height of every circle

# phases
phi <- matrix(NA, nrow=200, ncol=200)
for (i in 1:200) {
  for (j in 1:200) phi[i,j] <- kime.manifold$theta[j]
}

mytext <- cbind(radius=a, height=zzz2[1:200], phi=phi[ ,1:200]); # tail(mytext)
custom_txt <- matrix(NA, nrow=200, ncol=200)
for (i in 1:200) {
   for (j in 1:200) {
     custom_txt[i,j] <- paste(' x: ', round(mytext[i, 2], 3),
                    '\n r: ', round(mytext[i, 1], 3),
                    '\n phi: ', round(kime.manifold$theta[j], 3)) 
   }
}

# Define kime-curve parameter
xCurve <- g(kime.manifold$s) * cos(kime.manifold$theta) 
yCurve <- g(kime.manifold$s) * sin(kime.manifold$theta)
zCurve <- h(kime.manifold$s) 

kimeCurve <- data.frame(xCurve, yCurve, zCurve)

#plot 2D into 3D and make the text of the diameter (time), height (r), and phase (phi)
f <- list(family = "Courier New, monospace", size = 18, color = "black")
x <- list(title = "k1", titlefont = f)
y <- list(title = "k2", titlefont = f)
z <- list(title = "space (x)", titlefont = f)

plot_ly(kimeCurve, x = ~xCurve, y = ~yCurve, z = ~zCurve, type = 'scatter3d', 
             mode = 'lines', showlegend = F, # name="Kime-space curve projection on Kime-surface",
             line = list(width = 22), name="SK curve") %>%
  add_trace(x = ~xx2, y = ~yy2, z = ~zz2, type = "surface", name="Spacekime leaf",
        text = custom_txt, hoverinfo = "text", showlegend = FALSE) %>% 
  add_trace(x=~x2, y=~y2, z=~z2, name="SK manifold",
                  colors = c("blue", "yellow"),type="surface", 
                  opacity=0.5, showscale = FALSE, showlegend = FALSE) %>%
        # trace the main Z-axis
  add_trace(x=0, y=0, z=~zz2[, 1], type="scatter3d", mode="lines", 
                  line = list(width = 10, color="navy blue"), name="Space(x)", 
                  hoverinfo="none", showlegend = FALSE) %>%
  layout(dragmode = "turntable", title = "Non-Euclidean Kime Manifold (1D space, 2D kime)",
               scene = list(xaxis = x, yaxis = y, zaxis = z), showlegend = FALSE)
```

<!--html_preserve-->
<div>
    	<footer><center>
			<a href="http://www.socr.umich.edu/">SOCR Resource</a>
				Visitor number <img class="statcounter" src="https://c.statcounter.com/5714596/0/038e9ac4/0/" alt="Web Analytics" align="middle" border="0">
				<script type="text/javascript">
					var d = new Date();
					document.write(" | " + d.getFullYear() + " | ");
				</script> 
				<a href="http://socr.umich.edu/img/SOCR_Email.png"><img alt="SOCR Email"
	 			title="SOCR Email" src="http://socr.umich.edu/img/SOCR_Email.png"
	 			style="border: 0px solid ;"></a>
	 		 </center>
	 	</footer>

	<!-- Start of StatCounter Code -->
		<script type="text/javascript">
			var sc_project=5714596; 
			var sc_invisible=1; 
			var sc_partition=71; 
			var sc_click_stat=1; 
			var sc_security="038e9ac4"; 
		</script>
		
		<script type="text/javascript" src="https://www.statcounter.com/counter/counter.js"></script>
	<!-- End of StatCounter Code -->
	
	<!-- GoogleAnalytics -->
		<script src="https://www.google-analytics.com/urchin.js" type="text/javascript"> </script>
		<script type="text/javascript"> _uacct = "UA-676559-1"; urchinTracker(); </script>
	<!-- End of GoogleAnalytics Code -->
</div>
<!--/html_preserve-->