# NOT RUN {
### Generate 100 data points on Sphere S^2.
# 50 points from near (0,0,1), and
# 50 points from near (0,0,-1)
ndata = 50
theta = seq(from=-0.99,to=0.99,length.out=ndata)*pi
tmpx = cos(theta)
tmpy = sin(theta)
### Wrap those as 'riemdata' class
data1 = list()
data2 = list()
for (i in 1:ndata){
tgt1 = c(tmpx[i],tmpy[i],1) + stats::rnorm(3,sd=0.1)
tgt2 = c(tmpx[i],tmpy[i],-1) + stats::rnorm(3,sd=0.1)
data1[[i]] = tgt1/sqrt(sum(tgt1^2)) # projection near (0,0,1)
data2[[i]] = tgt2/sqrt(sum(tgt2^2)) # (0,0,-1)
}
spdata1 = RiemBase::riemfactory(data1, name="sphere")
spdata2 = RiemBase::riemfactory(data2, name="sphere")
### Compute Two Types of Distances and Visualize
dist.int = rstat.pdist2(spdata1, spdata2, type="intrinsic")
dist.ext = rstat.pdist2(spdata1, spdata2, type="extrinsic")
### Visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
image(dist.int, main="intrinsic")
image(dist.ext, main="extrinsic")
par(opar)
# }
Run the code above in your browser using DataLab