math3d

package
v0.0.0-...-cec5250 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2017 License: Apache-2.0 Imports: 2 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UnitX is the unit vector in the X axis
	UnitX = Vector3{X: 1.0, Y: 0.0, Z: 0.0}
	// UnitY is the unit vector in the Y axis
	UnitY = Vector3{X: 0.0, Y: 1.0, Z: 0.0}
	// UnitZ is the unit vector in the Z axis
	UnitZ = Vector3{X: 0.0, Y: 0.0, Z: 1.0}
)

Functions

func Clamp

func Clamp(value float64, min float64, max float64) float64

Clamp limits the value to the min and max specified

func DiscardIfTooClose

func DiscardIfTooClose(t float64) float64

DiscardIfTooClose returns t if t is greater than a threshold. Otherwise, it returns math.MaxFloat64

func Distance

func Distance(pointA *Vector3, pointB *Vector3) float64

Distance returns the distance from pointA to pointB.

func GetNearestInFront

func GetNearestInFront(t1 float64, t2 float64) float64

GetNearestInFront returns the minimum of t1 and t2 so long as it is greater than a threshold. If neither is, it returns math.MaxFloat64

Types

type LightRay

type LightRay struct {
	Source    Vector3
	Direction Vector3
}

LightRay defines a ray of light that can be traced against a scene

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

Matrix represents a 4x4 matrix

func (*Matrix) ComposeMatrix

func (mat *Matrix) ComposeMatrix(mat2 *Matrix) *Matrix

ComposeMatrix composes the two matrices multiplying them

func (*Matrix) MultiplyPoint

func (mat *Matrix) MultiplyPoint(point *Vector3) *Vector3

MultiplyPoint returns point multiplied by the matrix

func (*Matrix) MultiplyVector

func (mat *Matrix) MultiplyVector(vector *Vector3) *Vector3

MultiplyVector returns vector multiplied by the matrix

type Vector3

type Vector3 struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	Z float64 `json:"z"`
}

Vector3 holds three floats that represent X Y and Z space. It holds both 3D vectors and 3D points.

func Subtract

func Subtract(pointA *Vector3, pointB *Vector3) *Vector3

Subtract returns the vector that goes from pointA to pointB.

func VectorFromMap

func VectorFromMap(m map[string]interface{}) Vector3

VectorFromMap returns the vector defined in the map

func (*Vector3) Abs

func (v *Vector3) Abs() float64

Abs returns the distance from the origin

func (*Vector3) Add

func (v *Vector3) Add(v2 *Vector3) *Vector3

Add returns the result of adding two vectors

func (*Vector3) AsMap

func (v *Vector3) AsMap() map[string]float64

AsMap returns a map representation of the vector

func (*Vector3) Cross

func (v *Vector3) Cross(v2 *Vector3) *Vector3

Cross returns the cross product of the 3D vectors

func (*Vector3) Differ

func (v *Vector3) Differ(v2 *Vector3) bool

Differ returns true if the vectors are not the same within a margin of error.

func (*Vector3) Divide

func (v *Vector3) Divide(k float64) *Vector3

Divide returns a vector result of dividing all the values in the vector by k

func (*Vector3) Dot

func (v *Vector3) Dot(v2 *Vector3) float64

Dot returns the dot product of the 3D vectors

func (*Vector3) Equal

func (v *Vector3) Equal(v2 *Vector3) bool

Equal returns true if both vectors are the same within a margin of error

func (*Vector3) GreaterOrEqual

func (v *Vector3) GreaterOrEqual(v2 *Vector3) bool

GreaterOrEqual returns true if the first vector is greater or equal in the three axes.

func (*Vector3) LesserOrEqual

func (v *Vector3) LesserOrEqual(v2 *Vector3) bool

LesserOrEqual returns true if the first vector is smaller or equal in the three axes.

func (*Vector3) Multiply

func (v *Vector3) Multiply(k float64) *Vector3

Multiply returns a vector result of multiplying all the values in the vector by k

func (*Vector3) Normalized

func (v *Vector3) Normalized() *Vector3

Normalized returns the normalized 3D vector

func (*Vector3) Print

func (v *Vector3) Print()

Print the values in the 3D vector

func (*Vector3) Reflect

func (v *Vector3) Reflect(normal *Vector3) *Vector3

Reflect returns the vector reflected off the surface with the given normal

func (*Vector3) String

func (v *Vector3) String() string

func (*Vector3) Subtract

func (v *Vector3) Subtract(v2 *Vector3) *Vector3

Subtract returns the result of subtracting two vectors

Jump to

Keyboard shortcuts

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