tuple

package
v0.0.0-...-8dd99ce Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package tuple implements points and vectors as a 4-tuple.

Using a common representation for both types allows for simpler computations Use of homogeneous coordinates. See https://en.wikipedia.org/wiki/Homogeneous_coordinates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dot

func Dot(a, b Tuple) float64

Dot returns the dot-product of two vectors. Passing a point to Dot is undefined.

func Equal

func Equal(a, b Tuple) bool

Equal returns true if two Tuples are equal.

func Mag

func Mag(vec Tuple) float64

Mag calculates the magnitude of a vector. Passing a point to Mag is undefined result.

Types

type Tuple

type Tuple struct {
	X, Y, Z float64
	// contains filtered or unexported fields
}

Tuple implements points and vectors using a common struct.

func Add

func Add(a, b Tuple) Tuple

Add calculates the component-wise sum of two Tuples.

func Cross

func Cross(a, b Tuple) Tuple

Cross returns the cross-product of two vectors. Passing a point to Cross is undefined.

func Div

func Div(t Tuple, scalar float64) Tuple

Div calculates the component-wise quotient of a Tuple and a scalar.

func Mult

func Mult(t Tuple, scalar float64) Tuple

Mult calculates the component-wise product of a Tuple and a scalar.

func Neg

func Neg(t Tuple) Tuple

Neg calculates the component-wise negation of a Tuple.

func New

func New(x, y, z, w float64) Tuple

New creates a new 4-tuple. It is recommended to use Vector and Point rather than using New directly.

func Norm

func Norm(vec Tuple) Tuple

Norm returns a new vector which is the norm of vec. Passing a point to Norm is undefined.

func Point

func Point(x, y, z float64) Tuple

Point creates a new point at (x,y,z).

func Reflect

func Reflect(in, norm Tuple) Tuple

Reflect returns the reflection of vector in along vector norm.

func Sub

func Sub(a, b Tuple) Tuple

Sub calculates the component-wise difference of two Tuples.

func Vector

func Vector(x, y, z float64) Tuple

Vector creates a new vector starting at the origin and ending at (x,y,z).

func (Tuple) Add

func (t1 Tuple) Add(t2 Tuple) Tuple

Add calculates the component-wise sum of two Tuples.

func (Tuple) IsPoint

func (t Tuple) IsPoint() bool

IsPoint returns true if a tuple is a point.

func (Tuple) IsVector

func (t Tuple) IsVector() bool

IsVector returns true if a given Tuple is a vector.

func (Tuple) Sub

func (t1 Tuple) Sub(t2 Tuple) Tuple

Sub calculates the component-wise difference of two Tuples.

func (Tuple) W

func (t Tuple) W() float64

W returns the w component of the Tuple. A w value of 0 represents a vector and a value of 1 represents a point.

Jump to

Keyboard shortcuts

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