2016-05-06 6 views
0

長方形を描画するためのデータフレームがあります。私はどのx座標で縦線が交差するかを知りたい。R:線が交差する矩形の数

enter image description here

ので、この例では、すべてのxの答えが2注意する必要があります:ここで

DataFrame = structure(list(topleftx = c(567L, 762L, 579L), toplefty = c(1000L, 
1001L, 1304L), bottomrightx = c(761L, 956L, 949L), bottomrighty = c(1292L, 
1309L, 1774L), PageDetailID = c("0014214H565", "0014215H565", 
"0014216H565"), Page = c(3L, 3L, 3L)), .Names = c("topleftx", 
"toplefty", "bottomrightx", "bottomrighty", "PageDetailID", "Page" 
), row.names = 5:7, class = "data.frame") 

xmin = round_any(min(DataFrame$topleftx),100) 
xmax = round_any(max(DataFrame$bottomrightx),100) 
ymin = round_any(min(DataFrame$toplefty),100) 
ymax = round_any(max(DataFrame$bottomrighty),100) 

print(paste(xmin,xmax,ymin,ymax)) 

prec_x = round_any(0.1*(xmax-xmin),10) 
prec_y = round_any(0.1*(ymax-ymin),10) 

topleftx = round_any(DataFrame$topleftx,prec_x) 
toplefty = round_any(DataFrame$toplefty,prec_y) 
bottomrightx = round_any(DataFrame$bottomrightx,prec_x) 
bottomrighty = round_any(DataFrame$bottomrighty,prec_y) 


# View(DataFrame) 
require(grDevices) 
## set up the plot region: 
op <- par(bg = "white") 
plot(c(xmin, xmax), c(ymin, ymax), type = "n", xlab = "", ylab = "", main = "Y-axis should be inverted") 

#569 935 723 1076 
rect(topleftx, toplefty, bottomrightx, bottomrighty , col = c(NA,0))#, col = rainbow(11, start = 0.7, end = 0.1)) 

は、プロットの国境が同じ y常にではない - との間に隙間があるかもしれません長方形。

アイデア?ありがとう!そのxの値が範囲内にある場合

答えて

3

線は長方形を横断するtopleftx X

x.test <- 720 
sum(topleftx<=x.test & x.test<=bottomrightx) 

注矩形のエッジと一致する行を治療する方法に関する曖昧< = X < =右下。 < =(これらの値を含める)を使用するか、<を使用して除外するかを決定する必要があります。

+0

ありがとうございました!思ったよりも簡単な –

関連する問題