Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thomasp85/euclid
Exact Computation Geometry Framework Based on 'CGAL'
https://github.com/thomasp85/euclid
cgal computational-geometry geometry rstats
Last synced: 17 days ago
JSON representation
Exact Computation Geometry Framework Based on 'CGAL'
- Host: GitHub
- URL: https://github.com/thomasp85/euclid
- Owner: thomasp85
- License: other
- Created: 2020-09-17T07:16:38.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T08:54:42.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T17:28:30.008Z (about 1 month ago)
- Topics: cgal, computational-geometry, geometry, rstats
- Language: C++
- Homepage: https://r-euclid.com
- Size: 13.2 MB
- Stars: 83
- Watchers: 6
- Forks: 13
- Open Issues: 11
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
set.seed(2)
```[![R-CMD-check](https://github.com/thomasp85/euclid/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/thomasp85/euclid/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/thomasp85/euclid/branch/master/graph/badge.svg)](https://codecov.io/gh/thomasp85/euclid?branch=master)The purpose of euclid is to provide a new unified foundation for computational geometry in R. It provides new data types for common low level geometric concepts such as lines, planes, points, triangles, etc. as well as a core of functionality relates to these primitives. Specialised geometric algorithms are intended to extend this package so that e.g. Tessellation will live in it's own package but use the foundation laid out in euclid.
At its core euclid is an interface to the CGAL library for computational geometry. More specifically, it provides access to the functionality in the [2D and 3D Linear Geometry Kernel](https://doc.cgal.org/4.14.3/Kernel_23/index.html). The CGAL foundation means that computations with euclid are exact and free of the imprecision attached to working with floating point numbers. This is very important for geometry since floating point errors can compound and lead to failures in geometric predicates at the core of many geometric algorithms. To achieve this, data in euclid is never converted to R data structures but remain as pointers to CGAL structures unless specifically converted to numerics (in which case the floating point world kicks in)
## Installation
For now, euclid can be installed from github using remotes:
```{r, eval=FALSE}
# install.packages("remotes")
remotes::install_github("thomasp85/euclid")
```## Data types
The core of euclid is a set of new primitive vector types that model 2 and 3 dimensional geometric objects. The following types are present:
### 2 and 3 dimensions
- Circles
- Directions
- Lines
- Points
- Weighted Points
- Rays
- Segments
- Triangles
- Vectors
### 2 dimensions
- Iso rectangles
### 3 dimensions
- Iso cubes
- Planes
- Spheres
- Tetrahedrons
### Special vector types
In addition to the geometric data types, euclid also provides these primitive vector types:
- Exact numerics
- Bounding boxes
- Affine transformation matrices
## Example
The following example shows how to work with the different data types:
```{r, message=FALSE}
library(euclid)# Construct some exact numbers
random_num <- exact_numeric(rnorm(20))# Exact numbers behave much like R numerics (though not everything is possible)
random_num[1:5]
max(random_num)
random_num[2] * 10
random_num[5] + random_num[16]
sum(random_num)# With exact numbers we can construct our geometries
p <- point(random_num[1:10], random_num[11:20])
p# Create a line based on a vector, going through the origin
l <- line(point(0, 0), vec(3, 7))# Which points lies on the positive side of the line?
p %is_on_positive_side% l# Project points to line
p1 <- project(p, l)# Do the projected points lie on the line?
p1 %is_on% l# Construct a triangle from a random point to the extremes of the projected points
t <- triangle(point(rnorm(1), rnorm(1)), min(p1), max(p1))
t# Which points lies inside the triangle?
p %is_inside% t# Visualise result
plot(p, pch = 16)
euclid_plot(t)
euclid_plot(p[p %is_inside% t], cex = 3)# Area of t (cannot be given exact for all geometries so is returned as numerics)
approx_area(t)
```## Code of Conduct
Please note that the euclid project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.