1 前言
图片按中心旋转后,新图的左顶点位置的偏移量
2 代码
func OffsetXYAfterRotationCore(W, H, L, T, Angle float64) (x, y float64) { var DX, DY, X, Y float64 AngleRad := Angle * math.Pi / 180 SinX := math.Sin(AngleRad) CosX := math.Cos(AngleRad) //0<=Angle <=90 if Angle >= 0 && Angle <= 90 { DX = SinX * H DY = 0 X = L - DX Y = T - DY //fmt.Println("At last Angle,X,Y,DX,DY=", Angle, X, Y, DX, DY) } else if Angle > 90 && Angle <= 180 { //90<=Angle <=180 //SinX2 := math.Sin((180 - Angle) ) //CosX2 := math.Cos((180 - Angle) ) SinX2 := SinX CosX2 := -CosX DX = SinX2*H + W*CosX2 DY = H * CosX2 X = L - DX Y = T - DY //fmt.Println("At last Angle,X,Y,DX,DY=", Angle, X, Y, DX, DY) } else if Angle > 180 && Angle <= 270 { //SinX2 := math.Sin((270 - Angle)) //CosX2 := math.Cos((270 - Angle)) SinX2 := -CosX CosX2 := -SinX DX = SinX2 * W DY = CosX2*W + SinX2*H X = L - DX Y = T - DY //fmt.Println("At last Angle,X,Y,DX,DY=", Angle, X, Y, DX, DY) } else { //SinX2 := math.Sin((360 - Angle)) SinX2 := -SinX DX = 0 DY = SinX2 * W X = L - DX Y = T - DY //fmt.Println("At last Angle,X,Y,DX,DY=", Angle, X, Y, DX, DY) } x = X y = Y return }
3 效果图
1981x325
1878x1272