# `rgl` package and `sphereplot` pacakges are needed for the visualizaiton of the following example.
# Define control points and knots
library(rgl)
library(sphereplot)
control_points <- matrix(c(1, 0, 0, # Control point 1
1/sqrt(2), 1/sqrt(2), 0, # Control point 2
-1/sqrt(3), 1/sqrt(3), 1/sqrt(3), # Control point 3
0, 0, 1), # Control point 4
nrow = 4, byrow = TRUE)
knots <- c(1, 2, 3, 3.5) # Knots indicating transitions
# Example of generating piecewise geodesic curve
t_example <- seq(0, 4, by = 0.01)
gamma_example <- piecewise_geodesic(t_example, control_points, knots)
# Plotting the piecewise geodesic curve
rgl.sphgrid(deggap = 45, col.long = "skyblue", col.lat = "skyblue")
spheres3d(x = 0, y = 0, z = 0, radius = 1, col = "grey", alpha = 0.05)
pch3d(control_points, col = "blue", cex = 0.2, pch = 19)
lines3d(gamma_example, col = "red", lty = 1, lwd = 2)
Run the code above in your browser using DataLab