r2

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: BSD-3-Clause Imports: 1 Imported by: 50

Documentation

Overview

Package r2 provides 2D vectors and boxes and operations on them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cos added in v0.8.0

func Cos(p, q Vec) float64

Cos returns the cosine of the opening angle between p and q.

func Cross added in v0.9.0

func Cross(p, q Vec) float64

Cross returns the cross product p×q.

func Dot added in v0.9.0

func Dot(p, q Vec) float64

Dot returns the dot product p·q.

func Norm added in v0.8.0

func Norm(p Vec) float64

Norm returns the Euclidean norm of p

|p| = sqrt(p_x^2 + p_y^2).

func Norm2 added in v0.8.0

func Norm2(p Vec) float64

Norm returns the Euclidean squared norm of p

|p|^2 = p_x^2 + p_y^2.

Types

type Box

type Box struct {
	Min, Max Vec
}

Box is a 2D bounding box.

type Rotation added in v0.9.0

type Rotation struct {
	// contains filtered or unexported fields
}

Rotation describes a rotation in 2D.

func NewRotation added in v0.9.0

func NewRotation(alpha float64, p Vec) Rotation

NewRotation creates a rotation by alpha, around p.

func (Rotation) Rotate added in v0.9.0

func (r Rotation) Rotate(p Vec) Vec

Rotate returns the rotated vector according to the definition of rot.

type Vec

type Vec struct {
	X, Y float64
}

Vec is a 2D vector.

func Add added in v0.9.0

func Add(p, q Vec) Vec

Add returns the vector sum of p and q.

func Rotate added in v0.9.0

func Rotate(p Vec, alpha float64, q Vec) Vec

Rotate returns a new vector, rotated by alpha around the provided point, q.

func Scale added in v0.9.0

func Scale(f float64, p Vec) Vec

Scale returns the vector p scaled by f.

func Sub added in v0.9.0

func Sub(p, q Vec) Vec

Sub returns the vector sum of p and -q.

func Unit added in v0.8.0

func Unit(p Vec) Vec

Unit returns the unit vector colinear to p. Unit returns {NaN,NaN} for the zero vector.

func (Vec) Add

func (p Vec) Add(q Vec) Vec

Add returns the vector sum of p and q.

DEPRECATED: use r2.Add.

func (Vec) Cross added in v0.8.0

func (p Vec) Cross(q Vec) float64

Cross returns the cross product p×q.

DEPRECATED: use r2.Cross.

func (Vec) Dot added in v0.8.0

func (p Vec) Dot(q Vec) float64

Dot returns the dot product p·q.

DEPRECATED: use r2.Dot.

func (Vec) Rotate added in v0.9.0

func (p Vec) Rotate(alpha float64, q Vec) Vec

Rotate returns a new vector, rotated by alpha around the provided point, q.

DEPRECATED: use r2.Rotate.

func (Vec) Scale

func (p Vec) Scale(f float64) Vec

Scale returns the vector p scaled by f.

DEPRECATED: use r2.Scale.

func (Vec) Sub

func (p Vec) Sub(q Vec) Vec

Sub returns the vector sum of p and -q.

DEPRECATED: use r2.Sub.

Jump to

Keyboard shortcuts

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