检索关键字:
R语言
三维
3d
3D
R语言三维图像
R语言3D模型
R语言立体图像
三维体积计算
# Thu Sep 03 09:06:42 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.2
# cgh163email@163.com
#个人笔记不负责任
# —— 拎了个梨🍐
rm(list=ls());gc()
.rs.restartR()
require(alphashape3d)
# Thu Sep 03 09:43:09 2020 ---rtorus函数,在圆环中生成随机点---------------------------
# 此函数在圆环内生成n个随机点,其小半径为r,大半径为R,中心为ct。:
T1 <- rtorus(2000, 0.5, 2.5)
rgl.bbox()
rgl.points(T1, col = 4)
# 没有背景:
T2 <- rtorus(2000, 0.5, 2.5, ct = c(2, 0, 0.5), rotx = pi/2)
rgl.points(T2, col = 2)
# DIY:
a <- rtorus(10,.5,1 )# 生成n个大于min,小于max的随机数
b <- rtorus(10,.2,1 )# 生成n个大于min,小于max的随机数
dt.mat <- rbind(a,b)
myalpha <- .9
my3d.obj <- ashape3d(dt.mat,alpha = myalpha)
plot(my3d.obj)
# Thu Sep 03 10:04:13 2020 --ashape3d函数,构建图形----------------------------
# 计算三维空间中给定点样本的3Dα形状。
# 此函数在圆环内生成n个随机点,其小半径为r,大半径为R,中心为ct。:
T1 <- rtorus(1000, 0.5, 2)
T2 <- rtorus(1000, 0.5, 2, ct = c(2, 0, 0), rotx = pi/2)
x <- rbind(T1, T2)
rm(T1);rm(T2)
head(x)
# Z
# 1.6033958 -0.5457622 -0.25895432
# -0.8972383 1.5987173 0.04437849
# -2.0239157 -0.5564308 0.45616703
# 1.5193709 1.5879458 -0.20329480
#
alpha <- 0.25
#3D alpha形状
ashape3d.obj <- ashape3d(x, alpha = alpha)
plot(ashape3d.obj)
# 对于新的alpha值,我们可以使用ashape3d.obj作为输入(更快)
alpha <- c(0.15, 1)
ashape3d.obj <- ashape3d(ashape3d.obj, alpha = alpha)
plot(ashape3d.obj, indexAlpha = 2:3)
# Thu Sep 03 10:05:13 2020 -components_ashape3d函数关联子集计算----------------------------
# 此函数计算和聚类三维空间中给定点样本的α形状的不同连接分量。
T1 <- rtorus(1000, 0.5, 2)
T2 <- rtorus(1000, 0.5, 2, ct = c(2, 0, 0), rotx = pi/2)
x <- rbind(T1, T2)
alpha <- c(0.25, 2)
ashape3d.obj <- ashape3d(x, alpha = alpha)
plot(ashape3d.obj, indexAlpha = "all")
# 两个alpha值的alpha形状的连通分量
comp <- components_ashape3d(ashape3d.obj, indexAlpha = "all")
class(comp)
# N零件数和每个零件中的点数(对于alpha = 0.25)
table(comp[[1]])
# 零件数和每个零件中alpha = 2的点数
table(comp[[2]])
# 绘制连接组件的alpha = 0.25
plot(ashape3d.obj, byComponents = TRUE, indexAlpha = 1)
# Thu Sep 03 10:12:52 2020 -inashape3d函数,图形的内部-插入对象----------------------------
# 此功能检查点是否在α形内。
T1 <- rtorus(2000, 0.5, 2)
T2 <- rtorus(2000, 0.5, 2, ct = c(2, 0, 0), rotx = pi/2)
x <- rbind(T1, T2)
ashape3d.obj <- ashape3d(x,alpha = 0.4)
#平面中点的随机样本
points <- matrix(c(5*runif(10000) - 2.5, rep(0.01, 5000)), nc = 3)
in3d <- inashape3d(ashape3d.obj, # 表示三维空间中给定点样本的α形状的“ ashape3d”类对象
points = points) # 一个三列矩阵,带有输入点的坐标。
plot(ashape3d.obj, transparency = 0.2) # 透明度
# 叠加平面元素:
colors <- ifelse(in3d, "#7c1823", "#126bae")
rgl.points(points, col = colors)
# Thu Sep 03 10:22:21 2020 --plot.ashape3d ----------------------------
T1 <- rtorus(1000, 0.5, 2)
T2 <- rtorus(1000, 0.5, 2, ct = c(2, 0, 0), rotx = pi/2)
x <- rbind(T1, T2)
alpha <- c(0.15, 0.25, 1)
ashape3d.obj <- ashape3d(x, alpha = alpha)
# 绘制所有alpha值的alpha形状
plot(ashape3d.obj, indexAlpha = "all")
# 为alpha = 0.25绘制alpha形状的已连接组件
plot(ashape3d.obj, byComponents = TRUE, indexAlpha = 2)
# Thu Sep 03 10:40:25 2020 -surfaceNormals表面插入直线线向量 -----------------------------
x <- rtorus(1000, 1, 1)
alpha <- 0.7
ashape3d.obj <- ashape3d(x, alpha = alpha)
surfaceNormals(ashape3d.obj, display = TRUE)
# Thu Sep 03 10:43:16 2020 -Volume computation体积计算-----------------------------
# 此函数计算三维空间中给定点样本的α形状的体积。
C1 <- matrix(runif(6000), nc = 3)
C2 <- matrix(runif(6000), nc = 3) + 2
x <- rbind(C1, C2)
ashape3d.obj <- ashape3d(x, alpha = 0.75)
plot(ashape3d.obj, byComponents = TRUE)
#计算alpha形状的体积
volume_ashape3d(ashape3d.obj)
# 计算Alpha形状的连接组件的体积
volume_ashape3d(ashape3d.obj, byComponents = TRUE)
# Thu Sep 03 10:47:11 2020 --End----------------------------
空格分割的表格
x "A 3-column matrix with the coordinates of the input points. Alternatively, an object of class "ashape3d" can be provided, see Details." “具有输入点坐标的三列矩阵。或者,可以提供“ ashape3d”类的对象,请参见“详细信息”。
alpha A single value or vector of values for α. α的单个值或值向量。
pert Logical. If the input points are not in general position and pert it set to TRUE the observations are perturbed by adding random noise, see Details. 逻辑上。 如果输入点不在一般位置并将其设置为TRUE,则观察结果会因添加随机噪声而受到干扰,请参见“详细信息”。
eps Scaling factor used for data perturbation when the input points are not in general position, see Details. 输入点不在一般位置时用于数据微扰的比例因子,请参见“详细信息”。