用多边形制作 3D 圆柱体
Making a 3D cylinder out of a polygon
我有一个多边形,我想将其转换为圆柱形 3D 对象以进行说明:
x <- structure(list(x = c(7.99, 6.25, -1.77, -1.8, -0.48, 3.93, 7.99
), y = c(2.84, 2.31, 2.43, 2.98, 3.19, 3.26, 2.84)), row.names = c(NA,
7L), class = "data.frame")
plot(x$x, x$y, type = "n")
polygon(x$x, x$y, col = "blue")
points(x$x, x$y)
我无法理解如何添加值为 2 和 5 的 z 轴,例如:
library(rgl)
lines3d(x = rep(x$x, 2), y = rep(x$y, 2), z = rep(c(2, 5), each = nrow(x)))
我想把面孔涂上颜色并连接起来。如果我使用 rgl 包,我应该使用 cylinders on Wikipedia illustrations, but naturally not round ends, but those polygons instead. tringles3d
或 polygon3d
函数之类的东西,但我不明白如何重组我的 data.frame。我不需要在 rgl 中这样做。这只是 R 包,似乎对这项任务最可行。我应该如何重新组织数据以绘制 3D 圆柱体?
您需要使用 extrude3d
创建多边形的 "extrusion"。
例如,问题中定义的 x
,
x[-1,] %>%
extrude3d(thickness = 3, material = list(col = rainbow(14)),
meshColor = "faces") %>%
translate3d(x = 0, y = 0, z = 2) %>%
shade3d()
生成此图像(经过一些手动旋转):
它使用 x[-1,]
,因为你在最后重复了第一个顶点:它需要唯一的顶点。
上色有点搞笑:为了在两端画六边形,rgl
画了4个三角形,每一个都当作一个面来上色。如果你想要那里的纯色,请记住首先画出末端:所以使用像
这样的东西
material = list(col = rainbow(8)[c(1,1,1,1,2,2,2,2:8)])
相反。
extrude3d
的另一个有趣论点是 thickness
:多面体绘制在 z=0
和 z=thickness
之间。因为你想要 z
从 2 到 5,所以 thickness
是 3,结果需要在 z 中向上翻译 2 个单位。
还有 cylinder3d
,用于生成管状结构,但如果您只想让多边形显示在与侧面成直角的两个位置,则 extrude3d
使用起来更简单。
我有一个多边形,我想将其转换为圆柱形 3D 对象以进行说明:
x <- structure(list(x = c(7.99, 6.25, -1.77, -1.8, -0.48, 3.93, 7.99
), y = c(2.84, 2.31, 2.43, 2.98, 3.19, 3.26, 2.84)), row.names = c(NA,
7L), class = "data.frame")
plot(x$x, x$y, type = "n")
polygon(x$x, x$y, col = "blue")
points(x$x, x$y)
我无法理解如何添加值为 2 和 5 的 z 轴,例如:
library(rgl)
lines3d(x = rep(x$x, 2), y = rep(x$y, 2), z = rep(c(2, 5), each = nrow(x)))
我想把面孔涂上颜色并连接起来。如果我使用 rgl 包,我应该使用 cylinders on Wikipedia illustrations, but naturally not round ends, but those polygons instead. tringles3d
或 polygon3d
函数之类的东西,但我不明白如何重组我的 data.frame。我不需要在 rgl 中这样做。这只是 R 包,似乎对这项任务最可行。我应该如何重新组织数据以绘制 3D 圆柱体?
您需要使用 extrude3d
创建多边形的 "extrusion"。
例如,问题中定义的 x
,
x[-1,] %>%
extrude3d(thickness = 3, material = list(col = rainbow(14)),
meshColor = "faces") %>%
translate3d(x = 0, y = 0, z = 2) %>%
shade3d()
生成此图像(经过一些手动旋转):
它使用 x[-1,]
,因为你在最后重复了第一个顶点:它需要唯一的顶点。
上色有点搞笑:为了在两端画六边形,rgl
画了4个三角形,每一个都当作一个面来上色。如果你想要那里的纯色,请记住首先画出末端:所以使用像
material = list(col = rainbow(8)[c(1,1,1,1,2,2,2,2:8)])
相反。
extrude3d
的另一个有趣论点是 thickness
:多面体绘制在 z=0
和 z=thickness
之间。因为你想要 z
从 2 到 5,所以 thickness
是 3,结果需要在 z 中向上翻译 2 个单位。
还有 cylinder3d
,用于生成管状结构,但如果您只想让多边形显示在与侧面成直角的两个位置,则 extrude3d
使用起来更简单。