58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
|
package solaranalyzer
|
|||
|
|
|||
|
import (
|
|||
|
"math"
|
|||
|
|
|||
|
"github.com/tomchavakis/geojson/geometry"
|
|||
|
)
|
|||
|
|
|||
|
const (
|
|||
|
earthRadius = 6371000 // 地球半径(米)
|
|||
|
|
|||
|
radiusMeters = 0.07 // 半径(7厘米)
|
|||
|
|
|||
|
numPoints = 8 // 点的数量
|
|||
|
)
|
|||
|
|
|||
|
type GeoPoint struct {
|
|||
|
ID int
|
|||
|
Coordinates Coordinates
|
|||
|
}
|
|||
|
|
|||
|
type Coordinates struct {
|
|||
|
Lng float64
|
|||
|
Lat float64
|
|||
|
Alt float64
|
|||
|
}
|
|||
|
|
|||
|
// ExpandToCircle 用于桩点和支架
|
|||
|
// 以一个点为中心,扩展出一个圆形
|
|||
|
func (p Coordinates) ExpandToCircle() geometry.Polygon {
|
|||
|
circle := make([]Coordinates, numPoints)
|
|||
|
|
|||
|
for i := 0; i < numPoints; i++ {
|
|||
|
angle := 2 * math.Pi * float64(i) / float64(numPoints)
|
|||
|
|
|||
|
// 计算偏移量(米)
|
|||
|
dx := radiusMeters * math.Cos(angle)
|
|||
|
dy := radiusMeters * math.Sin(angle)
|
|||
|
|
|||
|
// 将米转换为经纬度
|
|||
|
dLng := dx / (earthRadius * math.Cos(p.Lat*math.Pi/180)) * 180 / math.Pi
|
|||
|
dLat := dy / earthRadius * 180 / math.Pi
|
|||
|
|
|||
|
circle[i] = Coordinates{
|
|||
|
Lng: p.Lng + dLng,
|
|||
|
Lat: p.Lat + dLat,
|
|||
|
Alt: p.Alt,
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var coords []geometry.Point
|
|||
|
for _, point := range circle {
|
|||
|
coords = append(coords, geometry.Point{Lat: point.Lat, Lng: point.Lng})
|
|||
|
}
|
|||
|
|
|||
|
return geometry.Polygon{Coordinates: []geometry.LineString{{Coordinates: coords}}}
|
|||
|
}
|