簡體   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