不记得从学校使用的数学,但是,我想旋转一个点围绕原点使用Go/Golang。
下面的基本思想是,x,y是原点(中心),x2,y2是圆周上的点。我想让x2,y2在x,y上连续旋转360度。
x:= 10 // center x
y:= 10 // center y
x2 := 20 // rotating point x
y2 := 20 // rotating point y
xchange := ??? What math to use to calculate the change in x
ychange := ??? What math to use to calculate the change in y任何帮助都将不胜感激。
发布于 2022-05-29 18:12:06
你可以用半径为r的圆周轨道(x0,y0)参数化
x(t) = x0 + r cos(t)
y(t) = y0 + r sin(t)你可以根据你开始的两点算出r。从这里开始,它只是一个平稳增长的问题,以模拟时间的进展。
发布于 2022-05-30 05:48:16
围绕任意中心旋转:
(0,0)
示例代码:
// translate center of rotation to (0,0)
dx := x_in - x_center
dy := y_in - y_center
// rotate about (0,0)
c := math.Cos(angle)
s := math.Sin(angle)
rotx := dx * c - dy * s
roty := dx * s + dy * c
// translate (0,0) back to center of rotation
x_out := rotx + x_center
y_out := roty + y_centerhttps://stackoverflow.com/questions/72426109
复制相似问题