2
> d
         [,1]        [,2]
1  -0.5561835  1.49947588
2  -2.3985544  3.07130217
3  -3.8833659 -4.29331711
4   3.1025836  5.45359160
5   0.7438354 -2.80116065
6   7.0787294 -2.78121213
7  -1.6633598 -1.17898157
8  -0.6751930  0.03466162
9   1.4633841  0.50173157
10 -3.2118758  0.49390863

上の表は、プロットしたいプロットの x(1 列目)と y(2 列目)の座標を示しています。

require(MASS)               # for sammon using which i generated the above coordinates
require(deldir)             # for voronoi tessellations
dd <- deldir(d[,1], d[,2])  # voronoi tessellations
plot(dd,wlines="tess")      # This will give me tessellations

次のテッセレーションを上記のテッセレーションの 1 つの領域にプロットしたいと考えています。dd$dirsgs を使用してテッセレーションを形成する線を取得できます。この中で、テッセレーションにある各ラインには、それらの終点が与えられます。この最初の 4 列は、それぞれ x1,y1 および x2,y2 座標を示します。これらの座標は、線の終点です。このデータを使用して、上記のテッセレーションのこの 1 つの領域内に次のサブテッセレーションをプロットできます。

次のサブテッセレーションでは、選択した座標を生成できます。しかし、私はそれらが上記のプロットされたテッセレーションの 1 つの領域にあることを望んでいます。

dd$dirsgs の ind 1 と ind2 は、dd$dirsgs の最初の 4 列で表される線で区切られた「d」の点を示します。

たとえば、d の最初の点を含むプロットでサブテッセレーションをプロットする場合、行 1、2、9、12、17 は、d の最初の点の境界を形成する行です。この情報を使用して、この領域内にサブテッセレーションをプロットできますか? –</p>

私の問題を理解するために必要なすべてのことをカバーしたと思います。含まれていないデータが他にある場合は、お知らせください。情報をお伝えします。

4

2 に答える 2

2

私がそれを理解する方法(つまり、あなたの質問を正しく理解した場合)plot.deldirは、引数add=TRUEを渡すことができるため、直接行うことができます。

d<-structure(list(V1 = c(-0.5561835, -2.3985544, -3.8833659, 3.1025836, 0.7438354, 
                  7.0787294, -1.6633598, -0.675193, 1.4633841, -3.2118758), V2 = 
                  c(1.49947588, 3.07130217, -4.29331711, 5.4535916, -2.80116065, 
                  -2.78121213, -1.17898157, 0.03466162, 0.50173157, 0.49390863)), .Names =        
                  c("V1","V2"), class = "data.frame", row.names = c(NA, -10L))

library(MASS)
library(deldir)
dd <- deldir(d[,1], d[,2])
plot(dd, wlines="tess")

ここに画像の説明を入力

最初にポリゴンのデータを抽出しましょう: コメントで気付いたように、ポリゴンはポリゴンごとにでplot.deldirはなくラインごとにプロットされるため、以前に考えていたより多くの処理が必要dd$dirsgsです。

ddd <- as.matrix(dd$dirsgs[dd$dirsgs$ind2==1,1:4])
d1poly <- rbind(ddd[1,1:2],ddd[1,3:4])
for( i in 2:nrow(ddd)){
    x <- ddd[ddd[,1]==d1poly[i,1], 3:4]
    d1poly <- rbind(d1poly, x)
    }
d1poly
         x2       y2
  -2.096990 1.559118
   0.303986 4.373353
x  1.550185 3.220238
x  0.301414 0.692558
x -1.834581 0.866098
x -2.096990 1.559118

package を使用して、対象のポリゴンにランダム データを作成しましょうsplancs

library(splancs)
rd <- csr(as.matrix(d1poly),10) # For 10 random points in the polygon containing point 1
rd
              xc        yc
 [1,] -1.6904093 1.9281052
 [2,] -1.1321334 1.7363064
 [3,]  0.2264649 1.3986126
 [4,] -1.1883844 2.5996515
 [5,] -0.6929208 0.8745020
 [6,] -0.8348241 2.3318222
 [7,]  0.9101748 1.9439797
 [8,]  0.1665160 1.8754703
 [9,] -1.1100710 1.3517257
[10,] -1.5691826 0.8782223

rdd <- deldir(c(rd[,1],d[1,1]),c(rd[,2],d[1,2])) 
# don't forget to add the coordinates of your point 1 so it s part of the sub-tessellation
plot(dd, wlines="tess")
plot(rdd, add=TRUE, wlines="tess")

ここに画像の説明を入力

編集
境界内の線を制限することに関して、私が考えることができる唯一の解決策は、非常に醜い回避策です。最初にサブテッセレーションを描画し、次に関心のあるポリゴンの外側を非表示にしてから、グローバルテッセレーションをプロットします。

plot(dd, wlines="tess", col="white", wpoints="none")
plot(rdd, wlines="tess", add=TRUE)

plotlim <- cbind(par()$usr[c(1,2,2,1)],par()$usr[c(3,3,4,4)])
extpoly <- rbind(plotlim, d1poly) 
#Here the first point of d1poly is oriented toward the upper left corner: if it is oriented otherwise the order of plotlim has to be changed accordingly

polygon(extpoly, border=NA, col="white")

plot(dd, wlines="tess", add=TRUE)

ここに画像の説明を入力

于 2013-02-12T16:25:57.423 に答える
1

spatstat代わりに、新しいテッセレーションを既存のテッセレーションのタイルに制約することを大幅に簡素化できるため、このパッケージの使用を検討することをお勧めします。セットアップは次のようになります。

library(spatstat)
# Plot the main tessellation and points
d<-structure(list(V1 = c(-0.5561835, -2.3985544, -3.8833659, 3.1025836, 0.7438354, 
                  7.0787294, -1.6633598, -0.675193, 1.4633841, -3.2118758), V2 = 
                  c(1.49947588, 3.07130217, -4.29331711, 5.4535916, -2.80116065, 
                  -2.78121213, -1.17898157, 0.03466162, 0.50173157, 0.49390863)), .Names =        
                  c("V1","V2"), class = "data.frame", row.names = c(NA, -10L))

d_points <- ppp(d$V1, d$V2, window=owin(c(-5, 8), c(-6, 6)))
main_tessellation <- dirichlet(d_points)
plot(main_tessellation, lty=3) # plot the tessellation
plot(d_points, add=TRUE) # add the points

# Plot the interior tessellation and points (color=red so the difference is clear)
# Arbitrarily choosing the 9th tile from the above tessellation:
target_poly <- owin(poly=main_tessellation$tiles[[9]]$bdry[[1]])

# Generate random set of points within the boundaries of the polygon chosen above
new_points <- runifpoint(6, win=target_poly)
# Generate and plot the new tessellation and points
new_tessellation <- dirichlet(new_points)
plot(new_tessellation, add=TRUE, col='red')
plot(new_points, add=TRUE, col='red')

どちらが生成されますか: ここに画像の説明を入力

この密接に関連する質問を参照してください:地理的境界に囲まれたボロノイ図ポリゴン

于 2014-06-17T15:31:45.743 に答える