geometry

package
v0.0.0-...-5ed2699 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dot

func Dot(v1 Vec3, v2 Vec3) float64

Dot returns the dot product (a scalar) of 2 vectors

Types

type Point3

type Point3 struct {
	X, Y, Z float64
}

Point3 defines a point in 3D space

func (Point3) Sub

func (p Point3) Sub(p2 Point3) Vec3

Sub subtracts a point to another Point which gives a vector

func (Point3) Translate

func (p Point3) Translate(v Vec3) Point3

Translate translates the point to a new location (return a new point)

func (Point3) Vec3

func (p Point3) Vec3() Vec3

Vec3 converts a point to a vector (centered at origin)

type Ray

type Ray struct {
	Origin    Point3
	Direction Vec3
	Rnd       utils.Rnd
}

func (*Ray) PointAt

func (r *Ray) PointAt(t float64) Point3

PointAt returns a new point along the ray (0 will return the origin)

type Vec3

type Vec3 struct {
	X, Y, Z float64
}

Vec3 defines a vector in 3D space

func Cross

func Cross(v1 Vec3, v2 Vec3) Vec3

Cross returns the cross product of 2 vectors (another vector)

func Random

func Random(rnd utils.Rnd) Vec3

func RandomInUnitDisk

func RandomInUnitDisk(rnd utils.Rnd) Vec3

func RandomInUnitSphere

func RandomInUnitSphere(rnd utils.Rnd) Vec3

func RandomInt

func RandomInt(rnd utils.Rnd, interval *utils.Interval) Vec3

func RandomUnitSphere

func RandomUnitSphere(rnd utils.Rnd) Vec3

func (Vec3) Add

func (v Vec3) Add(v2 Vec3) Vec3

Add adds the 2 vectors (return a new vector)

func (Vec3) Length

func (v Vec3) Length() float64

Length returns the size of the vector

func (Vec3) LengthSq

func (v Vec3) LengthSq() float64

LengthSq returns the squared size of the vector

func (Vec3) Mult

func (v Vec3) Mult(v2 Vec3) Vec3

Mult multiplies the vector by the other one (return a new vector)

func (Vec3) NearZero

func (v Vec3) NearZero() bool

func (Vec3) Negate

func (v Vec3) Negate() Vec3

Negate returns a new vector with X/Y/Z negated

func (Vec3) Reflect

func (v Vec3) Reflect(n Vec3) Vec3

Reflect simply reflects the vector based on the normal n

func (Vec3) Refract

func (v Vec3) Refract(n Vec3, niOverNt float64) (bool, *Vec3)

Refract returns a refracted vector (or not if there is no refraction possible)

func (Vec3) Scale

func (v Vec3) Scale(t float64) Vec3

Scale scales the vector by the value (return a new vector)

func (Vec3) Sub

func (v Vec3) Sub(v2 Vec3) Vec3

Sub substracts the 2 vectors (return a new vector)

func (Vec3) Unit

func (v Vec3) Unit() Vec3

Unit returns a new vector with same direction and length 1

Jump to

Keyboard shortcuts

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