使3D圆柱体脱离多边形

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

[我有一个多边形,想要将其转换为圆柱形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)

enter image description here

例如,我无法理解如何添加值为2和5的z轴:

library(rgl)
lines3d(x = rep(x$x, 2), y = rep(x$y, 2), z = rep(c(2, 5), each = nrow(x)))

enter image description here

我想使面孔变色并相互联系。类似cylinders on Wikipedia illustrations的东西,但自然不是圆端,而是那些多边形。如果使用rgl包,可能应该使用tringles3dtringles3d函数,但是我不知道如何重组data.frame。我不需要在rgl中执行此操作。那只是R包,对于该任务而言似乎是最可行的。如何重组数据以绘制3D圆柱体?

r 3d
1个回答
0
投票

您需要使用polygon3d创建多边形的“拉伸”。例如,使用问题中定义的extrude3d

x

生成此图像(经过一些手动旋转后::

x %>% extrude3d(thickness = 3, material = list(col = rainbow(14)), meshColor = "faces") %>% translate3d(x = 0, y = 0, z = 2) %>% shade3d()

[着色是一种有趣的方式:在两端绘制六边形,screenshot绘制4个三角形,并且每个着色都被视为一个单独的面。 rgl的另一个有趣参数是extrude3d:多面体绘制在thicknessz=0之间。由于您希望z=thickness从2到5,因此z为3,并且需要在z中将结果转换为2个单位。

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