This function fits a principal circle on sphere via gradient descent algorithm.
PrincipalCircle(data, step.size = 1e-3, thres = 1e-5, maxit = 10000)
matrix or data frame consisting of spatial locations with two columns. Each row represents longitude and latitude.
step size of gradient descent algorithm. For convergence of the algorithm, step.size
is recommended to be below 0.01.
threshold of the stopping condition.
maximum number of iterations.
three-dimensional vector.
This function fits a principal circle on sphere via gradient descent algorithm. The function returns three-dimensional vectors whose components represent longitude and latitude of the center and the radius of the circle in regular order.
Jang-Hyun Kim, Jongmin Lee, Hee-Seok Oh (2020), Spherical principal curves <arXiv:2003.02578>.
# NOT RUN {
library(rgl)
library(sphereplot)
library(geosphere)
#### example 1: half-great circle data
circle <- GenerateCircle(c(150, 60), radius = pi/2)
half.great.circle <- circle[circle[, 1] < 0, , drop = FALSE]
sigma <- 2
half.great.circle <- half.great.circle + sigma * rnorm(nrow(half.great.circle))
## find a principal circle
# }
# NOT RUN {
PC <- PrincipalCircle(half.great.circle)
result <- GenerateCircle(PC[1:2], PC[3])
## plot
rgl.sphgrid()
rgl.sphpoints(half.great.circle, radius = 1, col = "blue", size = 12)
rgl.sphpoints(result, radius = 1, col = "red", size = 6)
# }
# NOT RUN {
#### example 2: circular data
n <- 700
x <- seq(-180, 180, length.out = n)
sigma <- 5
y <- 45 + sigma * rnorm(n)
simul.circle <- cbind(x, y)
## find a principal circle
PC <- PrincipalCircle(simul.circle)
result <- GenerateCircle(PC[1:2], PC[3])
## plot
rgl.sphgrid()
rgl.sphpoints(simul.circle, radius = 1, col = "blue", size = 12)
rgl.sphpoints(result, radius = 1, col = "red", size = 6)
#### example 3: earthquake data
data(Earthquake)
names(Earthquake)
earthquake <- cbind(Earthquake$longitude, Earthquake$latitude)
# }
# NOT RUN {
PC <- PrincipalCircle(earthquake)
# }
# NOT RUN {
result <- GenerateCircle(PC[1:2], PC[3])
## plot
rgl.sphgrid(col.long = "black", col.lat = "black")
rgl.sphpoints(earthquake, radius = 1, col = "blue", size = 12)
rgl.sphpoints(result, radius = 1, col = "red", size = 6)
# }
Run the code above in your browser using DataLab