math32

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: BSD-3-Clause Imports: 15 Imported by: 92

README

math32

math32 is a float32 based vector, matrix, and math package for 2D & 3D graphics, based on the G3N math32 package, but using a value-based design instead of pointer-based, which simplifies chained expressions of multiple operators.

The go-gl/mathgl package is also comparable, which in turn is based on image/math/f32 types, which use arrays instead of structs with named X, Y, Z components. The named components make things easier to read overall. The G3N and this package support a much more complete set of vector and matrix math, covering almost everything you might need, including aggregate types such as triangles, planes, etc.

This package also includes the Matrix type from fogleman/gg (as Mat2) for 2D graphics; this also includes additional support for SVG-style configuring of a matrix, in the SetString method.

Value-based Vectors

The use of value-based methods means that vectors are passed and returned as values instead of pointers:

So, in this math32 package, Add looks like this:

// Add adds other vector to this one and returns result in a new vector.
func (v Vector3) Add(other Vector3) Vector3 {
	return V3(v.X + other.X, v.Y + other.Y, v.Z + other.Z)
}

versus G3N:

// Add adds other vector to this one.
// Returns the pointer to this updated vector.
func (v *Vector3) Add(other *Vector3) *Vector3 {
	v.X += other.X
	v.Y += other.Y
	v.Z += other.Z
	return v
}

The value-based design allows you to just string together sequences of expressions naturally, without worrying about allocating intermediate variables:

// Normal returns the triangle's normal.
func Normal(a, b, c Vector3) Vector3 {
	nv := c.Sub(b).Cross(a.Sub(b))
   ...
}

There may be a small performance cost for the value-based approach (comparative benchmarks have not yet been run), but the overall simplicity advantages are significant.

The matrix types still do use pointer-based logic because they are significantly larger and thus the performance issues are likely to be more important.

Struct vs. Array Performance: Struct is much faster

This is a benchmark from Egon Elbre, showing that small arrays can be significantly slower than a struct: https://github.com/egonelbre/exp/blob/master/bench/vector_fusing/vector_test.go

# array
BenchmarkAddMul-32                      70589480                17.3 ns/op
# struct
BenchmarkStructAddMul-32                1000000000               0.740 ns/op

Discussion: https://github.com/golang/go/issues/15925

Documentation

Overview

math32 is our version of the G3N math32 32-bit, 3D rendering-based math library.

Initially copied from G3N: github.com/g3n/engine/math32 Copyright 2016 The G3N Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

A major modification from the G3N version is to use value-based logic instead of pointer-based self-modification in the Vector classes, As used in e.g., go-gl/mathgl (which uses slice-based vectors instead of the more intuitive and likely more efficient struct-based ones here).

The pointer-based approach was retained for the Matrix classes, which are larger and that is likely more performant.

Many names were shortened, consistent with more idiomatic Go naming. and again with the go-gl/mathgl library

Package math32 is a float32 based vector, matrix, and math package for 2D & 3D graphics.

Index

Constants

View Source
const (
	E   = math.E
	Pi  = math.Pi
	Phi = math.Phi

	Sqrt2   = math.Sqrt2
	SqrtE   = math.SqrtE
	SqrtPi  = math.SqrtPi
	SqrtPhi = math.SqrtPhi

	Ln2    = math.Ln2
	Log2E  = math.Log2E
	Ln10   = math.Ln10
	Log10E = math.Log10E
)

Mathematical constants.

View Source
const (
	MaxFloat32             = math.MaxFloat32
	SmallestNonzeroFloat32 = math.SmallestNonzeroFloat32
)

Floating-point limit values. Max is the largest finite value representable by the type. SmallestNonzero is the smallest positive, non-zero value representable by the type.

View Source
const (
	// DegToRadFactor is the number of radians per degree.
	DegToRadFactor = Pi / 180

	// RadToDegFactor is the number of degrees per radian.
	RadToDegFactor = 180 / Pi
)

Variables

View Source
var Infinity = float32(math.Inf(1))

Infinity is positive infinity.

Functions

func Abs

func Abs(x float32) float32

Abs returns the absolute value of x.

Special cases are:

Abs(±Inf) = +Inf
Abs(NaN) = NaN

func Acos

func Acos(x float32) float32

Acos returns the arccosine, in radians, of x.

Special case is:

Acos(x) = NaN if x < -1 or x > 1

func Acosh

func Acosh(x float32) float32

Acosh returns the inverse hyperbolic cosine of x.

Special cases are:

Acosh(+Inf) = +Inf
Acosh(x) = NaN if x < 1
Acosh(NaN) = NaN

func Asin

func Asin(x float32) float32

Asin returns the arcsine, in radians, of x.

Special cases are:

Asin(±0) = ±0
Asin(x) = NaN if x < -1 or x > 1

func Asinh

func Asinh(x float32) float32

Asinh returns the inverse hyperbolic sine of x.

Special cases are:

Asinh(±0) = ±0
Asinh(±Inf) = ±Inf
Asinh(NaN) = NaN

func Atan

func Atan(x float32) float32

Atan returns the arctangent, in radians, of x.

Special cases are:

Atan(±0) = ±0
Atan(±Inf) = ±Pi/2

func Atan2

func Atan2(y, x float32) float32

Atan2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value. Special cases are (in order):

Atan2(y, NaN) = NaN
Atan2(NaN, x) = NaN
Atan2(+0, x>=0) = +0
Atan2(-0, x>=0) = -0
Atan2(+0, x<=-0) = +Pi
Atan2(-0, x<=-0) = -Pi
Atan2(y>0, 0) = +Pi/2
Atan2(y<0, 0) = -Pi/2
Atan2(+Inf, +Inf) = +Pi/4
Atan2(-Inf, +Inf) = -Pi/4
Atan2(+Inf, -Inf) = 3Pi/4
Atan2(-Inf, -Inf) = -3Pi/4
Atan2(y, +Inf) = 0
Atan2(y>0, -Inf) = +Pi
Atan2(y<0, -Inf) = -Pi
Atan2(+Inf, x) = +Pi/2
Atan2(-Inf, x) = -Pi/2

func Atanh

func Atanh(x float32) float32

Atanh returns the inverse hyperbolic tangent of x.

Special cases are:

Atanh(1) = +Inf
Atanh(±0) = ±0
Atanh(-1) = -Inf
Atanh(x) = NaN if x < -1 or x > 1
Atanh(NaN) = NaN

func Cbrt

func Cbrt(x float32) float32

Cbrt returns the cube root of x.

Special cases are:

Cbrt(±0) = ±0
Cbrt(±Inf) = ±Inf
Cbrt(NaN) = NaN

func Ceil

func Ceil(x float32) float32

Ceil returns the least integer value greater than or equal to x.

Special cases are:

Ceil(±0) = ±0
Ceil(±Inf) = ±Inf
Ceil(NaN) = NaN

func Clamp

func Clamp(x, a, b float32) float32

Clamp clamps x to the provided closed interval [a, b]

func ClampInt

func ClampInt(x, a, b int) int

ClampInt clamps x to the provided closed interval [a, b]

func ContainsPoint

func ContainsPoint(point, a, b, c Vector3) bool

ContainsPoint returns whether a triangle contains a point.

func CopyFloat32s

func CopyFloat32s(trg *[]float32, src []float32)

CopyFloat32s copies a []float32 slice from src into target, ensuring that the target is the correct size.

func CopyFloat64s

func CopyFloat64s(trg *[]float64, src []float64)

CopyFloat64s copies a []float64 slice from src into target, ensuring that the target is the correct size.

func Copysign

func Copysign(f, sign float32) float32

Copysign returns a value with the magnitude of f and the sign of sign.

func Cos

func Cos(x float32) float32

Cos returns the cosine of the radian argument x.

Special cases are:

Cos(±Inf) = NaN
Cos(NaN) = NaN

func Cosh

func Cosh(x float32) float32

Cosh returns the hyperbolic cosine of x.

Special cases are:

Cosh(±0) = 1
Cosh(±Inf) = +Inf
Cosh(NaN) = NaN

func DegToRad

func DegToRad(degrees float32) float32

DegToRad converts a number from degrees to radians

func Dim

func Dim(x, y float32) float32

Dim returns the maximum of x-y or 0.

Special cases are:

Dim(+Inf, +Inf) = NaN
Dim(-Inf, -Inf) = NaN
Dim(x, NaN) = Dim(NaN, x) = NaN

func Erf

func Erf(x float32) float32

Erf returns the error function of x.

Special cases are:

Erf(+Inf) = 1
Erf(-Inf) = -1
Erf(NaN) = NaN

func Erfc

func Erfc(x float32) float32

Erfc returns the complementary error function of x.

Special cases are:

Erfc(+Inf) = 0
Erfc(-Inf) = 2
Erfc(NaN) = NaN

func Erfcinv

func Erfcinv(x float32) float32

Erfcinv returns the inverse of Erfc(x).

Special cases are:

Erfcinv(0) = +Inf
Erfcinv(2) = -Inf
Erfcinv(x) = NaN if x < 0 or x > 2
Erfcinv(NaN) = NaN

func Erfinv

func Erfinv(x float32) float32

Erfinv returns the inverse error function of x.

Special cases are:

Erfinv(1) = +Inf
Erfinv(-1) = -Inf
Erfinv(x) = NaN if x < -1 or x > 1
Erfinv(NaN) = NaN

func Exp

func Exp(x float32) float32

Exp returns e**x, the base-e exponential of x.

Special cases are:

Exp(+Inf) = +Inf
Exp(NaN) = NaN

Very large values overflow to 0 or +Inf. Very small values underflow to 1.

func Exp2

func Exp2(x float32) float32

Exp2 returns 2**x, the base-2 exponential of x.

Special cases are the same as Exp.

func Expm1

func Expm1(x float32) float32

Expm1 returns e**x - 1, the base-e exponential of x minus 1. It is more accurate than Exp(x) - 1 when x is near zero.

Special cases are:

Expm1(+Inf) = +Inf
Expm1(-Inf) = -1
Expm1(NaN) = NaN

Very large values overflow to -1 or +Inf.

func FMA

func FMA(x, y, z float32) float32

FMA returns x * y + z, computed with only one rounding. (That is, FMA returns the fused multiply add of x, y, and z.)

func FastExp

func FastExp(x float32) float32

FastExp is a quartic spline approximation to the Exp function, by N.N. Schraudolph It does not have any of the sanity checking of a standard method -- returns nonsense when arg is out of range. Runs in 2.23ns vs. 6.3ns for 64bit which is faster than math32.Exp actually.

func FitGeomInWindow

func FitGeomInWindow(stPos, stSz, winPos, winSz int) (pos, sz int)

FitGeomInWindow returns a position and size for a region (sub-window) within a larger window geom (pos and size) that fits entirely within that window to the extent possible, given an initial starting position and size. The position is first adjusted to try to fit the size, and then the size is adjusted to make it fit if it is still too big.

func Floor

func Floor(x float32) float32

Floor returns the greatest integer value less than or equal to x.

Special cases are:

Floor(±0) = ±0
Floor(±Inf) = ±Inf
Floor(NaN) = NaN

func Frexp

func Frexp(f float32) (frac float32, exp int)

Frexp breaks f into a normalized fraction and an integral power of two. It returns frac and exp satisfying f == frac × 2**exp, with the absolute value of frac in the interval [½, 1).

Special cases are:

Frexp(±0) = ±0, 0
Frexp(±Inf) = ±Inf, 0
Frexp(NaN) = NaN, 0

func FromFixed

func FromFixed(x fixed.Int26_6) float32

FromFixed converts a fixed.Int26_6 to a float32

func Gamma

func Gamma(x float32) float32

Gamma returns the Gamma function of x.

Special cases are:

Gamma(+Inf) = +Inf
Gamma(+0) = +Inf
Gamma(-0) = -Inf
Gamma(x) = NaN for integer x < 0
Gamma(-Inf) = NaN
Gamma(NaN) = NaN

func Hypot

func Hypot(p, q float32) float32

Hypot returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow.

Special cases are:

Hypot(±Inf, q) = +Inf
Hypot(p, ±Inf) = +Inf
Hypot(NaN, q) = NaN
Hypot(p, NaN) = NaN

func Ilogb

func Ilogb(x float32) float32

Ilogb returns the binary exponent of x as an integer.

Special cases are:

Ilogb(±Inf) = MaxInt32
Ilogb(0) = MinInt32
Ilogb(NaN) = MaxInt32

func Inf

func Inf(sign int) float32

Inf returns positive infinity if sign >= 0, negative infinity if sign < 0.

func IntMultiple

func IntMultiple(val, mod float32) float32

IntMultiple returns the interger multiple of mod closest to given value: Round(val / mod) * mod

func IntMultipleGE

func IntMultipleGE(val, mod float32) float32

IntMultipleGE returns the interger multiple of mod >= given value: Ceil(val / mod) * mod

func IsInf

func IsInf(x float32, sign int) bool

IsInf reports whether f is an infinity, according to sign. If sign > 0, IsInf reports whether f is positive infinity. If sign < 0, IsInf reports whether f is negative infinity. If sign == 0, IsInf reports whether f is either infinity.

func IsNaN

func IsNaN(x float32) bool

IsNaN reports whether f is an IEEE 754 “not-a-number” value.

func J0

func J0(x float32) float32

J0 returns the order-zero Bessel function of the first kind.

Special cases are:

J0(±Inf) = 0
J0(0) = 1
J0(NaN) = NaN

func J1

func J1(x float32) float32

J1 returns the order-one Bessel function of the first kind.

Special cases are:

J1(±Inf) = 0
J1(NaN) = NaN

func Jn

func Jn(n int, x float32) float32

Jn returns the order-n Bessel function of the first kind.

Special cases are:

Jn(n, ±Inf) = 0
Jn(n, NaN) = NaN

func Ldexp

func Ldexp(frac float32, exp int) float32

Ldexp is the inverse of Frexp. It returns frac × 2**exp.

Special cases are:

Ldexp(±0, exp) = ±0
Ldexp(±Inf, exp) = ±Inf
Ldexp(NaN, exp) = NaN

func Lerp

func Lerp(start, stop, amount float32) float32

Lerp returns the linear interpolation between start and stop in proportion to amount

func Lgamma

func Lgamma(x float32) (lgamma float32, sign int)

Lgamma returns the natural logarithm and sign (-1 or +1) of Gamma(x).

Special cases are:

Lgamma(+Inf) = +Inf
Lgamma(0) = +Inf
Lgamma(-integer) = +Inf
Lgamma(-Inf) = -Inf
Lgamma(NaN) = NaN

func Log

func Log(x float32) float32

Log returns the natural logarithm of x.

Special cases are:

Log(+Inf) = +Inf
Log(0) = -Inf
Log(x < 0) = NaN
Log(NaN) = NaN

func Log10

func Log10(x float32) float32

Log10 returns the decimal logarithm of x. The special cases are the same as for Log.

func Log1p

func Log1p(x float32) float32

Log1p returns the natural logarithm of 1 plus its argument x. It is more accurate than Log(1 + x) when x is near zero.

Special cases are:

Log1p(+Inf) = +Inf
Log1p(±0) = ±0
Log1p(-1) = -Inf
Log1p(x < -1) = NaN
Log1p(NaN) = NaN

func Log2

func Log2(x float32) float32

Log2 returns the binary logarithm of x. The special cases are the same as for Log.

func Logb

func Logb(x float32) float32

Logb returns the binary exponent of x.

Special cases are:

Logb(±Inf) = +Inf
Logb(0) = -Inf
Logb(NaN) = NaN

func Max

func Max(x, y float32) float32

Max returns the larger of x or y.

Special cases are:

Max(x, +Inf) = Max(+Inf, x) = +Inf
Max(x, NaN) = Max(NaN, x) = NaN
Max(+0, ±0) = Max(±0, +0) = +0
Max(-0, -0) = -0

Note that this differs from the built-in function max when called with NaN and +Inf.

func MaxPos

func MaxPos(a, b float32) float32

MaxPos returns the minimum of the two values, excluding any that are <= 0

func Min

func Min(x, y float32) float32

Min returns the smaller of x or y.

Special cases are:

Min(x, -Inf) = Min(-Inf, x) = -Inf
Min(x, NaN) = Min(NaN, x) = NaN
Min(-0, ±0) = Min(±0, -0) = -0

Note that this differs from the built-in function min when called with NaN and -Inf.

func MinPos

func MinPos(a, b float32) float32

MinPos returns the minimum of the two values, excluding any that are <= 0

func Mod

func Mod(x, y float32) float32

Mod returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.

Special cases are:

Mod(±Inf, y) = NaN
Mod(NaN, y) = NaN
Mod(x, 0) = NaN
Mod(x, ±Inf) = x
Mod(x, NaN) = NaN

func Modf

func Modf(f float32) (it float32, frac float32)

Modf returns integer and fractional floating-point numbers that sum to f. Both values have the same sign as f.

Special cases are:

Modf(±Inf) = ±Inf, NaN
Modf(NaN) = NaN, NaN

func NaN

func NaN() float32

NaN returns an IEEE 754 “not-a-number” value.

func Nextafter

func Nextafter(x, y float32) float32

Nextafter returns the next representable float32 value after x towards y.

Special cases are:

Nextafter32(x, x)   = x
Nextafter32(NaN, y) = NaN
Nextafter32(x, NaN) = NaN

func ParseAngle32

func ParseAngle32(pstr string) (float32, error)

ParseAngle32 returns radians angle from string that can specify units (deg, grad, rad) -- deg is assumed if not specified

func ParseFloat32

func ParseFloat32(pstr string) (float32, error)

ParseFloat32 logs any strconv.ParseFloat errors

func PointDim

func PointDim(pt image.Point, dim Dims) int

PointDim returns the given dimension of the given image.Point.

func PointsCheckN

func PointsCheckN(pts []float32, n int, errmsg string) error

PointsCheckN checks the number of points read and emits an error if not equal to n

func Pow

func Pow(x, y float32) float32

Pow returns x**y, the base-x exponential of y.

Special cases are (in order):

Pow(x, ±0) = 1 for any x
Pow(1, y) = 1 for any y
Pow(x, 1) = x for any x
Pow(NaN, y) = NaN
Pow(x, NaN) = NaN
Pow(±0, y) = ±Inf for y an odd integer < 0
Pow(±0, -Inf) = +Inf
Pow(±0, +Inf) = +0
Pow(±0, y) = +Inf for finite y < 0 and not an odd integer
Pow(±0, y) = ±0 for y an odd integer > 0
Pow(±0, y) = +0 for finite y > 0 and not an odd integer
Pow(-1, ±Inf) = 1
Pow(x, +Inf) = +Inf for |x| > 1
Pow(x, -Inf) = +0 for |x| > 1
Pow(x, +Inf) = +0 for |x| < 1
Pow(x, -Inf) = +Inf for |x| < 1
Pow(+Inf, y) = +Inf for y > 0
Pow(+Inf, y) = +0 for y < 0
Pow(-Inf, y) = Pow(-0, -y)
Pow(x, y) = NaN for finite x < 0 and finite non-integer y

func Pow10

func Pow10(n int) float32

Pow10 returns 10**n, the base-10 exponential of n.

Special cases are:

Pow10(n) =    0 for n < -323
Pow10(n) = +Inf for n > 308

func RadToDeg

func RadToDeg(radians float32) float32

RadToDeg converts a number from radians to degrees

func ReadPoints

func ReadPoints(pstr string) []float32

ReadPoints reads a set of floating point values from a SVG format number string -- returns a slice or nil if there was an error

func RectFromPosSizeMax

func RectFromPosSizeMax(pos, size Vector2) image.Rectangle

RectFromPosSizeMax returns an image.Rectangle from the floor of pos and ceil of size.

func RectFromPosSizeMin

func RectFromPosSizeMin(pos, size Vector2) image.Rectangle

RectFromPosSizeMin returns an image.Rectangle from the ceil of pos and floor of size.

func RectInNotEmpty

func RectInNotEmpty(r, b image.Rectangle) bool

RectInNotEmpty returns true if rect r is contained within b box and r is not empty. The existing image.Rectangle.In method returns true if r is empty, but we typically expect that case to be false (out of range box)

func Remainder

func Remainder(x, y float32) float32

Remainder returns the IEEE 754 floating-point remainder of x/y.

Special cases are:

Remainder(±Inf, y) = NaN
Remainder(NaN, y) = NaN
Remainder(x, 0) = NaN
Remainder(x, ±Inf) = x
Remainder(x, NaN) = NaN

func Round

func Round(x float32) float32

Round returns the nearest integer, rounding half away from zero.

Special cases are:

Round(±0) = ±0
Round(±Inf) = ±Inf
Round(NaN) = NaN

func RoundToEven

func RoundToEven(x float32) float32

RoundToEven returns the nearest integer, rounding ties to even.

Special cases are:

RoundToEven(±0) = ±0
RoundToEven(±Inf) = ±Inf
RoundToEven(NaN) = NaN

func SRGBFromLinear

func SRGBFromLinear(lin float32) float32

SRGBFromLinear converts a color with linear gamma correction to SRGB standard 2.4 gamma with offsets.

func SRGBToLinear

func SRGBToLinear(sr float32) float32

SRGBToLinear converts a color with SRGB gamma correction to SRGB standard 2.4 gamma with offsets

func SetPointDim

func SetPointDim(pt *image.Point, dim Dims, value int)

SetPointDim sets the given dimension of the given image.Point to the given value.

func Sign

func Sign(x float32) float32

Sign returns -1 if x < 0 and 1 otherwise.

func Signbit

func Signbit(x float32) bool

Signbit returns true if x is negative or negative zero.

func Sin

func Sin(x float32) float32

Sin returns the sine of the radian argument x.

Special cases are:

Sin(±0) = ±0
Sin(±Inf) = NaN
Sin(NaN) = NaN

func Sincos

func Sincos(x float32) (sin, cos float32)

Sincos returns Sin(x), Cos(x).

Special cases are:

Sincos(±0) = ±0, 1
Sincos(±Inf) = NaN, NaN
Sincos(NaN) = NaN, NaN

func Sinh

func Sinh(x float32) float32

Sinh returns the hyperbolic sine of x.

Special cases are:

Sinh(±0) = ±0
Sinh(±Inf) = ±Inf
Sinh(NaN) = NaN

func Sqrt

func Sqrt(x float32) float32

Sqrt returns the square root of x.

Special cases are:

Sqrt(+Inf) = +Inf
Sqrt(±0) = ±0
Sqrt(x < 0) = NaN
Sqrt(NaN) = NaN

func Tan

func Tan(x float32) float32

Tan returns the tangent of the radian argument x.

Special cases are:

Tan(±0) = ±0
Tan(±Inf) = NaN
Tan(NaN) = NaN

func Tanh

func Tanh(x float32) float32

Tanh returns the hyperbolic tangent of x.

Special cases are:

Tanh(±0) = ±0
Tanh(±Inf) = ±1
Tanh(NaN) = NaN

func ToFixed

func ToFixed(x float32) fixed.Int26_6

ToFixed converts a float32 value to a fixed.Int26_6

func ToFixedPoint

func ToFixedPoint(x, y float32) fixed.Point26_6

ToFixedPoint converts float32 x,y values to a fixed.Point26_6

func Trunc

func Trunc(x float32) float32

Trunc returns the integer value of x.

Special cases are:

Trunc(±0) = ±0
Trunc(±Inf) = ±Inf
Trunc(NaN) = NaN

func Truncate

func Truncate(val float32, prec int) float32

Truncate rounds a float32 number to the given level of precision, which the number of significant digits to include in the result.

func Truncate64

func Truncate64(val float64, prec int) float64

Truncate64 rounds a float64 number to the given level of precision, which the number of significant digits to include in the result.

func Y0

func Y0(x float32) float32

Y0 returns the order-zero Bessel function of the second kind.

Special cases are:

Y0(+Inf) = 0
Y0(0) = -Inf
Y0(x < 0) = NaN
Y0(NaN) = NaN

func Y1

func Y1(x float32) float32

Y1 returns the order-one Bessel function of the second kind.

Special cases are:

Y1(+Inf) = 0
Y1(0) = -Inf
Y1(x < 0) = NaN
Y1(NaN) = NaN

func Yn

func Yn(n int, x float32) float32

Yn returns the order-n Bessel function of the second kind.

Special cases are:

Yn(n, +Inf) = 0
Yn(n ≥ 0, 0) = -Inf
Yn(n < 0, 0) = +Inf if n is odd, -Inf if n is even
Yn(n, x < 0) = NaN
Yn(n, NaN) = NaN

Types

type ArrayF32

type ArrayF32 []float32

ArrayF32 is a slice of float32 with additional convenience methods for other math32 data types. Use slicesx.SetLength to set length efficiently.

func NewArrayF32

func NewArrayF32(size, capacity int) ArrayF32

NewArrayF32 creates a returns a new array of floats with the specified initial size and capacity

func (*ArrayF32) Append

func (a *ArrayF32) Append(v ...float32)

Append appends any number of values to the array

func (*ArrayF32) AppendVector2

func (a *ArrayF32) AppendVector2(v ...Vector2)

AppendVector2 appends any number of Vector2 to the array

func (*ArrayF32) AppendVector3

func (a *ArrayF32) AppendVector3(v ...Vector3)

AppendVector3 appends any number of Vector3 to the array

func (*ArrayF32) AppendVector4

func (a *ArrayF32) AppendVector4(v ...Vector4)

AppendVector4 appends any number of Vector4 to the array

func (*ArrayF32) CopyFrom

func (a *ArrayF32) CopyFrom(src ArrayF32)

func (ArrayF32) GetMatrix4

func (a ArrayF32) GetMatrix4(pos int, m *Matrix4)

GetMatrix4 stores in the specified Matrix4 the values from the array starting at the specified pos.

func (ArrayF32) GetVector2

func (a ArrayF32) GetVector2(pos int, v *Vector2)

GetVector2 stores in the specified Vector2 the values from the array starting at the specified pos.

func (ArrayF32) GetVector3

func (a ArrayF32) GetVector3(pos int, v *Vector3)

GetVector3 stores in the specified Vector3 the values from the array starting at the specified pos.

func (ArrayF32) GetVector4

func (a ArrayF32) GetVector4(pos int, v *Vector4)

GetVector4 stores in the specified Vector4 the values from the array starting at the specified pos.

func (*ArrayF32) NumBytes added in v0.3.2

func (a *ArrayF32) NumBytes() int

NumBytes returns the size of the array in bytes

func (ArrayF32) Set

func (a ArrayF32) Set(pos int, v ...float32)

Set sets the values of the array starting at the specified pos from the specified values

func (ArrayF32) SetVector2

func (a ArrayF32) SetVector2(pos int, v Vector2)

SetVector2 sets the values of the array at the specified pos from the XY values of the specified Vector2

func (ArrayF32) SetVector3

func (a ArrayF32) SetVector3(pos int, v Vector3)

SetVector3 sets the values of the array at the specified pos from the XYZ values of the specified Vector3

func (ArrayF32) SetVector4

func (a ArrayF32) SetVector4(pos int, v Vector4)

SetVector4 sets the values of the array at the specified pos from the XYZ values of the specified Vector4

type ArrayU32

type ArrayU32 []uint32

ArrayU32 is a slice of uint32 with additional convenience methods. Use slicesx.SetLength to set length efficiently.

func NewArrayU32

func NewArrayU32(size, capacity int) ArrayU32

NewArrayU32 creates a returns a new array of uint32 with the specified initial size and capacity

func (*ArrayU32) Append

func (a *ArrayU32) Append(v ...uint32)

Append appends n elements to the array updating the slice if necessary

func (*ArrayU32) NumBytes added in v0.3.2

func (a *ArrayU32) NumBytes() int

NumBytes returns the size of the array in bytes

func (ArrayU32) Set

func (a ArrayU32) Set(pos int, v ...uint32)

Set sets the values of the array starting at the specified pos from the specified values

type Box2

type Box2 struct {
	Min Vector2
	Max Vector2
}

Box2 represents a 2D bounding box defined by two points: the point with minimum coordinates and the point with maximum coordinates.

func B2

func B2(x0, y0, x1, y1 float32) Box2

B2 returns a new Box2 from the given minimum and maximum x and y coordinates.

func B2Empty

func B2Empty() Box2

B2Empty returns a new Box2 with empty minimum and maximum values

func B2FromFixed added in v0.1.1

func B2FromFixed(rect fixed.Rectangle26_6) Box2

B2FromFixed returns a new Box2 from the given fixed.Rectangle26_6.

func B2FromRect

func B2FromRect(rect image.Rectangle) Box2

B2FromRect returns a new Box2 from the given image.Rectangle.

func (Box2) Canon

func (b Box2) Canon() Box2

Canon returns the canonical version of the box. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.

func (Box2) Center

func (b Box2) Center() Vector2

Center calculates the center point of this bounding box.

func (Box2) ClampPoint

func (b Box2) ClampPoint(point Vector2) Vector2

ClampPoint calculates a new point which is the specified point clamped inside this box.

func (Box2) ContainsBox

func (b Box2) ContainsBox(box Box2) bool

ContainsBox returns if this bounding box contains other box.

func (Box2) ContainsPoint

func (b Box2) ContainsPoint(point Vector2) bool

ContainsPoint returns if this bounding box contains the specified point.

func (Box2) DistanceToPoint added in v0.1.4

func (b Box2) DistanceToPoint(point Vector2) float32

DistanceToPoint returns the distance from this box to the specified point.

func (*Box2) ExpandByBox

func (b *Box2) ExpandByBox(box Box2)

ExpandByBox may expand this bounding box to include the specified box

func (*Box2) ExpandByPoint

func (b *Box2) ExpandByPoint(point Vector2)

ExpandByPoint may expand this bounding box to include the specified point.

func (*Box2) ExpandByScalar

func (b *Box2) ExpandByScalar(scalar float32)

ExpandByScalar expands this bounding box by the specified scalar.

func (*Box2) ExpandByVector

func (b *Box2) ExpandByVector(vector Vector2)

ExpandByVector expands this bounding box by the specified vector.

func (Box2) Intersect

func (b Box2) Intersect(other Box2) Box2

Intersect returns the intersection with other box.

func (Box2) IntersectsBox

func (b Box2) IntersectsBox(other Box2) bool

IntersectsBox returns if other box intersects this one.

func (*Box2) IsEmpty

func (b *Box2) IsEmpty() bool

IsEmpty returns if this bounding box is empty (max < min on any coord).

func (Box2) MulMatrix2

func (b Box2) MulMatrix2(m Matrix2) Box2

MulMatrix2 multiplies the specified matrix to the vertices of this bounding box and computes the resulting spanning Box2 of the transformed points

func (Box2) ProjectX added in v0.1.1

func (b Box2) ProjectX(v float32) float32

ProjectX projects normalized value along the X dimension of this box

func (Box2) ProjectY added in v0.1.1

func (b Box2) ProjectY(v float32) float32

ProjectY projects normalized value along the Y dimension of this box

func (*Box2) Set

func (b *Box2) Set(min, max *Vector2)

Set sets this bounding box minimum and maximum coordinates. If either min or max are nil, then corresponding values are set to +/- Infinity.

func (*Box2) SetEmpty

func (b *Box2) SetEmpty()

SetEmpty set this bounding box to empty (min / max +/- Infinity)

func (*Box2) SetFromCenterAndSize

func (b *Box2) SetFromCenterAndSize(center, size Vector2)

SetFromCenterAndSize set this bounding box from a center point and size. Size is a vector from the minimum point to the maximum point.

func (*Box2) SetFromPoints

func (b *Box2) SetFromPoints(points []Vector2)

SetFromPoints set this bounding box from the specified array of points.

func (*Box2) SetFromRect

func (b *Box2) SetFromRect(rect image.Rectangle)

SetFromRect set this bounding box from an image.Rectangle

func (Box2) Size

func (b Box2) Size() Vector2

Size calculates the size of this bounding box: the vector from its minimum point to its maximum point.

func (Box2) ToRect

func (b Box2) ToRect() image.Rectangle

ToRect returns image.Rectangle version of this bbox, using floor for min and Ceil for max.

func (Box2) Translate

func (b Box2) Translate(offset Vector2) Box2

Translate returns translated position of this box by offset.

func (Box2) Union

func (b Box2) Union(other Box2) Box2

Union returns the union with other box.

type Box3

type Box3 struct {
	Min Vector3
	Max Vector3
}

Box3 represents a 3D bounding box defined by two points: the point with minimum coordinates and the point with maximum coordinates.

func B3

func B3(x0, y0, z0, x1, y1, z1 float32) Box3

B3 returns a new Box3 from the given minimum and maximum x, y, and z coordinates.

func B3Empty

func B3Empty() Box3

B3Empty returns a new Box3 with empty minimum and maximum values.

func (Box3) Center

func (b Box3) Center() Vector3

Center returns the center of the bounding box.

func (Box3) ClampPoint

func (b Box3) ClampPoint(point Vector3) Vector3

ClampPoint returns a new point which is the specified point clamped inside this box.

func (Box3) ContainsBox

func (b Box3) ContainsBox(box Box3) bool

ContainsBox returns if this bounding box contains other box.

func (Box3) ContainsPoint

func (b Box3) ContainsPoint(point Vector3) bool

ContainsPoint returns if this bounding box contains the specified point.

func (Box3) DistanceToPoint added in v0.1.4

func (b Box3) DistanceToPoint(point Vector3) float32

DistanceToPoint returns the distance from this box to the specified point.

func (*Box3) ExpandByBox

func (b *Box3) ExpandByBox(box Box3)

ExpandByBox may expand this bounding box to include the specified box

func (*Box3) ExpandByPoint

func (b *Box3) ExpandByPoint(point Vector3)

ExpandByPoint may expand this bounding box to include the specified point.

func (*Box3) ExpandByPoints

func (b *Box3) ExpandByPoints(points []Vector3)

ExpandByPoints may expand this bounding box from the specified array of points.

func (*Box3) ExpandByScalar

func (b *Box3) ExpandByScalar(scalar float32)

ExpandByScalar expands this bounding box by the specified scalar subtracting from min and adding to max.

func (*Box3) ExpandByVector

func (b *Box3) ExpandByVector(vector Vector3)

ExpandByVector expands this bounding box by the specified vector subtracting from min and adding to max.

func (Box3) GetBoundingSphere

func (b Box3) GetBoundingSphere() Sphere

GetBoundingSphere returns a bounding sphere to this bounding box.

func (Box3) Intersect

func (b Box3) Intersect(other Box3) Box3

Intersect returns the intersection with other box.

func (Box3) IntersectsBox

func (b Box3) IntersectsBox(other Box3) bool

IntersectsBox returns if other box intersects this one.

func (Box3) IsEmpty

func (b Box3) IsEmpty() bool

IsEmpty returns true if this bounding box is empty (max < min on any coord).

func (Box3) MVProjToNDC

func (b Box3) MVProjToNDC(m *Matrix4) Box3

MVProjToNDC projects bounding box through given MVP model-view-projection Matrix4 with perspective divide to return normalized display coordinates (NDC).

func (Box3) MulMatrix4

func (b Box3) MulMatrix4(m *Matrix4) Box3

MulMatrix4 multiplies the specified matrix to the vertices of this bounding box and computes the resulting spanning Box3 of the transformed points

func (Box3) MulQuat

func (b Box3) MulQuat(q Quat) Box3

MulQuat multiplies the specified quaternion to the vertices of this bounding box and computes the resulting spanning Box3 of the transformed points

func (*Box3) Set

func (b *Box3) Set(min, max *Vector3)

Set sets this bounding box minimum and maximum coordinates. If either min or max are nil, then corresponding values are set to +/- Infinity.

func (*Box3) SetEmpty

func (b *Box3) SetEmpty()

SetEmpty set this bounding box to empty (min / max +/- Infinity)

func (*Box3) SetFromCenterAndSize

func (b *Box3) SetFromCenterAndSize(center, size Vector3)

SetFromCenterAndSize sets this bounding box from a center point and size. Size is a vector from the minimum point to the maximum point.

func (*Box3) SetFromPoints

func (b *Box3) SetFromPoints(points []Vector3)

SetFromPoints sets this bounding box from the specified array of points.

func (Box3) Size

func (b Box3) Size() Vector3

Size calculates the size of this bounding box: the vector from its minimum point to its maximum point.

func (Box3) Translate

func (b Box3) Translate(offset Vector3) Box3

Translate returns translated position of this box by offset.

func (Box3) Union

func (b Box3) Union(other Box3) Box3

Union returns the union with other box.

type Dims

type Dims int32 //enums:enum

Dims is a list of vector dimension (component) names

const (
	X Dims = iota
	Y
	Z
	W
)
const DimsN Dims = 4

DimsN is the highest valid value for type Dims, plus one.

func DimsValues

func DimsValues() []Dims

DimsValues returns all possible values for the type Dims.

func OtherDim

func OtherDim(d Dims) Dims

OtherDim returns the other dimension for 2D X,Y

func (Dims) Desc

func (i Dims) Desc() string

Desc returns the description of the Dims value.

func (Dims) Int64

func (i Dims) Int64() int64

Int64 returns the Dims value as an int64.

func (Dims) MarshalText

func (i Dims) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Dims) Other

func (d Dims) Other() Dims

func (*Dims) SetInt64

func (i *Dims) SetInt64(in int64)

SetInt64 sets the Dims value from an int64.

func (*Dims) SetString

func (i *Dims) SetString(s string) error

SetString sets the Dims value from its string representation, and returns an error if the string is invalid.

func (Dims) String

func (i Dims) String() string

String returns the string representation of this Dims value.

func (*Dims) UnmarshalText

func (i *Dims) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Dims) Values

func (i Dims) Values() []enums.Enum

Values returns all possible values for the type Dims.

type Frustum

type Frustum struct {
	Planes [6]Plane
}

Frustum represents a frustum

func NewFrustum

func NewFrustum(p0, p1, p2, p3, p4, p5 *Plane) *Frustum

NewFrustum returns a pointer to a new Frustum object made of 6 explicit planes

func NewFrustumFromMatrix

func NewFrustumFromMatrix(m *Matrix4) *Frustum

NewFrustumFromMatrix creates and returns a Frustum based on the provided matrix

func (*Frustum) ContainsPoint

func (f *Frustum) ContainsPoint(point Vector3) bool

ContainsPoint determines whether the frustum contains the specified point

func (*Frustum) IntersectsBox

func (f *Frustum) IntersectsBox(box Box3) bool

IntersectsBox determines whether the specified box is intersecting the frustum

func (*Frustum) IntersectsSphere

func (f *Frustum) IntersectsSphere(sphere Sphere) bool

IntersectsSphere determines whether the specified sphere is intersecting the frustum

func (*Frustum) Set

func (f *Frustum) Set(p0, p1, p2, p3, p4, p5 *Plane)

Set sets the frustum's planes

func (*Frustum) SetFromMatrix

func (f *Frustum) SetFromMatrix(m *Matrix4)

SetFromMatrix sets the frustum's planes based on the specified Matrix4

type Geom2DInt

type Geom2DInt struct {
	Pos  image.Point
	Size image.Point
}

Geom2DInt defines a geometry in 2D dots units (int) -- this is just a more convenient format than image.Rectangle for cases where the size and position are independently updated (e.g., Viewport)

func (*Geom2DInt) Bounds

func (gm *Geom2DInt) Bounds() image.Rectangle

Bounds converts geom to equivalent image.Rectangle

func (*Geom2DInt) FitInWindow

func (gm *Geom2DInt) FitInWindow(win Geom2DInt) Geom2DInt

FitInWindow returns a position and size for a region (sub-window) within a larger window geom that fits entirely within that window to the extent possible, for the initial "ideal" starting position and size. The position is first adjusted to try to fit the size, and then the size is adjusted to make it fit if it is still too big.

func (*Geom2DInt) SetRect

func (gm *Geom2DInt) SetRect(r image.Rectangle)

SetRect sets values from image.Rectangle

func (*Geom2DInt) SizeRect

func (gm *Geom2DInt) SizeRect() image.Rectangle

SizeRect converts geom to rect version of size at 0 pos

type Line2 added in v0.3.3

type Line2 struct {
	Start Vector2
	End   Vector2
}

Line2 represents a 2D line segment defined by a start and an end point.

func NewLine2 added in v0.3.3

func NewLine2(start, end Vector2) Line2

NewLine2 creates and returns a new Line2 with the specified start and end points.

func (*Line2) Center added in v0.3.3

func (l *Line2) Center() Vector2

Center calculates this line segment center point.

func (*Line2) ClosestPointToPoint added in v0.3.3

func (l *Line2) ClosestPointToPoint(point Vector2) Vector2

ClosestPointToPoint returns the point along the line that is closest to the given point.

func (*Line2) Delta added in v0.3.3

func (l *Line2) Delta() Vector2

Delta calculates the vector from the start to end point of this line segment.

func (*Line2) Length added in v0.3.3

func (l *Line2) Length() float32

Length returns the length from the start point to the end point.

func (*Line2) LengthSquared added in v0.3.3

func (l *Line2) LengthSquared() float32

LengthSquared returns the square of the distance from the start point to the end point.

func (*Line2) Set added in v0.3.3

func (l *Line2) Set(start, end Vector2)

Set sets this line segment start and end points.

type Line3

type Line3 struct {
	Start Vector3
	End   Vector3
}

Line3 represents a 3D line segment defined by a start and an end point.

func NewLine3

func NewLine3(start, end Vector3) Line3

NewLine3 creates and returns a new Line3 with the specified start and end points.

func (*Line3) Center

func (l *Line3) Center() Vector3

Center calculates this line segment center point.

func (*Line3) Delta

func (l *Line3) Delta() Vector3

Delta calculates the vector from the start to end point of this line segment.

func (*Line3) Dist

func (l *Line3) Dist() float32

Dist returns the distance from the start point to the end point.

func (*Line3) DistanceSquared added in v0.1.4

func (l *Line3) DistanceSquared() float32

DistanceSquared returns the square of the distance from the start point to the end point.

func (*Line3) MulMatrix4

func (l *Line3) MulMatrix4(mat *Matrix4) Line3

MulMatrix4 returns specified matrix multiplied to this line segment start and end points.

func (*Line3) Set

func (l *Line3) Set(start, end Vector3)

Set sets this line segment start and end points.

type Matrix2

type Matrix2 struct {
	XX, YX, XY, YY, X0, Y0 float32
}

Matrix2 is a 3x2 matrix.

func Identity2

func Identity2() Matrix2

Identity2 returns a new identity Matrix2 matrix.

func Rotate2D

func Rotate2D(angle float32) Matrix2

Rotate2D returns a Matrix2 2D matrix with given rotation, specified in radians

func Scale2D

func Scale2D(x, y float32) Matrix2

Scale2D returns a Matrix2 2D matrix with given scaling factors

func Shear2D

func Shear2D(x, y float32) Matrix2

Shear2D returns a Matrix2 2D matrix with given shearing

func Skew2D

func Skew2D(x, y float32) Matrix2

Skew2D returns a Matrix2 2D matrix with given skewing

func Translate2D

func Translate2D(x, y float32) Matrix2

Translate2D returns a Matrix2 2D matrix with given translations

func (Matrix2) ExtractRot

func (a Matrix2) ExtractRot() float32

ExtractRot extracts the rotation component from a given matrix

func (Matrix2) ExtractScale

func (a Matrix2) ExtractScale() (scx, scy float32)

ExtractXYScale extracts the X and Y scale factors after undoing any rotation present -- i.e., in the original X, Y coordinates

func (Matrix2) Inverse

func (a Matrix2) Inverse() Matrix2

Inverse returns inverse of matrix, for inverting transforms

func (Matrix2) IsIdentity

func (m Matrix2) IsIdentity() bool

func (Matrix2) Mul

func (a Matrix2) Mul(b Matrix2) Matrix2

Mul returns a*b

func (Matrix2) MulCenter

func (a Matrix2) MulCenter(b Matrix2, ctr Vector2) Matrix2

MulCenter multiplies the Matrix2, first subtracting given translation center point from the translation components, and then adding it back in.

func (Matrix2) MulFixedAsPoint

func (a Matrix2) MulFixedAsPoint(fp fixed.Point26_6) fixed.Point26_6

MulFixedAsPoint multiplies the fixed point as a point, including adding translations.

func (Matrix2) MulVector2AsPoint

func (a Matrix2) MulVector2AsPoint(v Vector2) Vector2

MulVector2AsPoint multiplies the Vector2 as a point, including adding translations.

func (Matrix2) MulVector2AsPointCenter

func (a Matrix2) MulVector2AsPointCenter(v, ctr Vector2) Vector2

MulVector2AsPointCenter multiplies the Vector2 as a point relative to given center-point including adding translations.

func (Matrix2) MulVector2AsVector

func (a Matrix2) MulVector2AsVector(v Vector2) Vector2

MulVector2AsVector multiplies the Vector2 as a vector without adding translations. This is for directional vectors and not points.

func (Matrix2) Rotate

func (a Matrix2) Rotate(angle float32) Matrix2

func (Matrix2) Scale

func (a Matrix2) Scale(x, y float32) Matrix2

func (*Matrix2) SetMul

func (a *Matrix2) SetMul(b Matrix2)

SetMul sets a to a*b

func (*Matrix2) SetMulCenter

func (a *Matrix2) SetMulCenter(b Matrix2, ctr Vector2)

SetMulCenter sets the matrix to the result of Matrix2.MulCenter.

func (*Matrix2) SetString

func (a *Matrix2) SetString(str string) error

SetString processes the standard SVG-style transform strings

func (Matrix2) Shear

func (a Matrix2) Shear(x, y float32) Matrix2

func (Matrix2) Skew

func (a Matrix2) Skew(x, y float32) Matrix2

func (*Matrix2) String

func (a *Matrix2) String() string

String returns the XML-based string representation of the transform

func (Matrix2) Translate

func (a Matrix2) Translate(x, y float32) Matrix2

type Matrix3

type Matrix3 [9]float32

Matrix3 is 3x3 matrix organized internally as column matrix.

func Identity3

func Identity3() Matrix3

Identity3 returns a new identity Matrix3 matrix.

func Matrix3FromMatrix2

func Matrix3FromMatrix2(m Matrix2) Matrix3

func Matrix3FromMatrix4

func Matrix3FromMatrix4(m *Matrix4) Matrix3

func Matrix3Rotate2D

func Matrix3Rotate2D(angle float32) Matrix3

Rotate2D returns a Matrix2 2D matrix with given rotation, specified in radians

func Matrix3Scale2D

func Matrix3Scale2D(x, y float32) Matrix3

Matrix3Scale2D returns a Matrix3 2D matrix with given scaling factors

func Matrix3Translate2D

func Matrix3Translate2D(x, y float32) Matrix3

Matrix3Translate2D returns a Matrix3 2D matrix with given translations

func (*Matrix3) CopyFrom

func (m *Matrix3) CopyFrom(src Matrix3)

CopyFrom copies from source matrix into this matrix (a regular = assign does not copy data, just the pointer!)

func (*Matrix3) Determinant

func (m *Matrix3) Determinant() float32

Determinant calculates and returns the determinant of this matrix.

func (*Matrix3) FromArray

func (m *Matrix3) FromArray(array []float32, offset int)

FromArray sets this matrix array starting at offset.

func (Matrix3) Inverse

func (m Matrix3) Inverse() Matrix3

Inverse returns the inverse of this matrix. If the matrix cannot be inverted it silently sets this matrix to the identity matrix. See Try version for error.

func (Matrix3) InverseTry

func (m Matrix3) InverseTry() (Matrix3, error)

InverseTry returns the inverse of this matrix. If the matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (Matrix3) Mul

func (m Matrix3) Mul(other Matrix3) Matrix3

Mul returns this matrix times other matrix (this matrix is unchanged)

func (*Matrix3) MulMatrices

func (m *Matrix3) MulMatrices(a, b Matrix3)

MulMatrices sets ths matrix as matrix multiplication a by b (i.e., a*b).

func (Matrix3) MulScalar

func (m Matrix3) MulScalar(s float32) Matrix3

MulScalar returns each of this matrix's components multiplied by the specified scalar, leaving the original matrix unchanged.

func (Matrix3) MulVector2AsPoint

func (a Matrix3) MulVector2AsPoint(v Vector2) Vector2

MulVector2AsPoint multiplies the Vector2 as a point, including adding translations.

func (Matrix3) MulVector2AsVector

func (a Matrix3) MulVector2AsVector(v Vector2) Vector2

MulVector2AsVector multiplies the Vector2 as a vector without adding translations. This is for directional vectors and not points.

func (*Matrix3) MulVector3Array

func (m *Matrix3) MulVector3Array(array []float32, start, count int)

MulVector3Array multiplies count vectors (i.e., 3 sequential array values per each increment in count) in the array starting at start index by this matrix.

func (*Matrix3) ScaleCols

func (m *Matrix3) ScaleCols(v Vector3) *Matrix3

ScaleCols returns matrix with columns multiplied by the vector components. This can be used when multiplying this matrix by a diagonal matrix if we store the diagonal components as a vector.

func (*Matrix3) Set

func (m *Matrix3) Set(n11, n12, n13, n21, n22, n23, n31, n32, n33 float32)

Set sets all the elements of the matrix row by row starting at row1, column1, row1, column2, row1, column3 and so forth.

func (*Matrix3) SetFromMatrix2

func (m *Matrix3) SetFromMatrix2(src Matrix2)

SetFromMatrix2 sets the matrix elements based on a Matrix2.

func (*Matrix3) SetFromMatrix4

func (m *Matrix3) SetFromMatrix4(src *Matrix4)

SetFromMatrix4 sets the matrix elements based on a Matrix4.

func (*Matrix3) SetIdentity

func (m *Matrix3) SetIdentity()

SetIdentity sets this matrix as the identity matrix.

func (*Matrix3) SetInverse

func (m *Matrix3) SetInverse(src Matrix3) error

SetInverse sets this matrix to the inverse of the src matrix. If the src matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Matrix3) SetMul

func (m *Matrix3) SetMul(other Matrix3)

SetMul sets this matrix to this matrix * other

func (*Matrix3) SetMulScalar

func (m *Matrix3) SetMulScalar(s float32)

SetMulScalar multiplies each of this matrix's components by the specified scalar.

func (*Matrix3) SetNormalMatrix

func (m *Matrix3) SetNormalMatrix(src *Matrix4) error

SetNormalMatrix set this matrix to the matrix that can transform the normal vectors from the src matrix which is used transform the vertices (e.g., a ModelView matrix). If the src matrix cannot be inverted returns error.

func (*Matrix3) SetRotationFromQuat

func (m *Matrix3) SetRotationFromQuat(q Quat)

SetRotationFromQuat sets this matrix as a rotation matrix from the specified Quat.

func (*Matrix3) SetScaleCols

func (m *Matrix3) SetScaleCols(v Vector3)

SetScaleCols multiplies the matrix columns by the vector components. This can be used when multiplying this matrix by a diagonal matrix if we store the diagonal components as a vector.

func (*Matrix3) SetTranspose

func (m *Matrix3) SetTranspose()

SetTranspose transposes this matrix.

func (*Matrix3) SetZero

func (m *Matrix3) SetZero()

SetZero sets this matrix as the zero matrix.

func (Matrix3) ToArray

func (m Matrix3) ToArray(array []float32, offset int)

ToArray copies this matrix to array starting at offset.

func (Matrix3) Transpose

func (m Matrix3) Transpose() Matrix3

Transpose returns the transpose of this matrix.

type Matrix4

type Matrix4 [16]float32

Matrix4 is 4x4 matrix organized internally as column matrix.

func Identity4

func Identity4() *Matrix4

Identity4 returns a new identity Matrix4 matrix.

func NewLookAt

func NewLookAt(eye, target, up Vector3) *Matrix4

NewLookAt returns Matrix4 matrix as view transform matrix with origin at eye, looking at target and using the up vector.

func (*Matrix4) CopyFrom

func (m *Matrix4) CopyFrom(src *Matrix4)

CopyFrom copies from source matrix into this matrix (a regular = assign does not copy data, just the pointer!)

func (*Matrix4) CopyPos

func (m *Matrix4) CopyPos(src *Matrix4)

CopyPos copies the position elements of the src matrix into this one.

func (*Matrix4) Decompose

func (m *Matrix4) Decompose() (pos Vector3, quat Quat, scale Vector3)

Decompose updates the position vector, quaternion and scale from this transformation matrix.

func (*Matrix4) Determinant

func (m *Matrix4) Determinant() float32

Determinant calculates and returns the determinant of this matrix.

func (*Matrix4) ExtractBasis

func (m *Matrix4) ExtractBasis() (xAxis, yAxis, zAxis Vector3)

ExtractBasis returns the x,y,z basis vectors of this matrix.

func (*Matrix4) ExtractRotation

func (m *Matrix4) ExtractRotation(src *Matrix4)

ExtractRotation sets this matrix as rotation matrix from the src transformation matrix.

func (*Matrix4) FromArray

func (m *Matrix4) FromArray(array []float32, offset int)

FromArray set this matrix elements from the array starting at offset.

func (*Matrix4) GetMaxScaleOnAxis

func (m *Matrix4) GetMaxScaleOnAxis() float32

GetMaxScaleOnAxis returns the maximum scale value of the 3 axes.

func (*Matrix4) Inverse

func (m *Matrix4) Inverse() (*Matrix4, error)

Inverse returns the inverse of this matrix. If the matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Matrix4) LookAt

func (m *Matrix4) LookAt(eye, target, up Vector3)

LookAt sets this matrix as view transform matrix with origin at eye, looking at target and using the up vector.

func (*Matrix4) Mul

func (m *Matrix4) Mul(other *Matrix4) *Matrix4

Mul returns this matrix times other matrix (this matrix is unchanged)

func (*Matrix4) MulMatrices

func (m *Matrix4) MulMatrices(a, b *Matrix4)

MulMatrices sets this matrix as matrix multiplication a by b (i.e. a*b).

func (*Matrix4) MulScalar

func (m *Matrix4) MulScalar(s float32)

SetMulScalar multiplies each element of this matrix by the specified scalar.

func (*Matrix4) MulVector3Array

func (m *Matrix4) MulVector3Array(array []float32, start, count int)

MulVector3Array multiplies count vectors (i.e., 3 sequential array values per each increment in count) in the array starting at start index by this matrix.

func (*Matrix4) Pos

func (m *Matrix4) Pos() Vector3

Pos returns the position component of the matrix

func (*Matrix4) ScaleCols

func (m *Matrix4) ScaleCols(v Vector3) *Matrix4

ScaleCols returns matrix with first column of this matrix multiplied by the vector X component, the second column by the vector Y component and the third column by the vector Z component. The matrix fourth column is unchanged.

func (*Matrix4) Set

func (m *Matrix4) Set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 float32)

Set sets all the elements of this matrix row by row starting at row1, column1, row1, column2, row1, column3 and so forth.

func (*Matrix4) SetBasis

func (m *Matrix4) SetBasis(xAxis, yAxis, zAxis Vector3)

SetBasis sets this matrix basis vectors from the specified vectors.

func (*Matrix4) SetFromMatrix3

func (m *Matrix4) SetFromMatrix3(src *Matrix3)

SetFromMatrix3 sets the matrix elements based on a Matrix3, filling in 0's for missing off-diagonal elements, and 1 on the diagonal.

func (*Matrix4) SetFrustum

func (m *Matrix4) SetFrustum(left, right, bottom, top, near, far float32)

SetFrustum sets this matrix to a projection frustum matrix bounded by the specified planes.

func (*Matrix4) SetIdentity

func (m *Matrix4) SetIdentity()

SetIdentity sets this matrix as the identity matrix.

func (*Matrix4) SetInverse

func (m *Matrix4) SetInverse(src *Matrix4) error

SetInverse sets this matrix to the inverse of the src matrix. If the src matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Matrix4) SetMul

func (m *Matrix4) SetMul(other *Matrix4)

SetMul sets this matrix to this matrix times other

func (*Matrix4) SetOrthographic

func (m *Matrix4) SetOrthographic(width, height, near, far float32)

SetOrthographic sets this matrix to an orthographic projection matrix.

func (*Matrix4) SetPerspective

func (m *Matrix4) SetPerspective(fov, aspect, near, far float32)

SetPerspective sets this matrix to a perspective projection matrix with the specified field of view in degrees, aspect ratio (width/height) and near and far planes.

func (*Matrix4) SetPos

func (m *Matrix4) SetPos(v Vector3)

SetPos sets this transformation matrix position fields from the specified vector v.

func (*Matrix4) SetRotationAxis

func (m *Matrix4) SetRotationAxis(axis *Vector3, angle float32)

SetRotationAxis sets this matrix to a rotation matrix of the specified angle around the specified axis.

func (*Matrix4) SetRotationFromEuler

func (m *Matrix4) SetRotationFromEuler(euler Vector3)

SetRotationFromEuler set this a matrix as a rotation matrix from the specified euler angles.

func (*Matrix4) SetRotationFromQuat

func (m *Matrix4) SetRotationFromQuat(q Quat)

SetRotationFromQuat sets this matrix as a rotation matrix from the specified quaternion.

func (*Matrix4) SetRotationX

func (m *Matrix4) SetRotationX(theta float32)

SetRotationX sets this matrix to a rotation matrix of angle theta around the X axis.

func (*Matrix4) SetRotationY

func (m *Matrix4) SetRotationY(theta float32)

SetRotationY sets this matrix to a rotation matrix of angle theta around the Y axis.

func (*Matrix4) SetRotationZ

func (m *Matrix4) SetRotationZ(theta float32)

SetRotationZ sets this matrix to a rotation matrix of angle theta around the Z axis.

func (*Matrix4) SetScale

func (m *Matrix4) SetScale(x, y, z float32)

SetScale sets this matrix to a scale transformation matrix using the specified x, y and z values.

func (*Matrix4) SetScaleCols

func (m *Matrix4) SetScaleCols(v Vector3)

SetScaleCols multiplies the first column of this matrix by the vector X component, the second column by the vector Y component and the third column by the vector Z component. The matrix fourth column is unchanged.

func (*Matrix4) SetTransform

func (m *Matrix4) SetTransform(pos Vector3, quat Quat, scale Vector3)

SetTransform sets this matrix to a transformation matrix for the specified position, rotation specified by the quaternion and scale.

func (*Matrix4) SetTranslation

func (m *Matrix4) SetTranslation(x, y, z float32)

SetTranslation sets this matrix to a translation matrix from the specified x, y and z values.

func (*Matrix4) SetTranspose

func (m *Matrix4) SetTranspose()

SetTranspose transposes this matrix.

func (*Matrix4) SetVkFrustum

func (m *Matrix4) SetVkFrustum(left, right, bottom, top, near, far float32)

SetVkFrustum sets this matrix to a projection frustum matrix bounded by the specified planes. This version is for use with Vulkan, and does the equivalent of GLM_DEPTH_ZERO_ONE in glm and also multiplies the Y axis by -1, preserving the original OpenGL Y-up system. OpenGL provides a "natural" coordinate system for the physical world so it is useful to retain that for the world system and just convert on the way out to the render using this projection matrix.

func (*Matrix4) SetVkPerspective

func (m *Matrix4) SetVkPerspective(fov, aspect, near, far float32)

SetVkPerspective sets this matrix to a vulkan appropriate perspective projection matrix, assuming the use of the OpenGL Y-up coordinate system for the geometry points. OpenGL provides a "natural" coordinate system for the physical world so it is useful to retain that for the world system and just convert on the way out to the render using this projection matrix. The specified field of view is in degrees, aspect ratio (width/height) and near and far planes.

func (*Matrix4) SetZero

func (m *Matrix4) SetZero()

SetZero sets this matrix as the zero matrix.

func (*Matrix4) ToArray

func (m *Matrix4) ToArray(array []float32, offset int)

ToArray copies this matrix elements to array starting at offset.

func (*Matrix4) Transpose

func (m *Matrix4) Transpose() *Matrix4

Transpose returns the transpose of this matrix.

type Plane

type Plane struct {
	Norm Vector3
	Off  float32
}

Plane represents a plane in 3D space by its normal vector and a constant offset. When the the normal vector is the unit vector the offset is the distance from the origin.

func NewPlane

func NewPlane(normal Vector3, offset float32) *Plane

NewPlane creates and returns a new plane from a normal vector and a offset.

func (*Plane) CoplanarPoint

func (p *Plane) CoplanarPoint() Vector3

CoplanarPoint returns a point in the plane that is the closest point from the origin.

func (*Plane) DistanceToPoint added in v0.1.4

func (p *Plane) DistanceToPoint(point Vector3) float32

DistanceToPoint returns the distance of this plane from point.

func (*Plane) DistanceToSphere added in v0.1.4

func (p *Plane) DistanceToSphere(sphere Sphere) float32

DistanceToSphere returns the distance of this place from the sphere.

func (*Plane) IntersectLine

func (p *Plane) IntersectLine(line Line3) (Vector3, bool)

IntersectLine calculates the point in the plane which intersets the specified line. Returns false if the line does not intersects the plane.

func (*Plane) IsIntersectionLine

func (p *Plane) IsIntersectionLine(line Line3) bool

IsIntersectionLine returns the line intersects this plane.

func (*Plane) Negate

func (p *Plane) Negate()

Negate negates this plane normal.

func (*Plane) Normalize

func (p *Plane) Normalize()

Normalize normalizes this plane normal vector and adjusts the offset. Note: will lead to a divide by zero if the plane is invalid.

func (*Plane) Set

func (p *Plane) Set(normal Vector3, offset float32)

Set sets this plane normal vector and offset.

func (*Plane) SetDims

func (p *Plane) SetDims(x, y, z, w float32)

SetDims sets this plane normal vector dimensions and offset.

func (*Plane) SetFromCoplanarPoints

func (p *Plane) SetFromCoplanarPoints(a, b, c Vector3)

SetFromCoplanarPoints sets this plane from three coplanar points.

func (*Plane) SetFromNormalAndCoplanarPoint

func (p *Plane) SetFromNormalAndCoplanarPoint(normal Vector3, point Vector3)

SetFromNormalAndCoplanarPoint sets this plane from a normal vector and a point on the plane.

func (*Plane) SetTranslate

func (p *Plane) SetTranslate(offset Vector3)

SetTranslate translates this plane in the direction of its normal by offset.

type Quat

type Quat struct {
	X float32
	Y float32
	Z float32
	W float32
}

Quat is quaternion with X,Y,Z and W components.

func NewQuat

func NewQuat(x, y, z, w float32) Quat

NewQuat returns a new quaternion from the specified components.

func NewQuatAxisAngle

func NewQuatAxisAngle(axis Vector3, angle float32) Quat

NewQuatAxisAngle returns a new quaternion from given axis and angle rotation (radians).

func NewQuatEuler

func NewQuatEuler(euler Vector3) Quat

NewQuatEuler returns a new quaternion from given Euler angles.

func (*Quat) Conjugate

func (q *Quat) Conjugate() Quat

Conjugate returns the conjugate of this quaternion.

func (*Quat) Dot

func (q *Quat) Dot(other Quat) float32

Dot returns the dot products of this quaternion with other.

func (*Quat) FromArray

func (q *Quat) FromArray(array []float32, offset int)

FromArray sets this quaternion's components from array starting at offset.

func (*Quat) GenGoNew

func (q *Quat) GenGoNew() string

GenGoNew returns code to create new

func (*Quat) GenGoSet

func (q *Quat) GenGoSet(path string) string

GenGoSet returns code to set values in object at given path (var.member etc)

func (*Quat) Inverse

func (q *Quat) Inverse() Quat

Inverse returns the inverse of this quaternion.

func (*Quat) IsIdentity

func (q *Quat) IsIdentity() bool

IsIdentity returns if this is an identity quaternion.

func (*Quat) IsNil

func (q *Quat) IsNil() bool

IsNil returns true if all values are 0 (uninitialized).

func (Quat) Length

func (q Quat) Length() float32

Length returns the length of this quaternion

func (Quat) LengthSq

func (q Quat) LengthSq() float32

LengthSq returns this quanternion's length squared

func (*Quat) Mul

func (q *Quat) Mul(other Quat) Quat

Mul returns returns multiplication of this quaternion with other

func (*Quat) MulQuats

func (q *Quat) MulQuats(a, b Quat)

MulQuats set this quaternion to the multiplication of a by b.

func (*Quat) Normalize

func (q *Quat) Normalize()

Normalize normalizes this quaternion.

func (*Quat) NormalizeFast

func (q *Quat) NormalizeFast()

NormalizeFast approximates normalizing this quaternion. Works best when the quaternion is already almost-normalized.

func (*Quat) Set

func (q *Quat) Set(x, y, z, w float32)

Set sets this quaternion's components.

func (*Quat) SetConjugate

func (q *Quat) SetConjugate()

SetConjugate sets this quaternion to its conjugate.

func (*Quat) SetFromAxisAngle

func (q *Quat) SetFromAxisAngle(axis Vector3, angle float32)

SetFromAxisAngle sets this quaternion with the rotation specified by the given axis and angle.

func (*Quat) SetFromEuler

func (q *Quat) SetFromEuler(euler Vector3)

SetFromEuler sets this quaternion from the specified vector with Euler angles for each axis. It is assumed that the Euler angles are in XYZ order.

func (*Quat) SetFromRotationMatrix

func (q *Quat) SetFromRotationMatrix(m *Matrix4)

SetFromRotationMatrix sets this quaternion from the specified rotation matrix.

func (*Quat) SetFromUnitVectors

func (q *Quat) SetFromUnitVectors(vFrom, vTo Vector3)

SetFromUnitVectors sets this quaternion to the rotation from vector vFrom to vTo. The vectors must be normalized.

func (*Quat) SetIdentity

func (q *Quat) SetIdentity()

SetIdentity sets this quanternion to the identity quaternion.

func (*Quat) SetInverse

func (q *Quat) SetInverse()

SetInverse sets this quaternion to its inverse.

func (*Quat) SetMul

func (q *Quat) SetMul(other Quat)

SetMul sets this quaternion to the multiplication of itself by other.

func (*Quat) Slerp

func (q *Quat) Slerp(other Quat, t float32)

Slerp sets this quaternion to another quaternion which is the spherically linear interpolation from this quaternion to other using t.

func (Quat) String

func (q Quat) String() string

func (*Quat) ToArray

func (q *Quat) ToArray(array []float32, offset int)

ToArray copies this quaternions's components to array starting at offset.

func (*Quat) ToAxisAngle

func (q *Quat) ToAxisAngle() Vector4

ToAxisAngle returns the Vector4 holding axis and angle of this Quaternion

func (*Quat) ToEuler

func (q *Quat) ToEuler() Vector3

ToEuler returns a Vector3 with components as the Euler angles from the given quaternion.

type Ray

type Ray struct {
	Origin Vector3
	Dir    Vector3
}

Ray represents an oriented 3D line segment defined by an origin point and a direction vector.

func NewRay

func NewRay(origin, dir Vector3) *Ray

NewRay creates and returns a pointer to a Ray object with the specified origin and direction vectors. If a nil pointer is supplied for any of the parameters, the zero vector will be used.

func (*Ray) ApplyMatrix4

func (ray *Ray) ApplyMatrix4(mat4 *Matrix4)

MulMatrix4 multiplies this ray origin and direction by the specified matrix4, basically transforming this ray coordinates.

func (*Ray) At

func (ray *Ray) At(t float32) Vector3

At calculates the point in the ray which is at the specified t distance from the origin along its direction.

func (*Ray) ClosestPointToPoint

func (ray *Ray) ClosestPointToPoint(point Vector3) Vector3

ClosestPointToPoint calculates the point in the ray which is closest to the specified point.

func (*Ray) DistanceSquaredToPoint added in v0.1.4

func (ray *Ray) DistanceSquaredToPoint(point Vector3) float32

DistanceSquaredToPoint returns the smallest squared distance from the ray direction vector to the specified point. If the ray was pointed directly at the point this distance would be 0.

func (*Ray) DistanceSquaredToSegment added in v0.1.4

func (ray *Ray) DistanceSquaredToSegment(v0, v1 Vector3, optPointOnRay, optPointOnSegment *Vector3) float32

DistanceSquaredToSegment returns the smallest squared distance from this ray to the line segment from v0 to v1. If optPointOnRay Vector3 is not nil, it is set with the coordinates of the point on the ray. if optPointOnSegment Vector3 is not nil, it is set with the coordinates of the point on the segment.

func (*Ray) DistanceToPlane added in v0.1.4

func (ray *Ray) DistanceToPlane(plane Plane) float32

DistanceToPlane returns the distance of this ray origin to its intersection point in the plane. If the ray does not intersects the plane, returns NaN.

func (*Ray) DistanceToPoint added in v0.1.4

func (ray *Ray) DistanceToPoint(point Vector3) float32

DistanceToPoint returns the smallest distance from the ray direction vector to the specified point.

func (*Ray) IntersectBox

func (ray *Ray) IntersectBox(box Box3) (Vector3, bool)

IntersectBox calculates the point which is the intersection of this ray with the specified box. If no intersection is found false is returned.

func (*Ray) IntersectPlane

func (ray *Ray) IntersectPlane(plane Plane) (Vector3, bool)

IntersectPlane calculates the point which is the intersection of this ray with the specified plane. If no intersection is found false is returned.

func (*Ray) IntersectSphere

func (ray *Ray) IntersectSphere(sphere Sphere) (Vector3, bool)

IntersectSphere calculates the point which is the intersection of this ray with the specified sphere. If no intersection is found it returns false.

func (*Ray) IntersectTriangle

func (ray *Ray) IntersectTriangle(a, b, c Vector3, backfaceCulling bool) (Vector3, bool)

IntersectTriangle returns if this ray intersects the triangle with the face defined by points a, b, c. Returns true if it intersects and the point parameter with the intersected point coordinates. If backfaceCulling is false it ignores the intersection if the face is not oriented in the ray direction.

func (*Ray) IsIntersectPlane

func (ray *Ray) IsIntersectPlane(plane Plane) bool

IsIntersectPlane returns if this ray intersects the specified plane.

func (*Ray) IsIntersectionSphere

func (ray *Ray) IsIntersectionSphere(sphere Sphere) bool

IsIntersectionSphere returns if this ray intersects with the specified sphere.

func (*Ray) Recast

func (ray *Ray) Recast(t float32)

Recast sets the new origin of the ray at the specified distance t from its origin along its direction.

func (*Ray) Set

func (ray *Ray) Set(origin, dir Vector3)

Set sets the origin and direction vectors of this Ray.

type Sphere

type Sphere struct {
	Center Vector3 // center of the sphere
	Radius float32 // radius of the sphere
}

Sphere represents a 3D sphere defined by its center point and a radius

func NewSphere

func NewSphere(center Vector3, radius float32) *Sphere

NewSphere creates and returns a pointer to a new sphere with the specified center and radius.

func (*Sphere) ClampPoint

func (s *Sphere) ClampPoint(point Vector3) Vector3

ClampPoint clamps the specified point inside the sphere. If the specified point is inside the sphere, it is the clamped point. Otherwise the clamped point is the the point in the sphere surface in the nearest of the specified point.

func (*Sphere) ContainsPoint

func (s *Sphere) ContainsPoint(point Vector3) bool

ContainsPoint returns if this sphere contains the specified point.

func (*Sphere) DistanceToPoint added in v0.1.4

func (s *Sphere) DistanceToPoint(point Vector3) float32

DistanceToPoint returns the distance from the sphere surface to the specified point.

func (*Sphere) GetBoundingBox

func (s *Sphere) GetBoundingBox() Box3

GetBoundingBox calculates a Box3 which bounds this sphere.

func (*Sphere) IntersectSphere

func (s *Sphere) IntersectSphere(other Sphere) bool

IntersectSphere returns if other sphere intersects this one.

func (*Sphere) IsEmpty

func (s *Sphere) IsEmpty(sphere *Sphere) bool

IsEmpty checks if this sphere is empty (radius <= 0)

func (*Sphere) MulMatrix4

func (s *Sphere) MulMatrix4(mat *Matrix4)

MulMatrix4 applies the specified matrix transform to this sphere.

func (*Sphere) Set

func (s *Sphere) Set(center Vector3, radius float32)

Set sets the center and radius of this sphere.

func (*Sphere) SetFromBox

func (s *Sphere) SetFromBox(box Box3)

SetFromBox sets the center and radius of this sphere to surround given box

func (*Sphere) SetFromPoints

func (s *Sphere) SetFromPoints(points []Vector3, optCenter *Vector3)

SetFromPoints sets this sphere from the specified points array and optional center.

func (*Sphere) Translate

func (s *Sphere) Translate(offset Vector3)

Translate translates this sphere by the specified offset.

type Triangle

type Triangle struct {
	A Vector3
	B Vector3
	C Vector3
}

Triangle represents a triangle made of three vertices.

func NewTriangle

func NewTriangle(a, b, c Vector3) Triangle

NewTriangle returns a new Triangle object.

func (*Triangle) Area

func (t *Triangle) Area() float32

Area returns the triangle's area.

func (*Triangle) BarycoordFromPoint

func (t *Triangle) BarycoordFromPoint(point Vector3) Vector3

BarycoordFromPoint returns the barycentric coordinates for the specified point.

func (*Triangle) ContainsPoint

func (t *Triangle) ContainsPoint(point Vector3) bool

ContainsPoint returns whether the triangle contains a point.

func (*Triangle) Midpoint

func (t *Triangle) Midpoint() Vector3

Midpoint returns the triangle's midpoint.

func (*Triangle) Normal

func (t *Triangle) Normal() Vector3

Normal returns the triangle's normal.

func (*Triangle) Plane

func (t *Triangle) Plane() Plane

Plane returns a Plane object aligned with the triangle.

func (*Triangle) Set

func (t *Triangle) Set(a, b, c Vector3)

Set sets the triangle's three vertices.

func (*Triangle) SetFromPointsAndIndices

func (t *Triangle) SetFromPointsAndIndices(points []Vector3, i0, i1, i2 int)

SetFromPointsAndIndices sets the triangle's vertices based on the specified points and indices.

type Vector2

type Vector2 struct {
	X float32
	Y float32
}

Vector2 is a 2D vector/point with X and Y components.

func FromPoint added in v0.3.3

func FromPoint(pt image.Point) Vector2

FromPoint returns a new Vector2 from the given image.Point.

func Vec2

func Vec2(x, y float32) Vector2

Vec2 returns a new Vector2 with the given x and y components.

func Vector2FromFixed

func Vector2FromFixed(pt fixed.Point26_6) Vector2

Vector2FromFixed returns a new Vector2 from the given fixed.Point26_6.

func Vector2Scalar

func Vector2Scalar(scalar float32) Vector2

Vector2Scalar returns a new Vector2 with all components set to the given scalar value.

func (Vector2) Abs

func (v Vector2) Abs() Vector2

Abs returns the vector with Abs applied to each component.

func (Vector2) Add

func (v Vector2) Add(other Vector2) Vector2

Add adds the other given vector to this one and returns the result as a new vector.

func (Vector2) AddDim

func (a Vector2) AddDim(d Dims, value float32) Vector2

AddDim returns the vector with the given value added on the given dimension.

func (Vector2) AddScalar

func (v Vector2) AddScalar(s float32) Vector2

AddScalar adds scalar s to each component of this vector and returns new vector.

func (Vector2) AngleTo

func (v Vector2) AngleTo(other Vector2) float32

AngleTo returns the angle between this vector and other. Returns angles in range of -PI to PI (not 0 to 2 PI).

func (Vector2) Ceil

func (v Vector2) Ceil() Vector2

Ceil returns this vector with Ceil applied to each of its components.

func (*Vector2) Clamp

func (v *Vector2) Clamp(min, max Vector2)

Clamp sets this vector's components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max; if this assumption isn't true, it will not operate correctly.

func (Vector2) CosTo

func (v Vector2) CosTo(other Vector2) float32

CosTo returns the cosine (normalized dot product) between this vector and other.

func (Vector2) Cross

func (v Vector2) Cross(other Vector2) float32

Cross returns the cross product of this vector with other.

func (Vector2) Dim

func (v Vector2) Dim(dim Dims) float32

Dim returns the given vector component.

func (Vector2) DistanceTo added in v0.1.3

func (v Vector2) DistanceTo(other Vector2) float32

DistanceTo returns the distance between these two vectors as points.

func (Vector2) DistanceToSquared added in v0.1.3

func (v Vector2) DistanceToSquared(other Vector2) float32

DistanceToSquared returns the squared distance between these two vectors as points.

func (Vector2) Div

func (v Vector2) Div(other Vector2) Vector2

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vector2) DivDim

func (a Vector2) DivDim(d Dims, value float32) Vector2

DivDim returns the vector with the given value divided by on the given dimension.

func (Vector2) DivScalar

func (v Vector2) DivScalar(scalar float32) Vector2

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vector2) Dot

func (v Vector2) Dot(other Vector2) float32

Dot returns the dot product of this vector with the given other vector.

func (Vector2) Floor

func (v Vector2) Floor() Vector2

Floor returns this vector with Floor applied to each of its components.

func (*Vector2) FromSlice added in v0.1.3

func (v *Vector2) FromSlice(slice []float32, offset int)

FromSlice sets this vector's components from the given slice, starting at offset.

func (Vector2) InTriangle

func (v Vector2) InTriangle(p0, p1, p2 Vector2) bool

InTriangle returns whether the vector is inside the specified triangle.

func (Vector2) Length

func (v Vector2) Length() float32

Length returns the length (magnitude) of this vector.

func (Vector2) LengthSquared added in v0.1.3

func (v Vector2) LengthSquared() float32

LengthSquared returns the length squared of this vector. LengthSquared can be used to compare the lengths of vectors without the need to perform a square root.

func (Vector2) Lerp

func (v Vector2) Lerp(other Vector2, alpha float32) Vector2

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vector2) Max

func (v Vector2) Max(other Vector2) Vector2

Max returns max of this vector components vs. other vector.

func (Vector2) Min

func (v Vector2) Min(other Vector2) Vector2

Min returns min of this vector components vs. other vector.

func (Vector2) Mul

func (v Vector2) Mul(other Vector2) Vector2

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vector2) MulDim

func (a Vector2) MulDim(d Dims, value float32) Vector2

MulDim returns the vector with the given value multiplied by on the given dimension.

func (Vector2) MulScalar

func (v Vector2) MulScalar(s float32) Vector2

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vector2) Negate

func (v Vector2) Negate() Vector2

Negate returns the vector with each component negated.

func (Vector2) Normal

func (v Vector2) Normal() Vector2

Normal returns this vector divided by its length (its unit vector).

func (Vector2) Round

func (v Vector2) Round() Vector2

Round returns this vector with Round applied to each of its components.

func (*Vector2) Set

func (v *Vector2) Set(x, y float32)

Set sets this vector's X and Y components.

func (*Vector2) SetAdd

func (v *Vector2) SetAdd(other Vector2)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vector2) SetAddScalar

func (v *Vector2) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vector2) SetDim

func (v *Vector2) SetDim(dim Dims, value float32)

SetDim sets the given vector component value by its dimension index.

func (*Vector2) SetDiv

func (v *Vector2) SetDiv(other Vector2)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vector2) SetDivScalar

func (v *Vector2) SetDivScalar(scalar float32)

SetDivScalar sets this to division by scalar.

func (*Vector2) SetFixed

func (a *Vector2) SetFixed(pt fixed.Point26_6)

SetFixed sets the vector from the given fixed.Point26_6.

func (*Vector2) SetFromVector2i

func (v *Vector2) SetFromVector2i(vi Vector2i)

SetFromVector2i sets from a Vector2i (int32) vector.

func (*Vector2) SetMax

func (v *Vector2) SetMax(other Vector2)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vector2) SetMin

func (v *Vector2) SetMin(other Vector2)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vector2) SetMul

func (v *Vector2) SetMul(other Vector2)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vector2) SetMulScalar

func (v *Vector2) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vector2) SetPoint

func (a *Vector2) SetPoint(pt image.Point)

SetPoint sets the vector from the given image.Point.

func (*Vector2) SetScalar

func (v *Vector2) SetScalar(scalar float32)

SetScalar sets all vector components to the same scalar value.

func (*Vector2) SetSub

func (v *Vector2) SetSub(other Vector2)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vector2) SetSubScalar

func (v *Vector2) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vector2) SetZero

func (v *Vector2) SetZero()

SetZero sets all of the vector's components to zero.

func (Vector2) String

func (a Vector2) String() string

func (Vector2) Sub

func (v Vector2) Sub(other Vector2) Vector2

Sub subtracts other vector from this one and returns result in new vector.

func (Vector2) SubDim

func (a Vector2) SubDim(d Dims, value float32) Vector2

SubDim returns the vector with the given value subtracted on the given dimension.

func (Vector2) SubScalar

func (v Vector2) SubScalar(s float32) Vector2

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vector2) ToFixed added in v0.1.3

func (a Vector2) ToFixed() fixed.Point26_6

ToFixed returns the vector as a fixed.Point26_6.

func (Vector2) ToPoint

func (a Vector2) ToPoint() image.Point

ToPoint returns the vector as an image.Point.

func (Vector2) ToPointCeil

func (a Vector2) ToPointCeil() image.Point

ToPointCeil returns the vector as an image.Point with all values [Ceil]ed.

func (Vector2) ToPointFloor

func (a Vector2) ToPointFloor() image.Point

ToPointFloor returns the vector as an image.Point with all values [Floor]ed.

func (Vector2) ToPointRound

func (a Vector2) ToPointRound() image.Point

ToPointRound returns the vector as an image.Point with all values [Round]ed.

func (Vector2) ToSlice added in v0.1.3

func (v Vector2) ToSlice(slice []float32, offset int)

ToSlice copies this vector's components to the given slice, starting at offset.

func (Vector2) WindowToNDC

func (v Vector2) WindowToNDC(size, off Vector2, flipY bool) Vector3

WindowToNDC converts window (pixel) coordinates to normalized display coordinates (NDC), using given window size parameters. The Z depth coordinate (0-1) must be set manually or by reading from framebuffer flipY if true means flip the Y axis (top = 0 for windows vs. bottom = 0 for 3D coords)

type Vector2i

type Vector2i struct {
	X int32
	Y int32
}

Vector2i is a 2D vector/point with X and Y int32 components.

func Vec2i

func Vec2i(x, y int32) Vector2i

Vec2i returns a new Vector2i with the given x and y components.

func Vector2iScalar

func Vector2iScalar(scalar int32) Vector2i

Vector2iScalar returns a new Vector2i with all components set to the given scalar value.

func (Vector2i) Add

func (v Vector2i) Add(other Vector2i) Vector2i

Add adds the other given vector to this one and returns the result as a new vector.

func (Vector2i) AddScalar

func (v Vector2i) AddScalar(s int32) Vector2i

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vector2i) Clamp

func (v *Vector2i) Clamp(min, max Vector2i)

Clamp sets this vector's components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max; if this assumption isn't true, it will not operate correctly.

func (Vector2i) Dim

func (v Vector2i) Dim(dim Dims) int32

Dim returns the given vector component.

func (Vector2i) Div

func (v Vector2i) Div(other Vector2i) Vector2i

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vector2i) DivScalar

func (v Vector2i) DivScalar(scalar int32) Vector2i

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (*Vector2i) FromSlice added in v0.1.3

func (v *Vector2i) FromSlice(array []int32, offset int)

FromSlice sets this vector's components from the given slice, starting at offset.

func (Vector2i) Max

func (v Vector2i) Max(other Vector2i) Vector2i

Max returns max of this vector components vs. other vector.

func (Vector2i) Min

func (v Vector2i) Min(other Vector2i) Vector2i

Min returns min of this vector components vs. other vector.

func (Vector2i) Mul

func (v Vector2i) Mul(other Vector2i) Vector2i

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vector2i) MulScalar

func (v Vector2i) MulScalar(s int32) Vector2i

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vector2i) Negate

func (v Vector2i) Negate() Vector2i

Negate returns the vector with each component negated.

func (*Vector2i) Set

func (v *Vector2i) Set(x, y int32)

Set sets this vector X and Y components.

func (*Vector2i) SetAdd

func (v *Vector2i) SetAdd(other Vector2i)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vector2i) SetAddScalar

func (v *Vector2i) SetAddScalar(s int32)

SetAddScalar sets this to addition with scalar.

func (*Vector2i) SetDim

func (v *Vector2i) SetDim(dim Dims, value int32)

SetDim sets the given vector component value by its dimension index.

func (*Vector2i) SetDiv

func (v *Vector2i) SetDiv(other Vector2i)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vector2i) SetDivScalar

func (v *Vector2i) SetDivScalar(scalar int32)

SetDivScalar sets this to division by scalar.

func (*Vector2i) SetFromVector2

func (v *Vector2i) SetFromVector2(vf Vector2)

SetFromVector2 sets from a Vector2 (float32) vector.

func (*Vector2i) SetMax

func (v *Vector2i) SetMax(other Vector2i)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vector2i) SetMin

func (v *Vector2i) SetMin(other Vector2i)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vector2i) SetMul

func (v *Vector2i) SetMul(other Vector2i)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vector2i) SetMulScalar

func (v *Vector2i) SetMulScalar(s int32)

SetMulScalar sets this to multiplication by scalar.

func (*Vector2i) SetScalar

func (v *Vector2i) SetScalar(scalar int32)

SetScalar sets all vector components to the same scalar value.

func (*Vector2i) SetSub

func (v *Vector2i) SetSub(other Vector2i)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vector2i) SetSubScalar

func (v *Vector2i) SetSubScalar(s int32)

SetSubScalar sets this to subtraction of scalar.

func (*Vector2i) SetZero

func (v *Vector2i) SetZero()

SetZero sets all of the vector's components to zero.

func (Vector2i) Sub

func (v Vector2i) Sub(other Vector2i) Vector2i

Sub subtracts other vector from this one and returns result in new vector.

func (Vector2i) SubScalar

func (v Vector2i) SubScalar(s int32) Vector2i

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vector2i) ToSlice added in v0.1.3

func (v Vector2i) ToSlice(array []int32, offset int)

ToSlice copies this vector's components to the given slice, starting at offset.

type Vector3

type Vector3 struct {
	X float32
	Y float32
	Z float32
}

Vector3 is a 3D vector/point with X, Y and Z components.

func BarycoordFromPoint

func BarycoordFromPoint(point, a, b, c Vector3) Vector3

BarycoordFromPoint returns the barycentric coordinates for the specified point.

func NewEulerAnglesFromMatrix

func NewEulerAnglesFromMatrix(m *Matrix4) Vector3

NewEulerAnglesFromMatrix returns a Vector3 with components as the Euler angles from the specified pure rotation matrix.

func NewVector3Color

func NewVector3Color(clr color.Color) Vector3

NewVector3Color returns a Vector3 from Go standard color.Color (R,G,B components only)

func Normal

func Normal(a, b, c Vector3) Vector3

Normal returns the triangle's normal.

func Vec3

func Vec3(x, y, z float32) Vector3

Vec3 returns a new Vector3 with the given x, y and z components.

func Vector3FromVector4

func Vector3FromVector4(v Vector4) Vector3

Vector3FromVector4 returns a new Vector3 from the given Vector4.

func Vector3Scalar

func Vector3Scalar(scalar float32) Vector3

Vector3Scalar returns a new Vector3 with all components set to the given scalar value.

func (Vector3) Abs

func (v Vector3) Abs() Vector3

Abs returns the vector with Abs applied to each component.

func (Vector3) Add

func (v Vector3) Add(other Vector3) Vector3

Add adds the other given vector to this one and returns the result as a new vector.

func (Vector3) AddScalar

func (v Vector3) AddScalar(s float32) Vector3

AddScalar adds scalar s to each component of this vector and returns new vector.

func (Vector3) AngleTo

func (v Vector3) AngleTo(other Vector3) float32

AngleTo returns the angle between this vector and other. Returns angles in range of -PI to PI (not 0 to 2 PI).

func (Vector3) Ceil

func (v Vector3) Ceil() Vector3

Ceil returns this vector with Ceil applied to each of its components.

func (*Vector3) Clamp

func (v *Vector3) Clamp(min, max Vector3)

Clamp sets this vector's components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max; if this assumption isn't true, it will not operate correctly.

func (Vector3) CosTo

func (v Vector3) CosTo(other Vector3) float32

CosTo returns the cosine (normalized dot product) between this vector and other.

func (Vector3) Cross

func (v Vector3) Cross(other Vector3) Vector3

Cross returns the cross product of this vector with other.

func (Vector3) Dim

func (v Vector3) Dim(dim Dims) float32

Dim returns this vector component

func (Vector3) DistanceTo added in v0.1.3

func (v Vector3) DistanceTo(other Vector3) float32

DistanceTo returns the distance between these two vectors as points.

func (Vector3) DistanceToSquared added in v0.1.3

func (v Vector3) DistanceToSquared(other Vector3) float32

DistanceToSquared returns the squared distance between these two vectors as points.

func (Vector3) Div

func (v Vector3) Div(other Vector3) Vector3

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vector3) DivScalar

func (v Vector3) DivScalar(scalar float32) Vector3

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vector3) Dot

func (v Vector3) Dot(other Vector3) float32

Dot returns the dot product of this vector with the given other vector.

func (Vector3) Floor

func (v Vector3) Floor() Vector3

Floor returns this vector with Floor applied to each of its components.

func (*Vector3) FromSlice added in v0.1.3

func (v *Vector3) FromSlice(array []float32, offset int)

FromSlice sets this vector's components from the given slice, starting at offset.

func (*Vector3) GenGoSet

func (v *Vector3) GenGoSet(path string) string

GenGoSet returns code to set values in object at given path (var.member etc).

func (Vector3) Length

func (v Vector3) Length() float32

Length returns the length (magnitude) of this vector.

func (Vector3) LengthSquared added in v0.1.3

func (v Vector3) LengthSquared() float32

LengthSquared returns the length squared of this vector. LengthSquared can be used to compare the lengths of vectors without the need to perform a square root.

func (Vector3) Lerp

func (v Vector3) Lerp(other Vector3, alpha float32) Vector3

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vector3) Max

func (v Vector3) Max(other Vector3) Vector3

Max returns max of this vector components vs. other vector.

func (Vector3) Min

func (v Vector3) Min(other Vector3) Vector3

Min returns min of this vector components vs. other vector.

func (Vector3) Mul

func (v Vector3) Mul(other Vector3) Vector3

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vector3) MulMatrix3

func (v Vector3) MulMatrix3(m *Matrix3) Vector3

MulMatrix3 returns the vector multiplied by the given 3x3 matrix.

func (Vector3) MulMatrix4

func (v Vector3) MulMatrix4(m *Matrix4) Vector3

MulMatrix4 returns the vector multiplied by the given 4x4 matrix.

func (Vector3) MulMatrix4AsVector4

func (v Vector3) MulMatrix4AsVector4(m *Matrix4, w float32) Vector3

MulMatrix4AsVector4 returns 3-dim vector multiplied by specified 4x4 matrix using a 4-dim vector with given 4th dimensional value, then reduced back to a 3-dimensional vector. This is somehow different from just straight MulMatrix4 on the 3-dim vector. Use 0 for normals and 1 for positions as the 4th dim to set.

func (Vector3) MulProjection

func (v Vector3) MulProjection(m *Matrix4) Vector3

MulProjection returns vector multiplied by the projection matrix m.

func (Vector3) MulQuat

func (v Vector3) MulQuat(q Quat) Vector3

MulQuat returns vector multiplied by specified quaternion and then by the quaternion inverse. It basically applies the rotation encoded in the quaternion to this vector.

func (Vector3) MulScalar

func (v Vector3) MulScalar(s float32) Vector3

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vector3) NDCToWindow

func (v Vector3) NDCToWindow(size, off Vector2, near, far float32, flipY bool) Vector3

NDCToWindow converts normalized display coordinates (NDC) to window (pixel) coordinates, using given window size parameters. near, far are 0, 1 by default (glDepthRange defaults). flipY if true means flip the Y axis (top = 0 for windows vs. bottom = 0 for 3D coords)

func (Vector3) Negate

func (v Vector3) Negate() Vector3

Negate returns the vector with each component negated.

func (Vector3) Normal

func (v Vector3) Normal() Vector3

Normal returns this vector divided by its length (its unit vector).

func (*Vector3) ProjectOnPlane

func (v *Vector3) ProjectOnPlane(planeNormal Vector3) Vector3

ProjectOnPlane returns vector projected on the plane specified by normal vector.

func (*Vector3) ProjectOnVector

func (v *Vector3) ProjectOnVector(other Vector3) Vector3

ProjectOnVector returns vector projected on other vector.

func (*Vector3) RandomTangents

func (v *Vector3) RandomTangents() (Vector3, Vector3)

RandomTangents computes and returns two arbitrary tangents to the vector.

func (*Vector3) Reflect

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

Reflect returns vector reflected relative to the normal vector (assumed to be already normalized).

func (Vector3) Round

func (v Vector3) Round() Vector3

Round returns this vector with Round applied to each of its components.

func (Vector3) SRGBFromLinear

func (v Vector3) SRGBFromLinear() Vector3

SRGBFromLinear returns an SRGB color space value from a linear source

func (Vector3) SRGBToLinear

func (v Vector3) SRGBToLinear() Vector3

SRGBToLinear returns a linear color space value from a SRGB source

func (*Vector3) Set

func (v *Vector3) Set(x, y, z float32)

Set sets this vector X, Y and Z components.

func (*Vector3) SetAdd

func (v *Vector3) SetAdd(other Vector3)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vector3) SetAddScalar

func (v *Vector3) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vector3) SetColor

func (v *Vector3) SetColor(clr color.Color)

SetColor sets from Go standard color.Color (R,G,B components only)

func (*Vector3) SetDim

func (v *Vector3) SetDim(dim Dims, value float32)

SetDim sets this vector component value by dimension index.

func (*Vector3) SetDiv

func (v *Vector3) SetDiv(other Vector3)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vector3) SetDivScalar

func (v *Vector3) SetDivScalar(scalar float32)

SetDivScalar sets this to division by scalar.

func (*Vector3) SetEulerAnglesFromMatrix

func (v *Vector3) SetEulerAnglesFromMatrix(m *Matrix4)

SetEulerAnglesFromMatrix sets this vector components to the Euler angles from the specified pure rotation matrix.

func (*Vector3) SetEulerAnglesFromQuat

func (v *Vector3) SetEulerAnglesFromQuat(q Quat)

SetEulerAnglesFromQuat sets this vector components to the Euler angles from the specified quaternion.

func (*Vector3) SetFromMatrixPos

func (v *Vector3) SetFromMatrixPos(m *Matrix4)

SetFromMatrixPos set this vector from the translation coordinates in the specified transformation matrix.

func (*Vector3) SetFromVector3i

func (v *Vector3) SetFromVector3i(vi Vector3i)

SetFromVector3i sets from a Vector3i (int32) vector.

func (*Vector3) SetFromVector4

func (v *Vector3) SetFromVector4(other Vector4)

SetFromVector4 sets this vector from a Vector4

func (*Vector3) SetMax

func (v *Vector3) SetMax(other Vector3)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vector3) SetMin

func (v *Vector3) SetMin(other Vector3)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vector3) SetMul

func (v *Vector3) SetMul(other Vector3)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vector3) SetMulScalar

func (v *Vector3) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vector3) SetNormal

func (v *Vector3) SetNormal()

SetNormal normalizes this vector so its length will be 1.

func (*Vector3) SetScalar

func (v *Vector3) SetScalar(scalar float32)

SetScalar sets all vector components to the same scalar value.

func (*Vector3) SetSub

func (v *Vector3) SetSub(other Vector3)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vector3) SetSubScalar

func (v *Vector3) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vector3) SetZero

func (v *Vector3) SetZero()

SetZero sets all of the vector's components to zero.

func (Vector3) String

func (a Vector3) String() string

func (Vector3) Sub

func (v Vector3) Sub(other Vector3) Vector3

Sub subtracts other vector from this one and returns result in new vector.

func (Vector3) SubScalar

func (v Vector3) SubScalar(s float32) Vector3

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vector3) ToSlice added in v0.1.3

func (v Vector3) ToSlice(array []float32, offset int)

ToSlice copies this vector's components to the given slice, starting at offset.

type Vector3i

type Vector3i struct {
	X int32
	Y int32
	Z int32
}

Vector3i is a 3D vector/point with X, Y and Z int32 components.

func Vec3i

func Vec3i(x, y, z int32) Vector3i

Vec3i returns a new Vector3i with the given x, y and y components.

func Vector3iScalar

func Vector3iScalar(scalar int32) Vector3i

Vector3iScalar returns a new Vector3i with all components set to the given scalar value.

func (Vector3i) Add

func (v Vector3i) Add(other Vector3i) Vector3i

Add adds the other given vector to this one and returns the result as a new vector.

func (Vector3i) AddScalar

func (v Vector3i) AddScalar(s int32) Vector3i

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vector3i) Clamp

func (v *Vector3i) Clamp(min, max Vector3i)

Clamp sets this vector's components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max; if this assumption isn't true, it will not operate correctly.

func (Vector3i) Dim

func (v Vector3i) Dim(dim Dims) int32

Dim returns the given vector component.

func (Vector3i) Div

func (v Vector3i) Div(other Vector3i) Vector3i

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vector3i) DivScalar

func (v Vector3i) DivScalar(scalar int32) Vector3i

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (*Vector3i) FromSlice added in v0.1.3

func (v *Vector3i) FromSlice(array []int32, offset int)

FromSlice sets this vector's components from the given slice, starting at offset.

func (Vector3i) Max

func (v Vector3i) Max(other Vector3i) Vector3i

Max returns max of this vector components vs. other vector.

func (Vector3i) Min

func (v Vector3i) Min(other Vector3i) Vector3i

Min returns min of this vector components vs. other vector.

func (Vector3i) Mul

func (v Vector3i) Mul(other Vector3i) Vector3i

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vector3i) MulScalar

func (v Vector3i) MulScalar(s int32) Vector3i

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vector3i) Negate

func (v Vector3i) Negate() Vector3i

Negate returns the vector with each component negated.

func (*Vector3i) Set

func (v *Vector3i) Set(x, y, z int32)

Set sets this vector X, Y and Z components.

func (*Vector3i) SetAdd

func (v *Vector3i) SetAdd(other Vector3i)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vector3i) SetAddScalar

func (v *Vector3i) SetAddScalar(s int32)

SetAddScalar sets this to addition with scalar.

func (*Vector3i) SetDim

func (v *Vector3i) SetDim(dim Dims, value int32)

SetDim sets the given vector component value by its dimension index.

func (*Vector3i) SetDiv

func (v *Vector3i) SetDiv(other Vector3i)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vector3i) SetDivScalar

func (v *Vector3i) SetDivScalar(scalar int32)

SetDivScalar sets this to division by scalar.

func (*Vector3i) SetFromVector3

func (v *Vector3i) SetFromVector3(vf Vector3)

SetFromVector3 sets from a Vector3 (float32) vector.

func (*Vector3i) SetMax

func (v *Vector3i) SetMax(other Vector3i)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vector3i) SetMin

func (v *Vector3i) SetMin(other Vector3i)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vector3i) SetMul

func (v *Vector3i) SetMul(other Vector3i)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vector3i) SetMulScalar

func (v *Vector3i) SetMulScalar(s int32)

SetMulScalar sets this to multiplication by scalar.

func (*Vector3i) SetScalar

func (v *Vector3i) SetScalar(scalar int32)

SetScalar sets all vector components to the same scalar value.

func (*Vector3i) SetSub

func (v *Vector3i) SetSub(other Vector3i)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vector3i) SetSubScalar

func (v *Vector3i) SetSubScalar(s int32)

SetSubScalar sets this to subtraction of scalar.

func (*Vector3i) SetZero

func (v *Vector3i) SetZero()

SetZero sets all of the vector's components to zero.

func (Vector3i) Sub

func (v Vector3i) Sub(other Vector3i) Vector3i

Sub subtracts other vector from this one and returns result in new vector.

func (Vector3i) SubScalar

func (v Vector3i) SubScalar(s int32) Vector3i

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vector3i) ToSlice added in v0.1.3

func (v Vector3i) ToSlice(array []int32, offset int)

ToSlice copies this vector's components to the given slice, starting at offset.

type Vector4

type Vector4 struct {
	X float32
	Y float32
	Z float32
	W float32
}

Vector4 is a vector/point in homogeneous coordinates with X, Y, Z and W components.

func NewVector4Color

func NewVector4Color(clr color.Color) Vector4

NewVector4Color returns a Vector4 from Go standard color.Color (full R,G,B,A components)

func Vec4

func Vec4(x, y, z, w float32) Vector4

Vec4 returns a new Vector4 with the given x, y, z, and w components.

func Vector4FromVector3

func Vector4FromVector3(v Vector3, w float32) Vector4

Vector4FromVector3 returns a new Vector4 from the given Vector3 and w component.

func Vector4Scalar

func Vector4Scalar(scalar float32) Vector4

Vector4Scalar returns a new Vector4 with all components set to the given scalar value.

func (Vector4) Add

func (v Vector4) Add(other Vector4) Vector4

Add adds the other given vector to this one and returns the result as a new vector.

func (Vector4) AddScalar

func (v Vector4) AddScalar(s float32) Vector4

AddScalar adds scalar s to each component of this vector and returns new vector.

func (Vector4) Ceil

func (v Vector4) Ceil() Vector4

Ceil returns this vector with Ceil applied to each of its components.

func (*Vector4) Clamp

func (v *Vector4) Clamp(min, max Vector4)

Clamp sets this vector's components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max; if this assumption isn't true, it will not operate correctly.

func (Vector4) Dim

func (v Vector4) Dim(dim Dims) float32

Dim returns this vector component.

func (Vector4) Div

func (v Vector4) Div(other Vector4) Vector4

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vector4) DivScalar

func (v Vector4) DivScalar(scalar float32) Vector4

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vector4) Dot

func (v Vector4) Dot(other Vector4) float32

Dot returns the dot product of this vector with the given other vector.

func (Vector4) Floor

func (v Vector4) Floor() Vector4

Floor returns this vector with Floor applied to each of its components.

func (*Vector4) FromSlice added in v0.1.3

func (v *Vector4) FromSlice(array []float32, offset int)

FromSlice sets this vector's components from the given slice, starting at offset.

func (Vector4) Length

func (v Vector4) Length() float32

Length returns the length (magnitude) of this vector.

func (Vector4) LengthSquared added in v0.1.3

func (v Vector4) LengthSquared() float32

LengthSquared returns the length squared of this vector. LengthSquared can be used to compare the lengths of vectors without the need to perform a square root.

func (Vector4) Lerp

func (v Vector4) Lerp(other Vector4, alpha float32) Vector4

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vector4) Max

func (v Vector4) Max(other Vector4) Vector4

Max returns max of this vector components vs. other vector.

func (Vector4) Min

func (v Vector4) Min(other Vector4) Vector4

Min returns min of this vector components vs. other vector.

func (Vector4) Mul

func (v Vector4) Mul(other Vector4) Vector4

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vector4) MulMatrix4

func (v Vector4) MulMatrix4(m *Matrix4) Vector4

MulMatrix4 returns vector multiplied by specified 4x4 matrix.

func (Vector4) MulScalar

func (v Vector4) MulScalar(s float32) Vector4

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vector4) Negate

func (v Vector4) Negate() Vector4

Negate returns the vector with each component negated.

func (Vector4) Normal

func (v Vector4) Normal() Vector4

Normal returns this vector divided by its length (its unit vector).

func (Vector4) PerspDiv

func (v Vector4) PerspDiv() Vector3

PerspDiv returns the 3-vector of normalized display coordinates (NDC) from given 4-vector By dividing by the 4th W component

func (Vector4) Round

func (v Vector4) Round() Vector4

Round returns this vector with Round applied to each of its components.

func (Vector4) SRGBFromLinear

func (v Vector4) SRGBFromLinear() Vector4

SRGBFromLinear returns an SRGB color space value from a linear source

func (Vector4) SRGBToLinear

func (v Vector4) SRGBToLinear() Vector4

SRGBToLinear returns a linear color space value from a SRGB source

func (*Vector4) Set

func (v *Vector4) Set(x, y, z, w float32)

Set sets this vector X, Y, Z and W components.

func (*Vector4) SetAdd

func (v *Vector4) SetAdd(other Vector4)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vector4) SetAddScalar

func (v *Vector4) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vector4) SetAxisAngleFromQuat

func (v *Vector4) SetAxisAngleFromQuat(q Quat)

SetAxisAngleFromQuat set this vector to be the axis (x, y, z) and angle (w) of a rotation specified the quaternion q. Assumes q is normalized.

func (*Vector4) SetColor

func (v *Vector4) SetColor(clr color.Color)

SetColor sets a Vector4 from Go standard color.Color

func (*Vector4) SetDim

func (v *Vector4) SetDim(dim Dims, value float32)

SetDim sets this vector component value by dimension index.

func (*Vector4) SetDiv

func (v *Vector4) SetDiv(other Vector4)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vector4) SetDivScalar

func (v *Vector4) SetDivScalar(s float32)

SetDivScalar sets this to division by scalar.

func (*Vector4) SetFromVector2

func (v *Vector4) SetFromVector2(other Vector2)

SetFromVector2 sets this vector from a Vector2 with 0,1 for Z,W

func (*Vector4) SetFromVector3

func (v *Vector4) SetFromVector3(other Vector3, w float32)

SetFromVector3 sets this vector from a Vector3 and W

func (*Vector4) SetMax

func (v *Vector4) SetMax(other Vector4)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vector4) SetMin

func (v *Vector4) SetMin(other Vector4)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vector4) SetMul

func (v *Vector4) SetMul(other Vector4)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vector4) SetMulScalar

func (v *Vector4) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vector4) SetNormal

func (v *Vector4) SetNormal()

SetNormal normalizes this vector so its length will be 1.

func (*Vector4) SetScalar added in v0.1.3

func (v *Vector4) SetScalar(scalar float32)

SetScalar sets all vector components to the same scalar value.

func (*Vector4) SetSub

func (v *Vector4) SetSub(other Vector4)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vector4) SetSubScalar

func (v *Vector4) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vector4) SetZero

func (v *Vector4) SetZero()

SetZero sets all of the vector's components to zero, except for the W component, which it sets to 1, as is standard.

func (Vector4) String

func (v Vector4) String() string

func (Vector4) Sub

func (v Vector4) Sub(other Vector4) Vector4

Sub subtracts other vector from this one and returns result in new vector.

func (Vector4) SubScalar

func (v Vector4) SubScalar(s float32) Vector4

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vector4) ToSlice added in v0.1.3

func (v Vector4) ToSlice(array []float32, offset int)

ToSlice copies this vector's components to the given slice, starting at offset.

Directories

Path Synopsis
Package minmax provides a struct that holds Min and Max values.
Package minmax provides a struct that holds Min and Max values.
Package vecint has vector types for emergent, including Vector2i which is a 2D vector with int values, using the API based on math32.Vector2i.
Package vecint has vector types for emergent, including Vector2i which is a 2D vector with int values, using the API based on math32.Vector2i.

Jump to

Keyboard shortcuts

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