mytri is an R package that demonstrates a simple method for connecting five 2D points into three triangles. This approach forms the foundation for exploring advanced Delaunay triangulation techniques in R.
Features
-
Triangulation Function:
Implementsconnect_five_points
that takes a 5×2 matrix of points and returns the points along with the edges forming three triangles. -
Sample Data:
Provides a built-in datasetsample_points
with five 2D coordinates. -
Graphical Output:
Offers code to visualize the triangulation using ggplot2.
Installation
Install the development version of mytri from GitHub:
devtools::install_github("SohaibRaoufy/mytri")
Example
The following example shows how to use the package:
# Load the built-in sample data
data("sample_points")
# Calculate the triangulation using the built-in data
result <- mytri::connect_five_points(sample_points)
print(result)
# Example custom input: a 5x2 matrix of points
custom_points <- matrix(c(1, 2, 2, 4, 4, 5, 5, 1, 3, 9), ncol = 2, byrow = TRUE)
result <- mytri::connect_five_points(custom_points)
print(result)