https://github.com/atedja/go-vector
Simple Vector math library
https://github.com/atedja/go-vector
go golang simple vector vector-math
Last synced: 17 days ago
JSON representation
Simple Vector math library
- Host: GitHub
- URL: https://github.com/atedja/go-vector
- Owner: atedja
- License: other
- Created: 2017-03-07T07:30:02.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-18T03:08:44.000Z (almost 9 years ago)
- Last Synced: 2024-06-19T06:46:44.183Z (over 1 year ago)
- Topics: go, golang, simple, vector, vector-math
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Vector
[](https://travis-ci.org/atedja/go-vector)
Simple N-dimensional Vector math library. Uses standard `[]float64` type.
### Quick Example
```go
package main
import (
"fmt"
"github.com/atedja/go-vector"
)
func main() {
v1 := vector.New(4)
v2 := vector.NewWithValues([]float64{0.0, 1.0, 2.0, 3.0})
result := vector.Add(v1, v2)
}
```
#### [Full API Documentation](https://godoc.org/github.com/atedja/go-vector)
### Basic Usage
#### Creating Vectors
var v vector.Vector
v = vector.New(3)
v = vector.NewWithValues([]float64{0.0, 1.0, 2.0})
#### Scale Vectors
v.Scale(2.0)
#### Dot and Cross Products
v1 := vector.NewWithValues([]float64{0.0, 1.0, 2.0})
v2 := vector.NewWithValues([]float64{2.0, -1.0, 4.0})
cross, _ := vector.Cross(v1, v2)
dot, _ := vector.Dot(v1, v2)
In general, all functions under `vector` package are designed to always return a new result without modifying the vectors
in the arguments, while functions under the `vector.Vector` type will modify the vector.
#### And more!
`Add`, `Subtract`, `Scale`, `Resize`, `Zero`, `Magnitude`, `Unit`, `Hadamard`