1

別の線に対して 90 度の角度の線分パターンがあります。

require(spatstat)    
range <- c(0,10)

owin <- owin(xrange = range, yrange = range)

l1 <- psp(x0 = 8, x1 = 8, y0 = 2, y1 = 8, window = owin, marks = "l1")
l2 <- psp(x0 = 6, x1 = 6, y0 = 2, y1 = 8, window = owin, marks = "l2")
l3 <- psp(x0 = 4, x1 = 4, y0 = 2, y1 = 8, window = owin, marks = "l3")
l4 <- psp(x0 = 2, x1 = 2, y0 = 2, y1 = 8, window = owin, marks = "l4")

lines <- superimpose(l1, l2, l3, l4)

main <- psp(x0 = 8, x1 = 0, y0 = 5, y1 = 5, window = owin, marks = "main")

angles.psp(lines)*(180/pi)
[1] 90 90 90 90

視覚的な表現は次のとおりです。

plot(x = range, y = range, type = "n", main = "", asp = 1, axes = F, xlab = "x", ylab = "y")
plot(lines, col = "darkgrey", add = T)
plot(main, col = "black", add = T)
axis(1)
axis(2, las = 2)

ここに画像の説明を入力

ここで、同じ点で 45 度の角度でlines交差するように回転させたいと思います。main

lines.rotated <- rotate(lines, -0.7853982)
angles.psp(lines.rotated)*(180/pi)
[1] 45 45 45 45

これは機能しますが、関数は必要に応じて行ではなくウィンドウ ( ) を個別にangles.psp回転するようです。owin

plot(x = range, y = range, type = "n", main = "", asp = 1, axes = F, xlab = "x", ylab = "y")
plot(lines, col = "darkgrey", add = T)
plot(lines.rotated, col = "blue", add = T)
plot(main, col = "black", add = T)
axis(1)
axis(2, las = 2)

ここに画像の説明を入力

lines角度が 45 度になるように線に対してすべてを回転させる方法はありますmainが、交点は同じままですか?

4

2 に答える 2

1

私があなたの考えを理解したかどうかはわかりません。

単純化したアプローチの場合elide、maptools からオプションを選択できますか?

このようなもの:

library(maptools)
# convert lines to SpatialLines
slines <- as(lines, 'SpatialLines')

plot(x = range, y = range, type = "n", main = "", asp = 1, axes = F,
     xlab = "x", ylab = "y")
plot(lines, col = "darkgrey", add = T)
plot(main, col = "black", add = T)
axis(1)
axis(2, las = 2)
# Plot slines object on top of your data
plot(elide(slines, rotate = 45, center = c(5, 5)), add = T)

# plot it

回転した直線

ただし、回転した線の各線が、線とメインの交点を横切ることが必要な場合があります。本当?

その場合、各 psp 行でループします。psp l4 の場合:

plot(elide(slines[4], rotate = 45, center = c(2, 5)), add = T)

交点にプロット

あなたはそれを強制的にpspに戻すことができます

as.psp.Lines(from, ..., window=NULL, marks=NULL, fatal)
于 2014-02-26T10:26:34.140 に答える
1

答えを自己完結させるためだけに。次のコードは、探しているものを生成するはずです (これが便利な関数である場合は、Adrian (spatstat のメンテナ) に改良版を spatstat に含めるよう依頼できます)。最初の前提条件:

require(spatstat)

linerotate.psp <- function(X, L, angle){
    ## Window:
    W <- as.owin(X)
    ## Empty psp object:
    Y <- psp(numeric(0),numeric(0),numeric(0),numeric(0),W)
    for(i in 1:X$n){
        ## Line i:
        Xi <- X[i]
        ## Crossing of line i and test line L in the window:
        cross <- crossing.psp(L, Xi)
        ## Rotate line if the crossing is non-empty:
        if(npoints(cross)>0){
            m <- as.numeric(coords(cross))
            ## Move to crossing:
            Xi <- affine(Xi, vec = -m)
            ## Rotate:
            Xi <- rotate(Xi, angle = angle)
            ## Move back:
            Xi <- affine(Xi, vec = m)
            ## Restrict to non-rotated window:
            Xi <- Xi[W]
        }
        ## Collect results:
        Y <- superimpose(Y, Xi)
    }
    return(Y)
}

データ:

W <- square(10)

x0 <- c(8,6,4,2)
x1 <- x0
y0 <- rep(2,4)
y1 <- rep(8,4)

lines <- psp(x0, y0, x1, y1, window = W)

main <- psp(x0 = 8, x1 = 0, y0 = 5, y1 = 5, window = W)

回転したデータと角度の比較:

rotlines <- linerotate.psp(lines, main, angle = -pi/4)
angles.psp(lines)*(180/pi)
[1] 90 90 90 90
angles.psp(rotlines)*(180/pi)
[1] 45 45 45 45

グラフィカルに:

plot(lines, col = "darkgrey")
plot(main, col = "black", add = T)
plot(rotlines, col = "blue", add = T)

回転した線

水平でないテスト ラインを使用したグラフィカルな表示:

main <- psp(x0 = 0, x1 = 10, y0 = 3, y1 = 7, window = W)
rotlines <- linerotate.psp(lines, main, angle = -pi/4)

plot(lines, col = "darkgrey")
plot(main, col = "black", add = T)
plot(rotlines, col = "blue", add = T)

回転した行 2

于 2014-02-26T10:44:52.547 に答える