Lad*_*aďo 8 3d 2d r transformation coordinates
我的问题很简单!如何将点xyz坐标(都属于单个平面)转换为仅xy坐标.我找不到任何R功能或R解决方案.

来源数据:
# cube with plain
library(scatterplot3d)
my.plain <- data.frame(ID = c("A","B","C","D","E","F","G","H"),
x = c(1,1,1,2,2,2,3,3),
y = c(1,1,1,2,2,2,3,3),
z = c(1,2,3,1,2,3,1,2))
scatterplot3d(my.plain$x, my.plain$y, my.plain$z,
xlim = c(0,3), ylim = c(0,3), zlim = c(0,3))
Run Code Online (Sandbox Code Playgroud)
如何获得点数据帧,其中A点为[0,0],而A和D之间的距离为sqrt(2)?
所以你现在拥有的是共面点的 3D 坐标(你确实可以通过计算矩阵 的秩my.plain[, c("x", "y", "z")](即 2)来验证你的点是否共面)。
您希望新的“框架”由点 A 定义为原点,向量(A->B)/|A->B|^2和(A->D)/|A->D|^2。
要将 xyz 坐标转换为新“框架”中的坐标,您需要将之前的坐标(移动 A 的坐标)乘以从旧框架到新框架的变换矩阵。
因此,在 R 代码中,这给出:
# Get a matrix out of your data.frame
row.names(my.plain) <- my.plain$ID
my.plain <- as.matrix(my.plain[, -1])
# compute the matrix of transformation
require(Matrix)
AB <- (my.plain["B", ] - my.plain["A", ])
AD <- (my.plain["D", ] - my.plain["A", ])
tr_mat <- cbind(AD/norm(AD, "2"), AB/norm(AB, "2"))
# compute the new coordinates
my.plain.2D <- (my.plain - my.plain["A", ]) %*% tr_mat
# plot the 2D data
plot(my.plain.2D, pch=19, las=1, xlab="x", ylab="y")
# and the plot with the letters, the polygon and the color:
plot(my.plain.2D, pch=3, las=1, xlab="x", ylab="y")
polygon(my.plain.2D[c("A", "B", "C", "F", "H", "G", "D"), ], col="magenta")
points(my.plain.2D, pch=3, lwd=2)
text(my.plain.2D[, 1], my.plain.2D[, 2], row.names(my.plain.2D), pos=2, font=2)
Run Code Online (Sandbox Code Playgroud)