-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME.Rmd
185 lines (132 loc) · 6.11 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
dpi=200,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# Rpolyhedra
[![Downloads](http://cranlogs.r-pkg.org/badges/Rpolyhedra?color=brightgreen)](https://www.r-pkg.org:443/pkg/Rpolyhedra)
[![Downloads](http://cranlogs.r-pkg.org/badges/grand-total/Rpolyhedra?color=brightgreen)](https://www.r-pkg.org:443/pkg/Rpolyhedra)
<!-- Polyhedra database scraped from publically available sources using R6 objects and 'rgl' visualizing capabilities. -->
This package is a polyhedra database based on the poly package found on https://netlib.org/polyhedra/ ([Original Help message](https://raw.githubusercontent.com/ropensci/Rpolyhedra/master/man/html/poly_original_help_message.html)), and the polyhedra definitions found on http://dmccooey.com/polyhedra/. As such, Rpolyhedra provides with the following:
1. A module to scrape the polyhedra for the different sources found with features for incremental correction of issues found and to be found in scraping process.
1. A database of the scraped polyhedra.
1. An R6 polyhedron representation with 'rgl' package visualizing capabilities.
| Release | Usage | Development |
|:--------|:------|:------------|
| [![](https://badges.ropensci.org/157_status.svg)](https://github.com/ropensci/software-review/issues/157)| [![minimal R version](https://img.shields.io/badge/R%3E%3D-3.4.0-blue.svg)](https://cran.r-project.org/) |
[![R-CMD-check](https://github.com/ropensci/Rpolyhedra/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/Rpolyhedra/actions) |
| [![CRAN](https://www.r-pkg.org:443/pkg/Rpolyhedra)](https://cran.r-project.org/package=Rpolyhedra) | | [![codecov](https://codecov.io/gh/ropensci/Rpolyhedra/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/Rpolyhedra) |
|||[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)|
# Preview
Through [Rpolyhedraexplorer](https://qbotics.shinyapps.io/rpolyhedra-explorer/) you can navigate the polyhedra database without actually installing R environment.
# How to get started
```R
install.packages("Rpolyhedra")
```
# How to get started (Development version)
Install the R package using the following commands on the R console:
```R
devtools::install_github("ropensci/Rpolyhedra", build_opts = NULL)
```
# Loading the database
```{r, rpolyhedra}
library(Rpolyhedra)
```
```R
# if want to switch to fullDB in user filespace, it will ask you for downloading the full database to your home directory
switchToFullDatabase()
```
# A simple example of 5 regular polyhedra
To get started execute the following commands:
```{r, libraries}
# 0. Load libraries
library(knitr)
library(rgl)
# For foarding webgl output to knitr
knit_hooks$set(webgl = hook_webgl)
library(dplyr)
```
```{r, 1-retrieve}
# 1. Obtain 5 regular solids
polyhedra.2.draw <- getAvailablePolyhedra(source = "netlib")
polyhedra.2.draw <- polyhedra.2.draw %>%
filter(scraped.name %in%
c("tetrahedron", "octahedron", "cube",
"icosahedron", "dodecahedron"))
# 2. Setup colors and scales
n <- nrow(polyhedra.2.draw)
polyhedron.colors <- rainbow(n)
polyhedron.scale <- 5
```
```{r, render}
# For interactive RGL window
#```{r, render, webgl=TRUE}
# 3. open and setup RGL window
open3d()
par3d(FOV = 1)
rgl.bg( sphere =FALSE, fogtype = "none", color=c("black"))
rgl.viewpoint(theta = 0, phi=0, zoom=0.8, fov=1)
# 4. for each polyhedron, setup rotation, position and render
for (i in seq_len(n)) {
# Obtain polyhedron
polyhedron.row <- polyhedra.2.draw[i,]
polyhedron.name <- polyhedron.row$scraped.name
polyhedron <- getPolyhedron(source = polyhedron.row$source, polyhedron.name)
# Setup angles, position into transformationMatrix
current.angle <- i/n * 2 * pi
tm <- rotationMatrix(current.angle, 1, 0, 0)
x.pos <- round(polyhedron.scale * sin(current.angle), 2)
y.pos <- round(polyhedron.scale * cos(current.angle), 2)
tm <- tm %*% translationMatrix(x.pos, y.pos, 0)
# Render
print(paste("Drawing ", polyhedron.name, " rotated ", round(current.angle, 2),
" in (1,0,0) axis. Translated to (", x.pos, ",", y.pos, ",0)",
" with color ", polyhedron.colors[i], sep = ""))
shape.rgl <- polyhedron$getRGLModel(transformation.matrix = tm)
shade3d(shape.rgl, color = polyhedron.colors[i])
}
#rgl::rglwidget()
#rgl::rgl.snapshot("man/figures/README-5-polyhedra.png")
```
![5-polyhedra](man/figures/README-5-polyhedra.png)
## sources
### netlib
Includes 142 polyhedra definitions.
The PHD format was created to describe the geometric polyhedron definitions derived mathematically by Andrew Hume and by the Kaleido program of Zvi Har'El.
PHD files were generated using [poly2](https://netlib.org/poly2/readme) library (no longer maintained). Although the code is available, specific programming skills are required to run it.
PHD files can be found in `extdata/netlib.org/polyhedra/index.html`
### dmccooey
Includes 767 polyhedra definitions.
The [polyhedra database](http://dmccooey.com/polyhedra/) built by David Mccooey has an open format which has been scraped to feed Rpolyhedra database
dmccooey files can be found in `extdata/dmccooey.com/polyhedra/`
# Troubleshooting
## devtools
### Ubuntu
```bash
apt-get install libcurl4-openssl-dev
```
### Windows
run end user CRAN version
### macOS brew
```bash
brew install openssl
```
After, in R:
```R
install.packages("devtools")
```
## rgl
### Ubuntu
```bash
sudo apt-get install r-cran-rgl
```
Please note that the 'Rpolyhedra' project is released with a [Contributor Code of Conduct](https://github.com/ropensci/Rpolyhedra/blob/master/CODE_OF_CONDUCT.md). By [contributing](https://github.com/ropensci/Rpolyhedra/blob/master/CONTRIBUTING.md) to this project, you agree to abide by its terms.
[![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org)