geom

package
v0.0.0-...-cafe5d1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package geom defines common primiteves for creating objects in the 3D space.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dot

func Dot(v1, v2 Vector) (d float64)

Dot returns a float64, the dot product of v1 and v2.

func Len

func Len(v Vector) float64

Len returns a float64, the length of v.

Types

type Intersectable

type Intersectable interface {

	// Intersect returns true when `ray` intersects this object.
	Intersect(ray Ray) bool
}

Intersectable represents an object in the 3D space which can be tested for intersections with rays.

type Ray

type Ray struct {
	Origin    Vector
	Direction Vector
}

Ray represents a geometric ray defined by an origin point and direction vector.

func NewRay

func NewRay(origin, dir Vector) Ray

NewRay returns a ray defined by its origin point `origin` and direction `dir`.

type Vector

type Vector struct {
	// X, Y and Z are the coordinates of a point in each of the three
	// dimensions or alternatively the direction defined by a vector
	// with origin (0,0,0) and end at X, Y and Z.
	X, Y, Z float64
}

Vector represents a point or a direction vector in a 3D cartesian coordinate system.

func Add

func Add(v1, v2 Vector) (v Vector)

Add returns a Vector, the result of adding v2 and v1.

func Cross

func Cross(v1, v2 Vector) (v Vector)

Cross returns a Vector, the cross product of v1 and v2.

func Mul

func Mul(v Vector, n float64) (result Vector)

Mul returns a Vector, multiplied by the scalar value n.

func NewVector

func NewVector(x, y, z float64) Vector

NewVector returns a Vector with coordinates `x`, `y` and `z`.

func Sub

func Sub(v1, v2 Vector) (v Vector)

Sub returns a Vector, the result of subtracting v2 from v1.

Jump to

Keyboard shortcuts

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