原神cdk:原线两侧的平行线(line parallel)

我想在原始折线 x 英尺的两侧绘制平行的折线,覆盖 2 英里。

line<-structure(list(ID = 1, result = structure(list(structure(c(-103.425920946, 
-103.420670944, 31.7545147220001, 31.7406247380001), .Dim = c(2L, 
2L), class = c("XY", "LINESTRING", "sfg"))), class = c("sfc_LINESTRING", 
"sfc"), precision = 0, bbox = structure(c(xmin = -103.425920946, 
ymin = 31.7406247380001, xmax = -103.420670944, ymax = 31.7545147220001
), class = "bbox"), crs = structure(list(input = "+proj=longlat +datum=NAD27 +no_defs", 
    wkt = "GEOGCRS[\"unknown\",\n    DATUM[\"North American Datum 1927\",\n        ELLIPSOID[\"Clarke 1866\",6378206.4,294.978698213898,\n            LENGTHUNIT[\"metre\",1]],\n        ID[\"EPSG\",6267]],\n    PRIMEM[\"Greenwich\",0,\n        ANGLEUNIT[\"degree\",0.0174532925199433],\n        ID[\"EPSG\",8901]],\n    CS[ellipsoidal,2],\n        AXIS[\"longitude\",east,\n            ORDER[1],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]],\n        AXIS[\"latitude\",north,\n            ORDER[2],\n            ANGLEUNIT[\"degree\",0.0174532925199433,\n                ID[\"EPSG\",9122]]]]"), class = "crs"), n_empty = 0L)), row.names = c(NA, 
-1L), class = c("sf", "tbl_df", "tbl", "data.frame"), sf_column = "result", agr = structure(c(ID = NA_integer_), .Label = c("constant", 
"aggregate", "identity"), class = "factor"))

enter image description here

是一个类似问题的链接,但只绘制一条偏移线。

Draw a parallel line in R offset from a line

谢谢

x <-  c(10,5)
y <-  c(1,3)
d <- -0.5   # distance away from the road
I believe i need a for loop here.
# Given a vector (defined by 2 points) and the distance, 
# calculate a new vector that is distance away from the original 
segment.shift <- function(x, y, d){
  
  # calculate vector
  v <- c(x[2] - x[1],y[2] - y[1])
  
  # normalize vector
  v <- v/sqrt((v[1]**2 + v[2]**2))
  
  # perpendicular unit vector
  vnp <- c( -v[2], v[1] )
  
  return(list(x =  c( x[1] + d*vnp[1], x[2] + d*vnp[1]), 
              y =  c( y[1] + d*vnp[2], y[2] + d*vnp[2])))
  
}
plot(x,y, xlim=c(-1,11), ylim=c(-1,11), type="l", main= "Bicycle path" )
# allocate memory for the bike path
xn <- numeric( (length(x) - 1) * 2 )
yn <- numeric( (length(y) - 1) * 2 )
for ( i in 1:(length(x) - 1) ) {
  xs <- c(x[i], x[i+1])
  ys <- c(y[i], y[i+1])
  new.s <- segment.shift( xs, ys, d )
  xn[(i-1)*2+1] <- new.s$x[1] ; xn[(i-1)*2+2] <- new.s$x[2]
  yn[(i-1)*2+1] <- new.s$y[1] ; yn[(i-1)*2+2] <- new.s$y[2]
}
# draw the path
lines(xn, yn, col="brown", lwd =2, lty=1)
0

只是需要一个循环

x <-  c(10,5)
y <-  c(1,3)
distance <- c(-0.5,.5,.75)   # distance away from the road
#key update
for (d in distance) {
  # Given a vector (defined by 2 points) and the distance, 
  # calculate a new vector that is distance away from the original 
  segment.shift <- function(x, y, d){
    
    # calculate vector
    v <- c(x[2] - x[1],y[2] - y[1])
    
    # normalize vector
    v <- v/sqrt((v[1]**2 + v[2]**2))
    
    # perpendicular unit vector
    vnp <- c( -v[2], v[1] )
    
    return(list(x =  c( x[1] + d*vnp[1], x[2] + d*vnp[1]), 
                y =  c( y[1] + d*vnp[2], y[2] + d*vnp[2])))
    
  }
  
  #plot(x,y, xlim=c(-1,11), ylim=c(-1,11), type="l", main= "Bicycle path" )
  
  # allocate memory for the bike path
  xn <- numeric( (length(x) - 1) * 2 )
  yn <- numeric( (length(y) - 1) * 2 )
  
  for ( i in 1:(length(x) - 1) ) {
    xs <- c(x[i], x[i+1])
    ys <- c(y[i], y[i+1])
    new.s <- segment.shift( xs, ys, d )
    xn[(i-1)*2+1] <- new.s$x[1] ; xn[(i-1)*2+2] <- new.s$x[2]
    yn[(i-1)*2+1] <- new.s$y[1] ; yn[(i-1)*2+2] <- new.s$y[2]
  }
  lines(xn, yn, col="brown", lwd =2, lty=1)  
}
``

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(66)
Crackles:用简单的图形播放 iOS网络音频时发出的裂纹和噪音
上一篇
Ui工具:UI测试工具(ui testing tools)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(61条)