# R/egg.tri.R In eggs: Distances and areas on the surface of an egg

```egg.tri = function(egg, N) {

# Returns the triangulated model of a sphere using the
# icosaedron subdivision method.
#
# N indicates the number of subdivisions,

# require("Matrix", quietly=TRUE)
#
# a = egg\$a
# b = egg\$b
# c = egg\$c
# h = egg\$length
#
# # Get the twelve vertices of icosahedron on unit sphere
# t0 = (1 + sqrt(5))/2
# tau = t0/sqrt(1 + t0^2)
# one = 1/sqrt(1 + t0^2)
# p = rbind(
#   c( tau,  one,  0),
#   c(-tau,  one,  0),
#   c(-tau, -one,  0),
#   c( tau, -one,  0),
#   c( one,  0,    tau),
#   c( one,  0,   -tau),
#   c(-one,  0,   -tau),
#   c(-one,  0,    tau),
#   c( 0,    tau,  one),
#   c( 0,   -tau,  one),
#   c( 0,   -tau, -one),
#   c( 0,    tau, -one)
# )
# t = rbind(
#   c(5,  8,  9),
#   c(5, 10,  8),
#   c(6, 12,  7),
#   c(6,  7, 11),
#   c(1,  4,  5),
#   c(1,  6,  4),
#   c(3,  2,  8),
#   c(3,  7,  2),
#   c(9, 12,  1),
#   c(9,  2, 12),
#   c(10,  4, 11),
#   c(10, 11,  3),
#   c(9,  1,  5),
#   c(12,  6,  1),
#   c(5,  4, 10),
#   c(6, 11,  4),
#   c(8,  2,  9),
#   c(7, 12,  2),
#   c(8, 10,  3),
#   c(7,  3, 11)
# )
#
# if(N > 0) {
#
#   nt = nrow(t)
#   np = nrow(p)
#   totp = np
#   for(ii in 1:N) {
#     totp = 4*totp - 6
#   }
#   p = rbind(p, matrix(0, nrow=totp-12, ncol=3))
#
#   # Refine the icosahedron N times
#   for(i in 1:N) {
#
#     told = t
#     t = matrix(0, nrow=nt*4, ncol=3)
#     peMap = Matrix(0, nrow=np, ncol=np, sparse=TRUE)
#     ct = 1
#
#     # Loop trough all old triangles
#     for(j in 1:nt) {
#
#       p1 = told[j,1]; p2 = told[j,2]; p3 = told[j,3]
#       x1 = p[p1,1]; x2 = p[p2,1]; x3 = p[p3,1]
#       y1 = p[p1,2]; y2 = p[p2,2]; y3 = p[p3,2]
#       z1 = p[p1,3]; z2 = p[p2,3]; z3 = p[p3,3]
#
#       # First edge
#       # Preserve triangle orientation
#       if(p1 < p2) {
#         p1m = p1
#         p2m = p2
#       } else {
#         p2m = p1
#         p1m = p2
#       }
#       # If the point does not exist yet, calculate the new point
#       p4 = peMap[p1m,p2m]
#       if(p4 == 0) {
#         np = np + 1
#         p4 = np
#         peMap[p1m,p2m] = np
#         p[np,1] = (x1 + x2)/2
#         p[np,2] = (y1 + y2)/2
#         p[np,3] = (z1 + z2)/2
#       }
#
#       # Second edge
#       if(p2 < p3) {
#         p2m = p2
#         p3m = p3
#       } else {
#         p2m = p3
#         p3m = p2
#       }
#       p5 = peMap[p2m,p3m]
#       if(p5 == 0) {
#         np = np + 1
#         p5 = np
#         peMap[p2m,p3m] = np
#         p[np,1] = (x2 + x3)/2
#         p[np,2] = (y2 + y3)/2
#         p[np,3] = (z2 + z3)/2
#       }
#
#       # Third edge
#       if(p1 < p3) {
#         p1m = p1
#         p3m = p3
#       } else {
#         p3m = p1
#         p1m = p3
#       }
#       p6 = peMap[p1m,p3m]
#       if(p6 == 0) {
#         np = np + 1
#         p6 = np
#         peMap[p1m,p3m] = np
#         p[np,1] = (x1 + x3)/2
#         p[np,2] = (y1 + y3)/2
#         p[np,3] = (z1 + z3)/2
#       }
#
#       # Allocate new triangles
#       t[ct,1] = p1; t[ct,2] = p4; t[ct,3] = p6; ct = ct + 1
#       t[ct,1] = p4; t[ct,2] = p5; t[ct,3] = p6; ct = ct + 1
#       t[ct,1] = p4; t[ct,2] = p2; t[ct,3] = p5; ct = ct + 1
#       t[ct,1] = p6; t[ct,2] = p5; t[ct,3] = p3; ct = ct + 1
#
#     }
#
#     # Update the number of triangles
#     nt = ct - 1
#   }
#
# }
#
# # Normalize all points
# for(i in 1:nrow(p)) {
#   p[i,] = norm(p[i,])
#   z.hat = normalise(p[i,3], -1, 1, 0, 1)
#   p[i,1:2] = norm(p[i,1:2])*get.d(z.hat, a, b, c)
#   p[i,3] = normalise(z.hat, 0, 1, -(h/2), (h/2))
# }
# p[is.nan(p)] = 0
#
# out = list(t=t, p=p)
# class(out) = "egg.mesh"
# return (out)
stop("This function will be made available in a future release.")
}
```

## Try the eggs package in your browser

Any scripts or data that you put into this service are public.

eggs documentation built on May 2, 2019, 5:23 p.m.