mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 23:26:52 +08:00
spatial/barneshut: add Barnes-Hut force approximation package and R2/R3 helpers
This commit is contained in:
39
spatial/r3/vector.go
Normal file
39
spatial/r3/vector.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright ©2019 The Gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package r3
|
||||
|
||||
// Vec is a 3D vector.
|
||||
type Vec struct {
|
||||
X, Y, Z float64
|
||||
}
|
||||
|
||||
// Add returns the vector sum of p and q.
|
||||
func (p Vec) Add(q Vec) Vec {
|
||||
p.X += q.X
|
||||
p.Y += q.Y
|
||||
p.Z += q.Z
|
||||
return p
|
||||
}
|
||||
|
||||
// Sub returns the vector sum of p and -q.
|
||||
func (p Vec) Sub(q Vec) Vec {
|
||||
p.X -= q.X
|
||||
p.Y -= q.Y
|
||||
p.Z -= q.Z
|
||||
return p
|
||||
}
|
||||
|
||||
// Scale returns the vector p scaled by f.
|
||||
func (p Vec) Scale(f float64) Vec {
|
||||
p.X *= f
|
||||
p.Y *= f
|
||||
p.Z *= f
|
||||
return p
|
||||
}
|
||||
|
||||
// Box is a 3D bounding box.
|
||||
type Box struct {
|
||||
Min, Max Vec
|
||||
}
|
Reference in New Issue
Block a user