vec

package
v0.0.0-...-afa3bba Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: Unlicense Imports: 2 Imported by: 0

Documentation

Overview

Package vec contains basic vector math operations.

Index

Constants

This section is empty.

Variables

View Source
var I = Vec{1, 0, 0}

I is the unit vector on the x axis. Treat it as a const!

View Source
var J = Vec{0, 1, 0}

J is the unit vector on the y axis. Treat it as a const!

View Source
var K = Vec{0, 0, 1}

K is the unit vector on the z axis. Treat it as a const!

View Source
var Origin = Vec{0, 0, 0}

Origin is the point representing the zeo origin in 3D space. Treat it as a const!

Functions

func ToDegrees

func ToDegrees(rad float64) float64

ToDegrees converts from degrees to radians 2*pi radians = 360 degrees

func ToRadians

func ToRadians(deg float64) float64

ToRadians converts from radians to degrees 2*pi radians = 360 degrees

Types

type Vec

type Vec struct {
	X float64
	Y float64
	Z float64
}

Vec is a 3 dimensional vector. It's represented as a point relative to the origin So we also use Vec as if they were points. But it's implementation should be considered as private

func Newc

func Newc(x, y, z float64) Vec

Newc creates new Vec vector from a set of x, y, z coordinates

func Newd

func Newd(m, th, ph float64) Vec

Newd creates new Vec vector from a magnitude and the direction angles m is the magnitude of the new vector, th is theta the angle from the x axis in the xy plane ph is phi the angle fron the xy plane toward the z axis.

func Newp

func Newp(p1, p2 Vec) Vec

Newp creates a new Vec vector from 2 points. The Vec represents the distance and angle from p1 to p1

func Newv

func Newv(v Vec) Vec

Newv creates new Vec vector from an existing Vec

func (Vec) AsSpherical

func (v Vec) AsSpherical() (m float64, theta float64, phi float64)

AsSpherical returns the spherical coordinates of a Point returning length, theta, phi where theta is the angle from the the x axis in the xy plane and phi is the angle from the xy plane toward the z axis.

func (Vec) Cross

func (v Vec) Cross(w Vec) Vec

Cross performs the cross product u X v

func (Vec) Distance

func (v Vec) Distance(v2 Vec) float64

Distance returns the distance between 2 points in space

func (Vec) Dot

func (v Vec) Dot(b Vec) float64

Dot performs the dot product a.b

func (Vec) Info

func (v Vec) Info(str string)

Info prints a bunch of info for debugging purposes

func (Vec) Length

func (v Vec) Length() float64

Length returns the magnitude of a Vec, or the distance of a Vec from the Origin

func (Vec) Minus

func (v Vec) Minus(v2 Vec) Vec

Minus subtracts a Vec from the receiver Vec and returns a new Vec This is also vector subtraction

func (Vec) Mul

func (v Vec) Mul(x float64) Vec

Mul performs a scaler multiplation.

func (Vec) Plus

func (v Vec) Plus(v2 Vec) Vec

Plus adds a Vec to the receiver Vec and returns a new Vec This is also vector addition

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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