x <- matrix(c(0, 3, 0.5, 4, 1, 1), ncol=2, byrow=TRUE) # x: (0,0)→(3,0), (0,0)→(4,0), (0,0)→(0,0)
y <- matrix(c(0, 0, 1, 3, 0.5, 5), ncol=2, byrow=TRUE) # y: (0,0)→(0,0), (0,0)→(3,0), (0,0)→(5,0)
(vectDist <- vectorDistAngle(x, y))
plot(cbind(x=as.numeric(x),y=as.numeric(y)), main="Example for vectorDistAngle()",las=1)
arrows(x[,1],y[,1],x[,2],y[,2])
text(x[,2], 0.1 +y[,2], paste0("dist=",round(vectDist[,1],2),
", angle=",round(vectDist[,2],2)), adj=1)
Run the code above in your browser using DataLab