r2

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: BSD-3-Clause Imports: 1 Imported by: 0

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

func Cos(p, q Vec) float64

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

func Cross

func Cross(p, q Vec) float64

Cross returns the cross product p×q.

func Dot

func Dot(p, q Vec) float64

Dot returns the dot product p·q.

func Norm

func Norm(p Vec) float64

Norm returns the Euclidean norm of p

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

func Norm2

func Norm2(p Vec) float64

Norm2 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

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

Rotation describes a rotation in 2D.

func NewRotation

func NewRotation(alpha float64, p Vec) Rotation

NewRotation creates a rotation by alpha, around p.

func (Rotation) Rotate

func (r Rotation) Rotate(p Vec) Vec

Rotate returns p rotated according to the parameters used to construct the receiver.

type Vec

type Vec struct {
	X, Y float64
}

Vec is a 2D vector.

func Add

func Add(p, q Vec) Vec

Add returns the vector sum of p and q.

func Rotate

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

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

func Scale

func Scale(f float64, p Vec) Vec

Scale returns the vector p scaled by f.

func Sub

func Sub(p, q Vec) Vec

Sub returns the vector sum of p and -q.

func Unit

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

func (p Vec) Cross(q Vec) float64

Cross returns the cross product p×q.

DEPRECATED: use r2.Cross.

func (Vec) Dot

func (p Vec) Dot(q Vec) float64

Dot returns the dot product p·q.

DEPRECATED: use r2.Dot.

func (Vec) Rotate

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