zworld-demo/plugin/math/shape/sphere.go
2023-12-22 22:04:27 +08:00

16 lines
316 B
Go

package shape
import "zworld/plugin/math/vec3"
type Sphere struct {
Center vec3.T
Radius float32
}
func (s *Sphere) IntersectsSphere(other *Sphere) bool {
sepAxis := s.Center.Sub(other.Center)
radiiSum := s.Radius + other.Radius
intersects := sepAxis.LengthSqr() < (radiiSum * radiiSum)
return intersects
}