グラフを構成する2D空間の複数の点のx座標とy座標で満たされた複数の行列があります。行列は次のようになります
x1 x2 x3 x4 ...
y1 y2 y3y4..。
可能なグラフは次のようになります
私がやりたいのは、点Aと点Bの間の線がX軸に平行になるように、点Aを中心にグラフを回転させることです。
私の考えは、直線ABを直角三角形の仮説として扱い、α(点Aでの角度)を計算し、回転行列を使用してこのグラフの行列を回転させることでした。
私がこれまでにしたことは次のとおりです
#df is the subset of my data that describes the graph we're handling right now,
#df has 2 or more rows
beginx=df[1,]$xcord #get the x coordinate of point A
beginy=df[1,]$ycord #get the y coordinate of point A
endx=df[nrow(df)-1,]$xcord #get the x coordinate of point B
endy=df[nrow(df)-1,]$ycord #get the y coordinate of point B
xnow=df$xcord
ynow=df$ycord
xdif=abs(beginx-endx)
ydif=abs(beginy-endy)
if((xdif != 0) & (ydif!=0)){
direct=sqrt(abs((xdif^2)-(ydif^2))) #calculate the length of the hypothenuse
sinang=abs(beginy-endy)/direct
angle=1/sin(sinang)
if(beginy>endy){
angle=angle
}else{
angle=360-angle
}
rotmat=rot(angle) # use the function rot(angle) to get the rotation matrix for
# the calculated angle
A = matrix(c(xnow,ynow),nrow=2,byrow = TRUE) # matrix containing the graph coords
admat=rotmat%*%A #multiply the matrix with the rotation matrix
}
このアプローチは、必要な角度を常に計算するのに十分な柔軟性がないため失敗し、その結果、グラフが間違った角度および/または間違った方向に回転します。
読んでくれてありがとう、そしてうまくいけば、あなたの何人かはこれにいくつかの新鮮なアイデアをもたらすことができます
編集:これを再現するためのデータはここにあります
要求したデータの提供方法がわからない場合は、希望する方法を指定していただければ、別の方法で喜んで提供します。