在 rgl 中绘制具有给定坐标的长方体
Drawing cuboid with given coordinates in rgl
我正在尝试绘制给定顶点坐标的长方体:(-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)
使用 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")
我正在尝试绘制给定顶点坐标的长方体:(-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)
使用 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")