{"id":25059913,"url":"https://github.com/stla/rcdt","last_synced_at":"2025-04-14T14:24:36.615Z","repository":{"id":56933933,"uuid":"466410258","full_name":"stla/RCDT","owner":"stla","description":"R package for 2D constrained Delaunay triangulation","archived":false,"fork":false,"pushed_at":"2023-10-31T12:47:42.000Z","size":476,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T02:27:44.336Z","etag":null,"topics":["constrained-delaunay-triangulation","cpp","delaunay-triangulation","r"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stla.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.note","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-05T09:40:29.000Z","updated_at":"2024-12-25T21:55:52.000Z","dependencies_parsed_at":"2025-02-06T15:55:52.214Z","dependency_job_id":"544e9a78-75fa-4d16-b2aa-d887dbd44e45","html_url":"https://github.com/stla/RCDT","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FRCDT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FRCDT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FRCDT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FRCDT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stla","download_url":"https://codeload.github.com/stla/RCDT/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248895516,"owners_count":21179250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["constrained-delaunay-triangulation","cpp","delaunay-triangulation","r"],"created_at":"2025-02-06T15:55:46.419Z","updated_at":"2025-04-14T14:24:36.588Z","avatar_url":"https://github.com/stla.png","language":"C++","readme":"---\r\ntitle: The 'RCDT' package - constrained 2D Delaunay triangulation\r\noutput: github_document\r\neditor_options: \r\n  chunk_output_type: console\r\n---\r\n\r\n\u003c!-- badges: start --\u003e\r\n[![R-CMD-check](https://github.com/stla/RCDT/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/stla/RCDT/actions/workflows/R-CMD-check.yaml)\r\n\u003c!-- badges: end --\u003e\r\n\r\n![](https://raw.githubusercontent.com/stla/RCDT/main/inst/images/CDT.png)\r\n\r\n```{r setup, include=FALSE}\r\nknitr::opts_chunk$set(echo = TRUE, collapse = TRUE)\r\n```\r\n\r\n## The pentagram\r\n\r\n```{r}\r\n# vertices\r\nR \u003c- sqrt((5-sqrt(5))/10)     # outer circumradius\r\nr \u003c- sqrt((25-11*sqrt(5))/10) # circumradius of the inner pentagon\r\nX \u003c- R * vapply(0L:4L, function(i) cos(pi/180 * (90+72*i)), numeric(1L))\r\nY \u003c- R * vapply(0L:4L, function(i) sin(pi/180 * (90+72*i)), numeric(1L))\r\nx \u003c- r * vapply(0L:4L, function(i) cos(pi/180 * (126+72*i)), numeric(1L))\r\ny \u003c- r * vapply(0L:4L, function(i) sin(pi/180 * (126+72*i)), numeric(1L))\r\nvertices \u003c- rbind(\r\n  c(X[1L], Y[1L]),\r\n  c(x[1L], y[1L]),\r\n  c(X[2L], Y[2L]),\r\n  c(x[2L], y[2L]),\r\n  c(X[3L], Y[3L]),\r\n  c(x[3L], y[3L]),\r\n  c(X[4L], Y[4L]),\r\n  c(x[4L], y[4L]),\r\n  c(X[5L], Y[5L]),\r\n  c(x[5L], y[5L])\r\n)\r\n```\r\n\r\n```{r}\r\n# edge indices (pairs)\r\nedges \u003c- cbind(1L:10L, c(2L:10L, 1L))\r\n```\r\n\r\n```{r}\r\n# constrained Delaunay triangulation\r\nlibrary(RCDT)\r\ndel \u003c- delaunay(vertices, edges)\r\n```\r\n\r\n```{r, eval=FALSE}\r\n# plot\r\nopar \u003c- par(mar = c(0, 0, 0, 0))\r\nplotDelaunay(\r\n  del, type = \"n\", asp = 1, fillcolor = \"distinct\", lwd_borders = 3,\r\n  xlab = NA, ylab = NA, axes = FALSE\r\n)\r\npar(opar)\r\n```\r\n\r\n![](https://raw.githubusercontent.com/stla/RCDT/main/inst/images/pentagram.png)\r\n\r\n```{r}\r\n# area\r\ndelaunayArea(del)\r\nsqrt(650 - 290*sqrt(5)) / 4 # exact value\r\n```\r\n\r\n\r\n## An eight-pointed star\r\n\r\nI found its vertices with the Julia library \r\n[Luxor](http://juliagraphics.github.io/Luxor.jl/v0.10.3/index.html).\r\n\r\n```{r}\r\nvertices \u003c- rbind(\r\n  c(2.121320343559643, 2.1213203435596424),\r\n  c(0.5740251485476348, 1.38581929876693),\r\n  c(0.0, 3.0),\r\n  c(-0.5740251485476346, 1.38581929876693),\r\n  c(-2.1213203435596424, 2.121320343559643),\r\n  c(-1.38581929876693, 0.5740251485476349),\r\n  c(-3.0, 0.0),\r\n  c(-1.3858192987669302, -0.5740251485476345),\r\n  c(-2.121320343559643, -2.1213203435596424),\r\n  c(-0.5740251485476355, -1.3858192987669298),\r\n  c(0.0, -3.0),\r\n  c(0.574025148547635, -1.38581929876693),\r\n  c(2.121320343559642, -2.121320343559643),\r\n  c(1.3858192987669298, -0.5740251485476355),\r\n  c(3.0, 0.0),\r\n  c(1.38581929876693, 0.5740251485476349)\r\n)\r\n```\r\n\r\n```{r}\r\n# edge indices\r\nedges \u003c- cbind(1L:16L, c(2L:16L, 1L))\r\n```\r\n\r\n```{r}\r\nlibrary(RCDT)\r\ndel \u003c- delaunay(vertices, edges)\r\n```\r\n\r\n```{r, eval=FALSE}\r\nopar \u003c- par(mar = c(0, 0, 0, 0))\r\nplotDelaunay(\r\n  del, type = \"n\", asp = 1, fillcolor = \"distinct\", \r\n  col_borders = \"navy\", lty_edges = 2, lwd_borders = 3, lwd_edges = 2, \r\n  xlab = NA, ylab = NA, axes = FALSE\r\n)\r\npar(opar)\r\n```\r\n\r\n![](https://raw.githubusercontent.com/stla/RCDT/main/inst/images/eight-pointed_star.png)\r\n\r\n\r\n## Triangulation of a polygon with a hole\r\n\r\n```{r polygon_hole}\r\nn \u003c- 100L # outer number of sides\r\nangles1 \u003c- seq(0, 2*pi, length.out = n + 1L)[-1L]\r\nouter_points \u003c- cbind(cos(angles1), sin(angles1))\r\nm \u003c- 10L  # inner number of sides\r\nangles2 \u003c- seq(0, 2*pi, length.out = m + 1L)[-1L]\r\ninner_points \u003c- 0.5 * cbind(cos(angles2), sin(angles2))\r\npoints \u003c- rbind(outer_points, inner_points)\r\n# constraint edges\r\nindices \u003c- 1L:n\r\nedges_outer \u003c- cbind(\r\n  indices, c(indices[-1L], indices[1L])\r\n)\r\nindices \u003c- n + 1L:m\r\nedges_inner \u003c- cbind(\r\n  indices, c(indices[-1L], indices[1L])\r\n)\r\nedges \u003c- rbind(edges_outer, edges_inner)\r\n# constrained Delaunay triangulation\r\ndel \u003c- delaunay(points, edges) \r\n```\r\n\r\n```{r plot_polygon_with_hole, eval=FALSE}\r\n# plot\r\nopar \u003c- par(mar = c(0, 0, 0, 0))\r\nplotDelaunay(\r\n  del, type = \"n\", asp = 1, lwd_borders = 3, col_borders = \"black\", \r\n  fillcolor = \"random\", col_edges = \"yellow\",\r\n  axes = FALSE, xlab = NA, ylab = NA\r\n)\r\npar(opar)\r\n```\r\n\r\n![](https://raw.githubusercontent.com/stla/RCDT/main/inst/images/polygonWithHole.png)\r\n\r\nOne can also enter a vector of colors in the `fillcolor` argument. First, \r\nsee the number of triangles:\r\n\r\n```{r number_triangles}\r\ndel[[\"mesh\"]]\r\n```\r\n\r\nThere are 110 triangles. Let's make a cyclic vector of 110 colors:\r\n\r\n```{r palette}\r\ncolors \u003c- viridisLite::viridis(55)\r\ncolors \u003c- c(colors, rev(colors))\r\n```\r\n\r\nAnd let's plot now:\r\n\r\n```{r plot_viridis, eval=FALSE}\r\nopar \u003c- par(mar = c(0, 0, 0, 0))\r\nplotDelaunay(\r\n  del, type = \"n\", asp = 1, lwd_borders = 3, col_borders = \"black\", \r\n  fillcolor = colors, col_edges = \"black\", lwd_edges = 1.5,\r\n  axes = FALSE, xlab = NA, ylab = NA\r\n)\r\npar(opar)\r\n```\r\n\r\n![](https://raw.githubusercontent.com/stla/RCDT/main/inst/images/polygonWithHoleViridis.png)\r\n\r\nThe colors are assigned to the triangles in the order they are given, but only \r\nafter the triangles have been circularly ordered.\r\n\r\n\r\n## A funny curve\r\n\r\nI found this curve [here](https://health.ahs.upei.ca/KubiosHRV/MCR/toolbox/matlab/demos/html/demoDelaunayTri.html#19).\r\n\r\n```{r suncurve}\r\nt_ \u003c- seq(-pi, pi, length.out = 193L)[-1L]\r\nr_ \u003c- 0.1 + 5*sqrt(cos(6*t_)^2 + 0.7^2)\r\nxy \u003c- cbind(r_*cos(t_), r_*sin(t_))\r\nedges1 \u003c- cbind(1L:192L, c(2L:192L, 1L))\r\ninner \u003c- which(r_ == min(r_))\r\nedges2 \u003c- cbind(inner, c(tail(inner, -1L), inner[1L]))\r\ndel \u003c- delaunay(xy, edges = rbind(edges1, edges2))\r\n```\r\n\r\n```{r plot_suncurve, eval=FALSE}\r\nopar \u003c- par(mar = c(0, 0, 0, 0))\r\nplotDelaunay(\r\n  del, type = \"n\", col_borders = \"black\", lwd_borders = 2, \r\n  fillcolor = \"random\", col_edges = \"white\", \r\n  axes = FALSE, xlab = NA, ylab = NA, asp = 1\r\n)\r\npolygon(xy[inner, ], col = \"#ffff99\")\r\npar(opar)\r\n```\r\n\r\n![](https://raw.githubusercontent.com/stla/RCDT/main/inst/images/sunCurve.png)\r\n\r\n\r\n## License\r\n\r\nThe 'RCDT' package as a whole is distributed under GPL-3 (GNU GENERAL\r\nPUBLIC LICENSE version 3).\r\n\r\nIt uses the C++ library [CDT](https://github.com/artem-ogre/CDT) which is \r\npermissively licensed under MPL-2.0. A copy of the 'CDT' license is provided in \r\nthe file **LICENSE.note**, and the source code of this library can be found in \r\nthe **src** folder.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Frcdt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstla%2Frcdt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Frcdt/lists"}