0

を使用X=rpoisline(4)して線を生成し、 でプロットしていplot(X)ます。X$ends私はそれらの座標とそれらの交点をselfcrossing.psp(X)(spatstatとのRでは:)と持っていますlibrary(spatstat)

セグメントとその座標のリストを取得し、それらを操作できるようにする必要があります (方向、位置、交差点を変更します...)。これらのセグメントは、線と他の線およびウィンドウとの交点によって定義する必要があります。

それで、交差していないセグメントのpspでいくつかの交差する線のpspを変換する簡単な方法がありませんか(明確であることを願っています)?

単純ではない方法がある場合は、興味があります。

御時間ありがとうございます !

編集 :

ここに私が持っている行があります:

ここに私が持っているものがあります

そして、ここに、各セグメントを (1 つずつ) 処理できれば作成できると思われるランダムなものを示します。したがって、ランダム行のリストからセグメントのリストを取得する必要があります。

そして、ここに私が必要なものがあります

4

2 に答える 2

2

OK、数回のコーヒーブレイクの後で、あなたが望むことをするいくつかのバグのあるコードがあります。お掃除はお任せします。

ranpoly <- function(numsegs=10,plotit=TRUE) {

require(spatstat)
# temp fix: put the first seg into segset. Later make it a constrained random.
segset<-psp(c(0,1,1,0,.25),c(0,0,1,1,0),c(1,1,0,0,1),c(0,1,1,0,.75),owin(c(0,1),c(0,1)) ) #frame the frame
for (jj in 1: numsegs) {
    # randomly select a segment to start from, a point on the seg, the slope,and direction
    # later... watch for slopes that immediately exit the frame
    endx <-sample(c(-0.2,1.2),1)  #force 'x1' outside the frame
# watch that sample() gotcha
    if(segset$n<=5) sampset <- c(5,5) else sampset<-5:segset$n
    startseg<-sample(sampset,1) #don't select a frame segment
    # this is slope of segment to be constructed
    slope <- tan(runif(1)*2*pi-pi) # range +/- Inf 
    # get length of selected segment
    seglen<-lengths.psp(segset)[startseg]
    startcut <- runif(1) 
    # grab the coords of starting point (similar triangles)
    startx<- segset$ends$x0[startseg] + (segset$ends$x1[startseg]-segset$ends$x0[startseg])*startcut #seglen
    starty<- segset$ends$y0[startseg] + (segset$ends$y1[startseg]-segset$ends$y0[startseg])*startcut #seglen
    # make a psp object with that startpoint and slope; will adjust it after finding intersections
    endy <- starty + slope*(endx-startx)
    newpsp<-psp(startx,starty,endx,endy,segset$window,check=FALSE)
    # don't calc crossing for current element of segset
    hits <- crossing.psp(segset[-startseg],newpsp)
    segdist <- dist(cbind(c(startx,hits$x),c(starty,hits$y)))
    # dig back to get the crosspoint desired -- have to get matrixlike object out of class "dist" object
    # And, as.matrix puts a zero in location 1,1 kill that row.
    cutx <- hits$x[ which.min( as.matrix(segdist)[-1,1] )]
    cuty <- hits$y[which.min(as.matrix(segdist)[-1,1] )]
    segset <- superimpose(segset,psp(startx,starty,cutx,cuty,segset$window))

} #end jj loop
if(plotit) plot(segset,col=rainbow(numsegs))
return(invisible(segset))
}
于 2013-01-18T14:59:01.103 に答える
1

このspatstat関数selfcut.pspは、まさにこの目的のために設計されています。

Y <- selfcut.psp(X)

線分パターンの操作の詳細については、spatstat bookのセクション 4.4 を参照してください。

于 2016-06-27T02:18:52.600 に答える