vec3

package module
v0.0.0-...-ae29446 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2019 License: MIT Imports: 3 Imported by: 0

README

vector

Module to describe a three dimensional vector

Installation

To install it, run:

go get github.com/aitorfernandez/vector

Tests

To run it:

go test

Example

package main

import (
  "fmt"

  vector "github.com/aitorfernandez/vector"
)

func main() {
  v := vector.Vec3{X: 1, Y: 2, Z: 3}
  fmt.Println(v.ToString()) // Vec3 struct: 1.00, 2.00, 3.00

  // methods

  v.Add(3)
  fmt.Println(v.ToString()) // Vec3 struct: 4.00, 2.00, 3.00
  // or
  v.Add(vector.Vec3{X: 4, Y: 5, Z: 6})
  fmt.Println(v.ToString()) // Vec3 struct: 8.00, 7.00, 9.00

  v.Sub(2, 2)
  fmt.Println(v.ToString()) // Vec3 struct: 6.00, 5.00, 9.00
  // or
  v.Sub(vector.Vec3{X: 1, Y: 1, Z: 1})
  fmt.Println(v.ToString()) // Vec3 struct: 5.00, 4.00, 8.00

  v.Mult(3)
  fmt.Println(v.ToString()) // Vec3 struct: 15.00, 12.00, 24.00

  v.Div(2)
  fmt.Println(v.ToString()) // Vec3 struct: 7.50, 6.00, 12.00

  mag := v.Magnitude()
  fmt.Println(mag) // 15.370426148939398

  v.Normalize()
  fmt.Println(v.ToString()) // Vec3 struct: 0.49, 0.39, 0.78
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Vec3

type Vec3 struct {
	X, Y, Z float64
}

func (*Vec3) Add

func (v *Vec3) Add(a ...interface{})

Add x, y, and z from a vector

func (*Vec3) Div

func (v *Vec3) Div(n float64)

Div the vector

func (*Vec3) Magnitude

func (v *Vec3) Magnitude() float64

Magnitude calculates the length of the vector

func (*Vec3) Mult

func (v *Vec3) Mult(n float64)

Mult the vector

func (*Vec3) Normalize

func (v *Vec3) Normalize()

Normalize the vector to length 1

func (*Vec3) Sub

func (v *Vec3) Sub(a ...interface{})

Sub x, y, and z from a vector

func (*Vec3) ToString

func (v *Vec3) ToString() string

ToString returns a string representation of a vector

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL