1 前言
略,作为记录使用
2 代码
/** * @Author: FB * @Description: * @File: RotateSample.go * @Version: 1.0.0 * @Date: 2019/9/5 16:23 */ package main import ( "math" "strconv" "fmt" "log" ) func main() { Angle := 90.0 H := 100.0 W := 200.0 L := 0.0 T := 0.0 x,y := GetOffsetXYAfterRotationForSVG(W, H, L, T, Angle) fmt.Println("x,y=",x,y) } func GetOffsetXYAfterRotationForSVG(W, H, L, T, Angle float64) (x, y float64) { if Angle <= 0.0 { return L, T } if Angle > 90 && Angle <= 180 { Angle = 180 - Angle } else if Angle > 180 && Angle <= 270 { Angle = 270 - Angle } else if Angle > 270 && Angle <= 360 { Angle = 360 - Angle } else if Angle <= 0 { log.Println("Exception-> Angle < 0") //Angle = 360 + Angle } else { //0<Angle<=90 } R := math.Sqrt(math.Pow(W, 2)+math.Pow(H, 2)) / 2 AngleRadBeta := math.Atan(H / W) AngleBeta := AngleRadBeta * 180 / math.Pi fmt.Println("Angle,H,W,L,T,ZHalf,AngleBeta=", Angle, H, W, L, T, R, AngleBeta) //开始计算,在以对角线一半为半径画圆,初始化角度为Anglebeta A1 := Angle + AngleBeta A2 := 90 + Angle - AngleBeta //A3 := AngleBeta - Angle AngleRad1 := A1 * math.Pi / 180 AngleRad2 := A2 * math.Pi / 180 //AngleRad3 := A3 * math.Pi / 180 SinA1 := math.Sin(AngleRad1) SinA2 := math.Sin(AngleRad2) //CosA3 := math.Cos(AngleRad3) //fmt.Println("sin1,sin2,cos3=",SinA1,SinA2,CosA3) X := -R * SinA2 Y := -R * SinA1 fmt.Println("X,Y=", X, Y) x = L + DecimalPrec(X+W/2, 3) y = T + DecimalPrec(Y+H/2, 3) return x, y } func DecimalPrec(value float64, prec int) float64 { value, _ = strconv.ParseFloat(fmt.Sprintf("%."+strconv.Itoa(prec)+"f", value), 64) return value }
3 图片
说明:偏移量为P到P°的偏移量