An open API service indexing awesome lists of open source software.

https://github.com/mdsumner/bluegum

Create various forms of globe meshes
https://github.com/mdsumner/bluegum

Last synced: 4 months ago
JSON representation

Create various forms of globe meshes

Awesome Lists containing this project

README

          

---
output: github_document
editor_options:
chunk_output_type: console
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
library(bluegum)
```

## bluegum

[![Travis build status](https://travis-ci.org/mdsumner/bluegum.svg?branch=master)](https://travis-ci.org/mdsumner/bluegum)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/mdsumner/bluegum?branch=master&svg=true)](https://ci.appveyor.com/project/mdsumner/bluegum)
[![Codecov test coverage](https://codecov.io/gh/mdsumner/bluegum/branch/master/graph/badge.svg)](https://codecov.io/gh/mdsumner/bluegum?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/bluegum)](https://CRAN.R-project.org/package=bluegum)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

The goal of bluegum is to get the simplest mesh creation for the R-global project and outline the space of tools that already exist.

Currently this stuff is scattered over a mess of my projects, gris, anglr, silicate, quadmesh, and it's time to outline the bare essentials and just how powerful rgl (and some key friends) already are.

WIP

### Scope

We will limit to visualizations that use a geocentric projection of the Earth's surface - i.e. a globe.

Luckily this does allow us to visit a lot of options.

#### convex hull in 3D is Delaunay surface

The `tri_graticule()` function can create an entire sphere or a portion of one and use the convex hull method or a Delaunay-triangulation algorithm directly.

In hull mode, this could be used for arbitrary locations on the sphere and works as well with a portion of the sphere but the hull will also wrap around the inside of the sliced sphere so it's a different result.

```{r del-hull, eval=FALSE}
library(bluegum)
hull <- tri_graticule(hull = TRUE)
library(rgl)
#clear3d();
#plot3d(hull, specular = "black")
#rglwidget()
```

Make it more detailed so that individual faces aren't so visible.

```{r del-hull-detail, eval=FALSE}
hull <- tri_graticule(n = 60 * c(1, 1/2), hull = TRUE)
library(rgl)
clear3d()
plot3d(hull, specular = grey(0.05))
rglwidget()

```

If we ask for a partial sphere when it's a hull, because the hull has to wrap around (well, you might want this but it's not faceted on those internal sides).

```{r partial, eval=FALSE}
hull <- tri_graticule(xlim = c(100, 150), hull = TRUE)
clear3d()
plot3d(hull, specular = "black")
rglwidget()
```

### random points in hull mode

This mode requires us to set the number of coordinates (not the number of faces in x/y) and allows
input of points on the surface, or they are created randomly.

```{r random, eval=FALSE}
library(rgl)
hull <- hull_graticule(n_coords = 24)
clear3d()
plot3d(hull, specular = "black")
rglwidget()
```

We can pass in a 2- or 3-column matrix of coordinates, with lon, lat, and elevation - 0
is used if elevation is not included.

```{r random-coords,eval=FALSE}

hull <- hull_graticule(coords = geosphere::randomCoordinates(120))
clear3d()
plot3d(hull, specular = "black")
rglwidget()

```

### direct creation of delaunay hull

If we only want a sector and not wrap we need to use a triangulation tool directly, without hull mode.

```{r sector, eval=FALSE}
hull <- tri_graticule(xlim = c(100, 150), hull = FALSE)
clear3d()
plot3d(hull, specular = "black")
rglwidget()
```

We probably can't tell the difference, hull or otherwise.

```{r delaunay, eval=FALSE}
library(bluegum)
hull <- tri_graticule(hull =FALSE)
library(rgl)
clear3d();
plot3d(hull, alpha = 0.5, specular = "black")
rglwidget()

```

### direct creation of quads on the sphere

The function `quad_graticule()` will produce a sphere or a portion of one using a quadmesh.
The hull mode is not relevant with quad.

```{r quad, eval=FALSE}
hull <- quad_graticule()
library(rgl)
clear3d();
plot3d(hull, alpha = 0.5, specular = "black")
rglwidget()

hull <- quad_graticule(ylim = c(-10, 30))
library(rgl)
clear3d();
plot3d(hull, alpha = 0.5, specular = "black")
rglwidget()

```

### 2. icosa

See Agafonkin for a parallel tool in JS: https://twitter.com/mourner/status/1176159651953594370

```R
library(icosa)
g <- icosa::trigrid(8)
library(rgl)
clear3d()
## note that we cannot index by name and use NA, hence match() here
lines3d(g@vertices[match(t(cbind(g@edges, NA) ), rownames(g@vertices)), ])
rglwidget()
```

### 3. quadmesh+reproj direct from a raster

### 4. terrain relief on mesh (trivial)

### 5. image textures - mesh3d format (two-step indexing to 0,1)

---

Please note that the 'bluegum' project is released with a
[Contributor Code of Conduct](CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.