geo

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: GPL-3.0 Imports: 3 Imported by: 1

Documentation

Overview

Package geo provides basic geometric constructs

Index

Constants

This section is empty.

Variables

View Source
var (
	// ZeroVector is a vector with the length of 0
	ZeroVector = Vec3{}
)

Functions

This section is empty.

Types

type Onb added in v0.0.7

type Onb struct {
	U Vec3
	V Vec3
	W Vec3
}

Onb is an Orthonormal Basis

func BuildOnbFromVec3 added in v0.0.7

func BuildOnbFromVec3(w Vec3) Onb

BuildOnbFromVec3 creates an Orthonormal Basis from the given vector

func (Onb) Local added in v0.0.7

func (o Onb) Local(a Vec3) Vec3

Local translates the given vector to the Orthonormal Basis

type Ray

type Ray struct {
	Origin            Vec3
	Direction         Vec3
	DirectionInverted Vec3
	Time              float64
}

Ray defines a ray of light used by the ray tracer

func NewRay added in v0.2.2

func NewRay(origin, direction Vec3, time float64) Ray

func (Ray) At

func (r Ray) At(distance float64) Vec3

At returns the position at a given length of the ray

type Vec3

type Vec3 struct {
	X float64
	Y float64
	Z float64
}

Vec3 is a 3 dimensional vector

func NewVec3

func NewVec3(x, y, z float64) Vec3

NewVec3 creates a new Vec3

func RandomCosineDirection added in v0.0.7

func RandomCosineDirection() Vec3

RandomCosineDirection generates a random vector similar to RandomUnitVector in that the length is always 1. But with a different distribution as it is generated by two random angles.

func RandomInHemisphere

func RandomInHemisphere(normal Vec3) Vec3

RandomInHemisphere creates a random Vec3 that is shorter than 1. And in the same general direction as given normal.

func RandomInUnitDisc

func RandomInUnitDisc() Vec3

RandomInUnitDisc creates a random Vec3 that is shorter than 1 And that has a Z value of 0

func RandomInUnitSphere

func RandomInUnitSphere() Vec3

RandomInUnitSphere creates a random Vec3 that is shorter than 1

func RandomUnitVector

func RandomUnitVector() Vec3

RandomUnitVector creates a random Vec3 that has the length of 1

func RandomVec3

func RandomVec3(min float64, max float64) Vec3

RandomVec3 creates a random Vec3 within the given interval

func (Vec3) Add

func (v Vec3) Add(w Vec3) Vec3

Add returns a Vec3 that has all values added with corresponding value in given w Vec3

func (Vec3) Axis added in v1.0.0

func (v Vec3) Axis(a int) float64

Axis returns value of a numbered axis

func (Vec3) Cross

func (v Vec3) Cross(w Vec3) Vec3

Cross returns the cross product with given Vec3 w

func (Vec3) DivS

func (v Vec3) DivS(t float64) Vec3

DivS returns a Vec3 that has all values divided by given scalar t

func (Vec3) Dot

func (v Vec3) Dot(w Vec3) float64

Dot returns the dot product with given Vec3 w

func (Vec3) Length

func (v Vec3) Length() float64

Length return the length of the vector

func (Vec3) LengthSquared

func (v Vec3) LengthSquared() float64

LengthSquared return the length squared of the vector

func (Vec3) Mul

func (v Vec3) Mul(w Vec3) Vec3

Mul returns a Vec3 that has all values multiplied with corresponding value in given w Vec3

func (Vec3) MulS

func (v Vec3) MulS(t float64) Vec3

MulS returns a Vec3 that has all values multiplied with given scalar t

func (Vec3) NearZero

func (v Vec3) NearZero() bool

NearZero checks if the vectors length is near zero

func (Vec3) Neg

func (v Vec3) Neg() Vec3

Neg returns a Vec3 that has all values negated

func (Vec3) Reflect

func (v Vec3) Reflect(n Vec3) Vec3

Reflect returns the reflection vector given the normal n

func (Vec3) Refract

func (v Vec3) Refract(n Vec3, indexOfRefraction float64) Vec3

Refract returns the refraction vector given the normal n and the index of refraction of the material

func (Vec3) Sub

func (v Vec3) Sub(w Vec3) Vec3

Sub returns a Vec3 that has all values subtracted by corresponding value in given w Vec3

func (Vec3) Unit

func (v Vec3) Unit() Vec3

Unit returns the vector but sized to a length of 1

Jump to

Keyboard shortcuts

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