vector

package module
v0.0.0-...-461ee96 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2014 License: MIT Imports: 3 Imported by: 0

README

vector

2D (for now) Vector Library in Go

Documentation

Index

Constants

View Source
const Deg2rad = math.Pi / 180
View Source
const Epsilon = 1e-7
View Source
const Rad2deg = 180 / math.Pi

Variables

This section is empty.

Functions

func Angle

func Angle(v1, v2 Vector2d) float64

returns radians

func Distance

func Distance(p1, p2 Point2d) float64

func IntervalDistance

func IntervalDistance(p1min, p1max, p2min, p2max float64) float64

func PointInPolygon

func PointInPolygon(p Point2d, py Polygon2d) bool

func PointInRect

func PointInRect(p Point2d, r AABB2d) bool

func ProjectPolygon

func ProjectPolygon(axis Vector2d, p Polygon2d) (min float64, max float64)

func RectRectIntersection

func RectRectIntersection(r1 AABB2d, r2 AABB2d) bool

Types

type AABB2d

type AABB2d struct {
	A Point2d `json:"A"`
	B Point2d `json:"B"`
}

A and B represent two opposite corners of axis-aligned boundin box

func AASquareAtPoint

func AASquareAtPoint(p Point2d, edgeLength float64) AABB2d

func (AABB2d) ToPolygon

func (r AABB2d) ToPolygon() Polygon2d

type Point2d

type Point2d struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

func Extrapolate

func Extrapolate(P []Point2d) (*Point2d, error)

explicitly implements Neville's algorithm for three points at very particular parameter values: ts[]{0, 1/3, 2/3}, extrapolate to 1.

func Intersection

func Intersection(p1, p2 Point2d, v1, v2 Vector2d) (bool, *Point2d)

func Neville

func Neville(P []Point2d, ts []float64, t float64) (*Point2d, error)

Implements Neville's Algorithm for a slice of points (P) at parameter values(ts), to parameter value (t). Returns the point and an error

func PolygonIntersection

func PolygonIntersection(r Polygon2d, p Point2d, v Vector2d) (bool, *Point2d)

func RectIntersection

func RectIntersection(r AABB2d, p Point2d, v Vector2d) (bool, bool, *Point2d)

returns collision, inside, point of collision

func (Point2d) Add

func (p Point2d) Add(v Vector2d) Point2d

func (Point2d) Sub

func (p1 Point2d) Sub(p2 Point2d) Vector2d

func (Point2d) ToVector

func (p Point2d) ToVector() Vector2d

type Polygon2d

type Polygon2d struct {
	Points  []Vector2d `json:"points"`
	Normals []Vector2d `json:"normals"`
	Origin  Point2d    `json:"origin"`
}

func OrientedSquare

func OrientedSquare(center Point2d, heading Vector2d, size float64) Polygon2d

func (Polygon2d) Edge

func (p Polygon2d) Edge(i int) (Point2d, Vector2d)

type Vector2d

type Vector2d struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

func PolyPolyIntersection

func PolyPolyIntersection(p1 Polygon2d, v1 Vector2d, p2 Polygon2d) (bool, bool, Vector2d)

returns intersect, will intersect, translation.Scale(minimum_interval_distance)

func (Vector2d) Cross

func (v1 Vector2d) Cross(v2 Vector2d) float64

func (Vector2d) Dot

func (v1 Vector2d) Dot(v2 Vector2d) float64

func (Vector2d) Mag

func (v Vector2d) Mag() float64

func (Vector2d) MagSquared

func (v Vector2d) MagSquared() float64

func (Vector2d) Normalize

func (v Vector2d) Normalize() Vector2d

func (Vector2d) PopPop

func (v Vector2d) PopPop() float64

func (Vector2d) Rotate

func (v1 Vector2d) Rotate(a float64) Vector2d

func (Vector2d) Scale

func (v Vector2d) Scale(s float64) Vector2d

func (Vector2d) ToPoint

func (v Vector2d) ToPoint() Point2d

Jump to

Keyboard shortcuts

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