-, elipse, , , , :
. wikipaedia
(x-h) ยฒ/(rx) ยฒ + (y-k) ยฒ/(ry) ยฒ = 1
(x, y) (h, k) rx, ry .
wikipaedia:
(x-v) ^ T A (x-v) = < 1
x - , . v - , . A - - , .
R:
origin <- c(h=1,k=2,l=3)
coords <- matrix(c(1,2,3,4,5,6),nrow=3)
A <- matrix(c(0,1,1,1,0,1,1,1,0),nrow=3)
cFromO <- coords-origin
:
apply(cFromO,2,function(c){t(c) %*% A %*% c})<=1
, , roxygen:
IsInEllipsoid <- function(points,origin,A){
cFromO <- points-origin
isIn <- (diag(cFromO %*% A %*% t(cFromO))<=1)
return(isIn)
}
:
p1 <- c(1,2,3)
p2 <- c(4,5,6)
points <- rbind(p1,p2)
origin <- c(h=1,k=2,l=3)
axe1 <- c(0,0,2)
axe2 <- c(0,1,0)
axe3 <- c(0.5,0,0)
A <- rbind(axe1,axe2,axe3)
expect_equal(IsInEllipsoid(points,origin,A),c(p1=TRUE,p2=FALSE))
Edit
, , / A chi , . , R:
set.seed(1234)
origin <- c(0.5,0.5,0.5)
sigma <- matrix(c(.58,.49,.37,.49,.58,.38,.37,.38,.34),3,3)
sigmaInv <-solve(sigma)
ArePointsInCVEllipsoid <- function(points,origin,sigmaInv,CV){
nDegreeFreedom <- length(dim(sigmaInv)[1])
cFromO <- points-origin
areIn <- apply(cFromO,2,function(p){t(p) %*% sigmaInv %*% p <= qchisq(CV,nDegreeFreedom)})
return(areIn)
}
k<-10000 # number of points to be drawn
toTest <- matrix(runif(k*3,min=-3,max=3),nrow=3)
library(scatterplot3d)
toPlot <-t(toTest[,which(ArePointsInCVEllipsoid(toTest,origin,sigmaInv,0.95))])
scatterplot3d(toPlot)