Library for work with vectors.
Methods you can use:
First get the package:
$ go get github.com/janczer/vector
Now you can add this library to import
and use it:
package main
import (
"fmt"
"github.com/janczer/vector"
)
func main() {
v := vector.New([]float64{1, 2, 3})
v2 := vector.New([]float64{1, 2, 4})
fmt.Println(v.Print()) //Vector: 1, 2, 3
fmt.Println(v.Eq(v2)) //false
}
Method return true
if vectors are equal:
v := vector.New([]float64{1, 2, 3})
v2 := vector.New([]float64{1, 2, 3})
fmt.Println(v.Eq(v2)) //true
This method add coordinates of two vectors, and return new Vector
:
v := vector.New([]float64{1, 2, 4})
v2 := vector.New([]float64{1, 1, 3})
v3 := v.Add(v2) //1+1, 2+1, 4+3
Method subtract coordinates of two vectors, and return new Vector
:
v := vector.New([]float64{1, 2, 4})
v2 := vector.New([]float64{1, 1, 3})
v3 := v.Sub(v2) //1-1, 2-1, 4-3
Method multiply coordinates of two vectors, and return new Vector
:
v := vector.New([]float64{1, 2, 4})
v2 := vector.New([]float64{1, 1, 3})
v3 := v.Dot(v2) //1, 2, 12
Method multiply each coordinate by number:
v := vector.New([]float64{1, 2, 4})
v2 := v.Scalar(3) //3, 6, 12
Method return magnitude of vector:
v := vector.New([]float64{1, 2, 4})
m := v.Magnitude() //4,5825..
Method return new unit vector:
v := vector.New([]float64{1, 2, 4})
m := v.Normalize() // 1/4,5825, 2/4.5825, 4/4.5825
Method return angle between two vectors:
v := vector.New([]float64{3, 0})
v2 := vector.New([]float64{0, 3})
a := v.Angle(v2, true) // 45
Method return true
if two vectors are paraller:
v := vector.New([]float64{3, 0})
v2 := vector.New([]float64{0, 3})
a := v.Paraller(v2) // false
Method return true
if two vectors are orthogonal:
v := vector.New([]float64{3, 0})
v2 := vector.New([]float64{0, 3})
a := v.Orthogonal(v2) // true