# NOT RUN {
#2D-Example:
library(transport)
set.seed(420)
N<-2
supp.size<-10^2
L<-sqrt(supp.size)
d<-2
data.list<-vector("list",N)
image.list<-vector("list",N)
for (i in 1:N){
t.vec<-seq(0,2*pi,length.out=supp.size)
pos<-cbind(cos(t.vec)*runif(1,0.2,1),sin(t.vec)*runif(1,0.2,1))
theta<-runif(1,0,2*pi)
rotation<-matrix(c(cos(theta),sin(theta),-1*sin(theta),cos(theta)),2,2)
pos<-pos%*%rotation
pos<-pos+1
pos<-pos/2
W<-rep(1/supp.size,supp.size)
data.list[[i]]<-transport::wpp(pos,W)
}
Geo<-geodesic_pos(data.list[[1]],data.list[[2]],2,seq(0,1,0.1))
## Set the image and/or gif flags to TRUE to run the example.
## CRAN policy prevents examples from generating files in the working directory,
## so this had to be disabled.
plotGeodesic(Geo,File="TestGeodesicDefault",images=FALSE,gif=FALSE)
plotGeodesic(Geo,method="bin",File="TestGeodesicDefaultBin",images=FALSE,gif=FALSE)
plotGeodesic(Geo,method="binSplit",File="TestGeodesicDefaultBinSPlit",
images=FALSE,gif=FALSE)
# }
# NOT RUN {
#3D-Example:
#Functions to build the example measures
gen_torus<-function(M,R,r){
theta<-seq(0,2*pi,length.out=M)
phi<-seq(0,2*pi,length.out=M)
G<-expand.grid(theta,phi)
x<-(R+r*cos(G[,1]))*cos(G[,2])
y<-(R+r*cos(G[,1]))*sin(G[,2])
z<-r*sin(G[,1])
return(cbind(x,y,z))
}
sq_norm<-function(v){
return(sqrt(sum(v^2)))
}
normalize<-function(v){
return(v/(sq_norm(v)))
}
rotate3D<-function(pos,axis,angle){
R<-matrix(0,3,3)
R[1]<-cos(angle)+axis[1]^2*(1-cos(angle))
R[2]<-axis[1]*axis[2]*(1-cos(angle))+axis[3]*sin(angle)
R[3]<-axis[3]*axis[1]*(1-cos(angle))-axis[2]*sin(angle)
R[4]<-axis[1]*axis[2]*(1-cos(angle))-axis[3]*sin(angle)
R[5]<-cos(angle)+axis[2]^2*(1-cos(angle))
R[6]<-axis[2]*axis[3]*(1-cos(angle))+axis[1]*sin(angle)
R[7]<-axis[1]*axis[3]*(1-cos(angle))+axis[2]*sin(angle)
R[8]<-axis[2]*axis[2]*(1-cos(angle))-axis[1]*sin(angle)
R[9]<-cos(angle)+axis[3]^2*(1-cos(angle))
return(t(diag(c(2,3,1))%*%(R%*%t(pos))))
}
## Example
set.seed(123)
M<-40
U<-runif(1,0.5,1)
Torus<-gen_torus(M,U,min(U/2,runif(1)))
v<-normalize(runif(3))
Torus<-rotate3D(Torus,v,runif(1,0,2*pi))
Torus1<-Torus%*%diag(runif(3,1,3))
U<-runif(1,0.5,1)
Torus<-gen_torus(M,U,min(U/2,runif(1)))
v<-normalize(runif(3))
Torus<-rotate3D(Torus,v,runif(1,0,2*pi))
Torus2<-Torus%*%diag(runif(3,1,3))
L<-length(Torus)/3
Torus1<-transport::wpp(Torus1,rep(1/L,L))
Torus2<-transport::wpp(Torus2,rep(1/L,L))
geo<-geodesic_pos(Torus1,Torus2,p=2,seq(0,1,0.1))
## Set the image and/or gif flags to TRUE to run the example.
## CRAN policy prevents examples from generating files in the working directory,
## so this had to be disabled.
plotGeodesic(geo,File="3dGeodesic",images=FALSE,gif=FALSE)
# }
Run the code above in your browser using DataLab