-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsphere.go
More file actions
34 lines (26 loc) · 767 Bytes
/
sphere.go
File metadata and controls
34 lines (26 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package math
type Sphere struct {
Center Vector3
Radius float32
}
func NewDefaultSphere() *Sphere {
return NewSphere(NewDefaultVector3(), 1)
}
func NewSphere(vector *Vector3, radius float32) *Sphere {
return &Sphere{
Center: Vector3{Vector2: Vector2{X: vector.X, Y: vector.Y}, Z: vector.Z},
Radius: radius,
}
}
func (sphere *Sphere) SetFromPoints(points []*Vector3) {
box := NewBox3FromPoints(points)
sphere.SetFromPointsAndCenter(points, box.GetCenter())
}
func (sphere *Sphere) SetFromPointsAndCenter(points []*Vector3, center *Vector3) {
sphere.Center.Copy(center)
var maxRadiusSq = float32(0)
for i := 0; i < len(points); i++ {
maxRadiusSq = Max(maxRadiusSq, center.GetDistanceToSquared(points[i]))
}
sphere.Radius = Sqrt(maxRadiusSq)
}