g3

package module
v0.0.0-...-e1ba7b7 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2012 License: MIT Imports: 1 Imported by: 6

README

g3: 3d geometry in Go

Build Status

This package defines primitives like Point, Vector, Triangle (float64-based), as well as integer Node. It also has a basic support of a uniform Grid.

The immediate purpose of this library is to be a base for github.com/krasin/voxel. Theoretically, it also might be useful for other uses.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AdjNodes26 = adjNodes26()

AdjNodes26 is the list of all 26 adjacent nodes of ZeroNode.

View Source
var AdjNodes6 = []Node{
	{0, 0, -1},
	{0, 0, 1},
	{0, -1, 0},
	{0, 1, 0},
	{-1, 0, 0},
	{1, 0, 0},
}
View Source
var ZeroNode = Node{0, 0, 0}

Functions

This section is empty.

Types

type Grid

type Grid struct {
	P0 Point
	H  float64
	N  int
}

Grid is a uniform grid NxNxN with step H in the cube with smallest point P0.

func (Grid) At

func (g Grid) At(node Node) Point

func (Grid) Node

func (g Grid) Node(p Point) Node

func (Grid) Side

func (g Grid) Side() float64

type Node

type Node [3]int

Node is a point in 3d space with integer coordinates. It also might be a node in a Grid.

func (Node) Add

func (node Node) Add(another Node) Node

Add returns a sum of node and another node.

func (Node) IsZero

func (node Node) IsZero() bool

IsZero returns if node is { 0, 0, 0 }

func (Node) Point

func (node Node) Point() Point

Point converts Node to Point.

func (Node) Sub

func (node Node) Sub(another Node) Node

Sub returns a difference between node and another node.

func (Node) Vector

func (node Node) Vector() Vector

Vector converts Node to Vector.

type Point

type Point [3]float64

Point is a point in 3d space.

func (Point) Sub

func (p Point) Sub(p2 Point) Point

type ScalarField

type ScalarField func(p Point) float64

ScalarField is a function that returns a value for every given point in 3d space.

type Triangle

type Triangle [3]Point

Triangle is a triangle in 3d space with a normal defined by the order of vertices. See http://www.opengl.org/wiki/Calculating_a_Surface_Normal

type Vector

type Vector [3]float64

Vector is a vector in 3d space.

func (Vector) L2

func (vec Vector) L2() float64

L2 calculates L2 norm of vector (aka length)

func (Vector) Normalize

func (vec Vector) Normalize() Vector

Normalize returns a vector that points to the same direction but has L2 norm equals to 1. It will panic on Zero vector and will be out of precision for small vectors.

Jump to

Keyboard shortcuts

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