我的数据集 x
, y
, z
和 size
立方矩形中的一些点(尺寸为500 * 250 * 4.4)。
我想知道如何以图形方式显示在MATLAB或R中是否存在从上表面到下表面的渗透路径?
(通过渗透路径,我指的是从上表面到下表面连接重叠或连接点的最小长度键合)
以下是数据:
x y z size time
209.209774 7.9408097 2.319656267 0.793087629 2.349739533
209.517228 7.7415856 3.106089673 0.855368535 3.328208366
209.825582 8.3846153 4.4 0.963765604 3.427967029
209.394164 7.3352438 2.237668673 0.793192695 3.796507832
209.63978 7.8792626 3.27099508 0.900599771 4.080787149
209.568834 7.8546372 2.132928776 0.706479048 4.976109131
128.111097 2.320084 1.009058449 0.84575615 5.009483351
128.828759 3.0712943 2.203492827 0.801342486 6.86730518
130.167194 3.1545389 0.447034036 0.710835683 7.899154944
128.079092 2.9857334 1.172837724 0.938893977 8.958792166
128.168961 3.1109508 1.59741468 0.828790284 9.601263
126.428196 1.2431261 4.4 0.841620207 10.28888122
169.000926 232.3168799 2.838484773 0.965162937 14.44635033
167.613178 233.0870048 4.4 0.963311412 17.31717175
168.280608 232.7597414 2.986730293 0.935770919 18.75617743
169.515323 232.2533107 1.903419973 0.832796506 18.97671994
169.0959 232.8055114 1.849872924 0.963380767 20.05274055
169.360326 232.178669 3.254741781 0.798400142 21.72085676
316.914311 85.1429799 0.304532208 0.874779903 21.82851836
317.666683 84.3638348 0.575424986 0.897444099 23.44320468
317.843483 84.3204013 0.649951435 0.819952123 31.73428955
316.411077 85.2226315 1.208328587 0.909955711 32.665324
315.528734 84.5738727 0 0.803030253 39.84755565
316.95075 85.9984237 0 0.846629661 43.03680485
473.066628 144.3695194 3.692835902 0.708103992 44.77448685
472.511676 144.642549 2.703160589 0.727135968 46.00986403
471.789029 145.1873901 4.4 0.793700934 46.10006721
473.124093 144.6244314 3.748699545 0.923879276 46.67709969
473.007353 144.4490594 3.822257434 0.813995533 47.13577935
474.160461 144.3467013 0.667543933 0.768687855 49.28275368
401.928394 143.4728223 1.709059908 0.82799731 49.83156299
401.536748 144.5209801 1.3955402 0.875955905 50.6172275
401.827267 144.5965744 0 0.84700354 53.46835651
402.338068 143.7885394 3.346277835 0.825995466 56.55046007
401.669496 144.1486653 4.4 0.854163065 58.68959416
401.616204 144.0842306 2.146882026 0.829120948 59.26343762
403.357177 71.4047311 3.236605073 0.936593234 59.89403416
402.618287 71.1964819 2.413086339 0.732318033 60.23297696
403.453695 71.4333441 2.520175374 0.729361398 62.50977251
403.21512 71.8066027 3.401890159 0.861805672 65.57455915
404.556463 71.2015514 2.526535007 0.952867407 66.72056939
403.646341 71.4315758 2.430139247 0.972378323 67.01929229
102.114416 68.5545694 2.506939095 0.834796995 70.27866664
106.483907 68.6162716 0.753957696 0.894386379 70.83871434
这是我在R中绘制它的方式:
library(rgl)
library (graphics)
library(grDevices)
library(plotrix)
x <- read.table(file.choose(), sep=",", header=T )
y <- x[,1:3]
spheres3d(y, radius=15*(x$size), alpha=1)
答案 0 :(得分:1)
像这样(将数据加载到d
):
# compute xyz pythagorean distance between all points as a full matrix:
dd = dist(d[,c("x","y","z")])
ddm = as.matrix(dd)
# compute similar matrix based on sum of object sizes (assumes size is radius)
drad = outer(d$size, d$size, "+")
# compute overlap matrix as any pairs of points closer than sum of their radii
dadj = (ddm<=drad)
# and convert to a graph object
require(igraph)
dg = graph.adjacency(dadj, mode="undirected")
# all objects at the top have z-size less than 0
starts = which(d$z-d$size < 0)
# objects at bottom have z+size greater than 4.4
ends = which(d$z+d$size > 4.4)
# now try and find paths:
range(shortest.paths(dg, starts, ends))
[1] Inf Inf
这意味着没有找到路径。
如果再次尝试双倍大小,即用以下代码替换上面一行:
# double the size:
drad = outer(2*d$size, 2*d$size, "+")
然后:
range(shortest.paths(dg, starts, ends))
[1] 1 Inf
表示顶部和底部的对象之间至少有一条路径。
> which(shortest.paths(dg, starts, ends)<Inf, arr.ind=TRUE)
row col
24 5 3
133 24 16
133 24 17
这告诉我们有三条路径,从starts[5]
,starts[24]
和starts[24]
开始,分别在ends[3]
,ends[16]
结束和ends[17]
。进一步的igraph函数将显示路径:
> get.shortest.paths(dg, starts[5], ends[3] )$vpath
[[1]]
[1] 24 26
> get.shortest.paths(dg, starts[24], ends[16] )$vpath
[[1]]
[1] 133 150 151
> get.shortest.paths(dg, starts[24], ends[17] )$vpath
[[1]]
[1] 133 150 153
返回的数字是沿路径遍历的点数据中的索引。所以:
d[get.shortest.paths(dg, starts[24], ends[17] )$vpath[[1]],]
x y z size
133 324.8932 146.4365 0.8823413 0.9670826
150 325.3532 143.7297 2.9670642 0.9871330
153 325.8101 144.3565 4.3900869 0.9981148
请注意,从starts[24]
到ends[17]
的路径可能不止一条。 get.shortest.paths
函数仅返回一个开始/结束点。要全部看到它们:
> get.all.shortest.paths(dg, starts[24], ends[17] )
$res
$res[[1]]
[1] 133 152 153
$res[[2]]
[1] 133 150 153
[...]
这表明我们有两条路线,分别是152或150.这两条路线的分数是:
> d[get.all.shortest.paths(dg, starts[24], ends[17] )$res[[1]],]
x y z size
133 324.8932 146.4365 0.8823413 0.9670826
152 325.9366 144.5316 2.3215717 0.8693740
153 325.8101 144.3565 4.3900869 0.9981148
> d[get.all.shortest.paths(dg, starts[24], ends[17] )$res[[2]],]
x y z size
133 324.8932 146.4365 0.8823413 0.9670826
150 325.3532 143.7297 2.9670642 0.9871330
153 325.8101 144.3565 4.3900869 0.9981148
这让我想到了 - &#34;最短路线&#34;计算为点之间的最小步数,并未考虑大小。因此,由十点组成的长路线是“更短的”#34;而不是由11个点组成的短程路线。你最初的问题是关于是否有任何渗透,所以我并没有真正想到找到任何意义上的最小路径,只是路径是否存在。
应该可以构造图形,边缘用点的大小加总,然后找到最短的路径...