gpt4 book ai didi

r - 在rgl中使用给定坐标绘制长方体

转载 作者:行者123 更新时间:2023-12-04 10:14:13 25 4
gpt4 key购买 nike

我正在尝试绘制一个给定顶点坐标的长方体:(-3,-2,-5), (-3,-2,6), (-3,3,-5), (-3,3, 6), (7,-2,-5), (7,-2,6), (7,3,-5), (7,3,6) 使用 rgl包裹。我是通过以下方式完成的:

library(rgl)
vertices1 <- c(
-3, -2, -5, 1,
7, -2, -5, 1,
7, 3, -5, 1,
-3, 3, -5, 1
)
vertices2 <- c(
-3, -2, 6, 1,
7, -2, 6, 1,
7, 3, 6, 1,
-3, 3, 6, 1
)
vertices3 <- c(
-3, -2, -5, 1,
-3, -2, 6, 1,
-3, 3, 6, 1,
-3, 3, -5, 1
)
vertices4 <- c(
7, -2, -5, 1,
7, -2, 6, 1,
7, 3, 6, 1,
7, 3, -5, 1
)
vertices5 <- c(
-3, 3, -5, 1,
7, 3, -5, 1,
7, 3, 6, 1,
-3, 3, 6, 1
)
vertices6 <- c(
-3, -2, -5, 1,
7, -2, -5, 1,
7, -2, 6, 1,
-3, -2, 6, 1

)
indices <- c( 1, 2, 3, 4 )
open3d()
wire3d( qmesh3d(vertices1, indices) , col = "blue")
wire3d( qmesh3d(vertices2, indices) , col = "blue" )
wire3d( qmesh3d(vertices3, indices) , col = "blue")
wire3d( qmesh3d(vertices4, indices) , col = "blue")
shade3d(qmesh3d(vertices1, indices) , col = "blue", alpha = 0.1)
shade3d(qmesh3d(vertices2, indices) , col = "blue", alpha = 0.1)
shade3d(qmesh3d(vertices3, indices) , col = "blue", alpha = 0.1)
shade3d(qmesh3d(vertices4, indices) , col = "blue", alpha = 0.1)
shade3d(qmesh3d(vertices5, indices) , col = "blue", alpha = 0.1)
shade3d(qmesh3d(vertices6, indices) , col = "blue", alpha = 0.1)

enter image description here

有没有更好的方法来使用 rgl ?

最佳答案

更简洁,避免重复一些顶点:

library(rgl)

vertices <- cbind(
c(-3,-2,-5),
c(-3,-2, 6),
c(-3, 3,-5),
c(-3, 3, 6),
c( 7,-2,-5),
c( 7,-2, 6),
c( 7, 3,-5),
c( 7, 3, 6)
)

indices <- cbind(
c(1, 5, 7, 3),
c(2, 6, 8, 4),
c(1, 2, 4, 3),
c(5, 6, 8, 7),
c(3, 7, 8, 4)
c(1, 5, 6, 2)
)

cuboid <- qmesh3d(
vertices = vertices,
indices = indices,
homogeneous = FALSE
)

shade3d(cuboid, color = "blue", alpha = 0.1)
wire3d(cuboid, color = "blue")

关于r - 在rgl中使用给定坐标绘制长方体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61157348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com