Tôi có hai bộ ( sourcvà target) các điểm (x,y)mà tôi muốn căn chỉnh. Những gì tôi đã làm cho đến nay là:
- tìm trọng tâm của từng bộ điểm
- sử dụng sự khác biệt giữa các bản dịch trung tâm điểm trong
xvày
Những gì tôi muốn là tìm vòng quay tốt nhất (tính theo độ) để căn chỉnh các điểm .
Bất kỳ ý tưởng?
Mã M ở bên dưới (với các sơ đồ để trực quan hóa các thay đổi):
# Raw data
## Source data
sourc = matrix(
c(712,960,968,1200,360,644,84,360), # the data elements
nrow=2, byrow = TRUE)
## Target data
target = matrix(
c(744,996,980,1220,364,644,68,336), # the data elements
nrow=2, byrow = TRUE)
# Get the centroids
sCentroid <- c(mean(sourc[1,]), mean(sourc[2,])) # Source centroid
tCentroid <- c(mean(target[1,]), mean(target[2,])) # Target centroid
# Visualize the points
par(mfrow=c(2,2))
plot(sourc[1,], sourc[2,], col="green", pch=20, main="Raw Data",
lwd=5, xlim=range(sourceX, targetX),
ylim=range(sourceY, targetY))
points(target[1,], target[2,], col="red", pch=20, lwd=5)
points(sCentroid[1], sCentroid[2], col="green", pch=4, lwd=2)
points(tCentroid[1], tCentroid[2], col="red", pch=4, lwd=2)
# Find the translation
translation <- tCentroid - sCentroid
target[1,] <- target[1,] - translation[1]
target[2,] <- target[2,] - translation[2]
# Get the translated centroids
tCentroid <- c(mean(target[1,]), mean(target[2,])) # Target centroid
# Visualize the translation
plot(sourc[1,], sourc[2,], col="green", pch=20, main="After Translation",
lwd=5, xlim=range(sourceX, targetX),
ylim=range(sourceY, targetY))
points(target[1,], target[2,], col="red", pch=20, lwd=5)
points(sCentroid[1], sCentroid[2], col="green", pch=4, lwd=2)
points(tCentroid[1], tCentroid[2], col="red", pch=4, lwd=2)
sourcetarget
