如何在rgl中使用除球体以外的点形状?

问题描述 投票:0回答:1

我试图用立方体上的点来说明投影的想法,用

rgl
显示以及它是什么 看起来像各种 2D 投影。

我的目标是使用不同的颜色和形状来区分 2D 绘图和 3D 绘图中的点, 但我不知道如何使用球体以外的方式绘制

rgl
中的点。

我现在的身材是这样的:

我在 10^3 立方体上生成点和两个投影:

vals <- c(0, 10)
X <- expand.grid(x1 = vals, x2=vals, x3=vals) |> as.matrix()

# project on just x1, x2 plane
P1 <- rbind(diag(2), c(0,0))
Y1 <- X %*% P1
# oblique projection
P2 <- matrix(c(0.71, 0.71, 0, -0.42, .42, 0.84), ncol=2)
Y2 <- X %*% P2

(b) 和 (c) 中的 2D 图使用 4 种不同的颜色和 4 种

pch
形状(正方形、圆形、三角形、菱形)

pch <- rep(15:18, 2)
colors <- c("red", "blue", "darkgreen", "brown")
col <- rep(colors, each = 2)

plot(Y1, cex = 3, 
     pch = pch, col = col,
     xlab = "Y[,1]", ylab = "Y[,2]",
     xlim = c(-1, 11), ylim = c(-1, 11))

plot(Y2, cex = 3, 
     pch = pch, col = col,
     xlab = "Y[,1]", ylab = "Y[,2]",
     xlim = c(-1, 15), ylim = c(-5, 14)
     )

这是我尝试使用

rgl
的方法。颜色是正确的,但显然,使用
pch
type = "s"
没有效果。 我想要的是形状:立方体、球体、金字塔、菱形(或其他任何形状)

library(rgl)
open3d()
plot3d(X, type = "s", size = 2,  pch = pch, col = col)
r 3d shapes rgl
1个回答
0
投票

您可以使用

type = "n"
设置绘图区域,然后使用
pch3d()
在点处绘制符号。例如,

library(rgl)
open3d()
plot3d(X, type = "n")
pch3d(X, pch = pch, col = col)

© www.soinside.com 2019 - 2024. All rights reserved.