繁体   English   中英

R中的最小二乘三角剖分

[英]Least Squares Triangulation in R

如果对已知点的3个点的距离进行观测,则未知点的坐标是什么?

例如:

x = c(30.0,10.0,50.0)
y = c(150.0,120.0,50.0)
distance = c("125.0 ± 0.5","133.5 ± 0.2","98.6 ± 0.2")
df = data.frame(x, y, distance) 

是否可以使用R通过(a)间接观测方法和(b)条件方程式使用最小二乘法计算未知点的坐标?

如何在R中导入“ 125.0±0.5”形式的数据?

这可能是一个开始。 我认为有一些方法可以使方程线性化,从而简化过程。 但是,这只是采取查找三个圆的交点的明显方法,并使用nlm来最小化正方形。 在这里,我完全不处理错误。

## Your data
x = c(30.0,10.0,50.0)
y = c(150.0,120.0,50.0)
## distance = c("125.0 ± 0.5","133.5 ± 0.2","98.6 ± 0.2")
dists <- c(125, 133.5, 98.6)  # simplified

## Minimize this function:
## x: guesstimates
## centers: fixed points (x, y)
## b: distances
f <- function(x, centers, b) {
    sqrt(sum((sqrt(colSums((x - centers)^2)) - b)^2))
}

## Get estimate: initial guess of c(100, 100)
centers <- matrix(c(x, y), nrow=2, byrow=TRUE)
res <- nlm(f, c(100, 100), centers=centers, b=dists)

## Lets visualize to see if it worked
circle <- function(x, y, d, col='black') {
    theta <- seq(0, 2*pi, length.out=100)
    data.frame(x=d*cos(theta)+x, y=d*sin(theta)+y, col, stringsAsFactors=FALSE)
}
cols <- colorRampPalette(c('blue', 'red'))(3)
circs <- Map(circle, x, y, dists, cols)
ps <- do.call(rbind, circs)
plot(ps[1:2], type='n')
grid()
abline(h=0, v=0)
points(x, y, col=cols, pch=16, cex=2)
for (i in circs) points(i[1:2], col=i$col, type='l')

## Add the estimated point
points(x=res$estimate[1], y=res$estimate[2], 
       col='firebrick', pch=8, cex=2)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM