geometry

package
v0.0.0-...-084007b Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: CC0-1.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FloatInRange

func FloatInRange(rnd Rnd, min float64, max float64) float64

Types

type Ray

type Ray struct {
	Origin    Vec
	Direction Unit
	Time      float64
	Rnd       Rnd
}

Ray represents a ray defined by its origin and direction

func NewRay

func NewRay(origin Vec, direction Unit, time float64, rnd Rnd) *Ray

NewRay creates a new ray with an origin and direction.

func (*Ray) At

func (r *Ray) At(t float64) Vec

At returns the ray at the given point.

type Rnd

type Rnd interface {
	Float64() float64
}

type Unit

type Unit struct {
	Vec
}

Unit represents a unit vector of length 1.

func NewUnit

func NewUnit(e0, e1, e2 float64) Unit

NewUnit creates a new Unit.

func RandUnit

func RandUnit(rnd Rnd) Unit

RandUnit returns a random unit vector.

func Refract

func Refract(u Unit, n Unit, ratio float64) (bool, *Unit)

Refract returns a refracted vector.

func (Unit) Dot

func (u Unit) Dot(u2 Unit) float64

Dot returns the dot product of two unit vectors.

func (Unit) Inv

func (u Unit) Inv() Unit

Inv returns the inverse of this unit vector as a new vector.

func (Unit) Reflect

func (u Unit) Reflect(n Unit) Unit

Reflect reflects this unit vector about a normal vector n.

type Vec

type Vec struct {
	X float64
	Y float64
	Z float64
}

Vec represents a 3-element vector.

func NewVec

func NewVec(e0, e1, e2 float64) Vec

NewVec creates a new Vec.

func RandVecInDisk

func RandVecInDisk(rnd Rnd) Vec

RandVecInDisk creates a random geometry.Vec within a unit disk.

func RandVecInSphere

func RandVecInSphere(rnd Rnd) Vec

RandVecInSphere creates a random geometry.Vec within a unit sphere.

This algorithm works by selecting a random vector inside the unit cube, and then discarding the vector if it falls outside the sphere. On average, we discard the vector 47.6% of the time.

func (Vec) Add

func (v Vec) Add(v2 Vec) Vec

Add returns the sum of two vectors.

func (Vec) Cross

func (v Vec) Cross(v2 Vec) Vec

Cross returns the cross-product of two vectors.

func (Vec) Div

func (v Vec) Div(v2 Vec) Vec

Div returns the division of two vectors.

func (Vec) Dot

func (v Vec) Dot(v2 Vec) float64

Dot returns the dot product of two unit vectors.

func (Vec) Inv

func (v Vec) Inv() Vec

Inv returns the inverse of the vector as a new vector.

func (Vec) Len

func (v Vec) Len() float64

Len returns the vector's length.

func (Vec) LenSquared

func (v Vec) LenSquared() float64

LenSquared returns the square of the vector's length.

func (Vec) Max

func (v Vec) Max(v2 Vec) Vec

Max returns a new Vector using the largest elements of two vectors.

func (Vec) Min

func (v Vec) Min(v2 Vec) Vec

Min returns a new Vector using the smallest elements of two vectors.

func (Vec) Mul

func (v Vec) Mul(v2 Vec) Vec

Mul returns the multiplication of two vectors.

func (Vec) Reflect

func (v Vec) Reflect(n Vec) Vec

Reflect reflects this unit vector about a normal vector n.

func (Vec) Scale

func (v Vec) Scale(n float64) Vec

Scale returns the vector scaled by a scalar.

func (Vec) Sub

func (v Vec) Sub(v2 Vec) Vec

Sub returns the difference of two vectors.

func (Vec) ToUnit

func (v Vec) ToUnit() Unit

ToUnit converts the vector to a unit vector.

func (Vec) Zero

func (v Vec) Zero() bool

Zero returns whether this is a zero vector.

Jump to

Keyboard shortcuts

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