R 平行线的旋转

R 平行线的旋转,r,rotation,R,Rotation,在绘图中考虑这两个平行段 plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6)) segments(1, 1, 6, 1) segments(1, 3, 6, 3) 如何将两条线一起旋转定义的角度 提前谢谢大家 最好的, 安东尼奥 下面是答案之后的一些观察结果 如果我们使用函数将笛卡尔空间中线段的度数返回到示例中使用的线段: segments(1, 1, 6, 1) angle <- function(x, y) re

在绘图中考虑这两个平行段

plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
segments(1, 1, 6, 1)
segments(1, 3, 6, 3)
如何将两条线一起旋转定义的角度

提前谢谢大家

最好的, 安东尼奥


下面是答案之后的一些观察结果

如果我们使用函数将笛卡尔空间中线段的度数返回到示例中使用的线段:

segments(1, 1, 6, 1)
angle <- function(x, y) return( atan2((y[2]-y[1]), (x[2]-x[1]))*(180/pi) )
但是,通过应用提供的功能:

> xyrot<-function(pairs,ang){
>     # pairs must be Nx2 matrix w/ x in first column and y in second
>     xrot <- pairs[,1]*cos(ang) - pairs[,2]*sin(ang)
>     yrot <- pairs[,1]*sin(ang) + pairs[,2]*cos(ang)
>     return(invisible(cbind(xrot,yrot))) }
图中也没有垂直线

plot(rot90)
segments(rot90[1,1], rot90[1,2], rot90[2,1], rot90[2,2])
我错过什么了吗


Sí,
ang
应为弧度:)

如下:

# coordinate transform: cartesian plane rotation
xyrot<-function(pairs,ang){
    # pairs must be Nx2 matrix w/ x in first column and y in second
    xrot <- pairs[,1]*cos(ang) - pairs[,2]*sin(ang)
    yrot <- pairs[,1]*sin(ang) + pairs[,2]*cos(ang)
    return(invisible(cbind(xrot,yrot)))
}
坐标变换:笛卡尔平面旋转 xyrot像这样:

# coordinate transform: cartesian plane rotation
xyrot<-function(pairs,ang){
    # pairs must be Nx2 matrix w/ x in first column and y in second
    xrot <- pairs[,1]*cos(ang) - pairs[,2]*sin(ang)
    yrot <- pairs[,1]*sin(ang) + pairs[,2]*cos(ang)
    return(invisible(cbind(xrot,yrot)))
}
坐标变换:笛卡尔平面旋转
谢谢你。通过旋转矩阵获得坐标非常有用。现在我需要得到线…好的,一旦你有了坐标,大概是成对的,例如第一行是
rotatedpairs[1:2,]
,第二行是
rotatedpairs[3:4,]
,应该很容易写一个循环来绘制所有的线。非常感谢。通过旋转矩阵获得坐标非常有用。现在我需要得到这些线……好吧,一旦你有了坐标,大概是成对的,例如第一行是
rotatedpairs[1:2,]
,第二行是
rotatedpairs[3:4,]
,写一个循环来绘制所有的线应该很容易。
plot(rot90)
segments(rot90[1,1], rot90[1,2], rot90[2,1], rot90[2,2])
# coordinate transform: cartesian plane rotation
xyrot<-function(pairs,ang){
    # pairs must be Nx2 matrix w/ x in first column and y in second
    xrot <- pairs[,1]*cos(ang) - pairs[,2]*sin(ang)
    yrot <- pairs[,1]*sin(ang) + pairs[,2]*cos(ang)
    return(invisible(cbind(xrot,yrot)))
}