r2

package
v0.8.14 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 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 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

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 Vec

type Vec struct {
	X, Y float64
}

Vec is a 2D vector.

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.

func (Vec) Cross

func (p Vec) Cross(q Vec) float64

Cross returns the cross product p×q.

func (Vec) Dot

func (p Vec) Dot(q Vec) float64

Dot returns the dot product p·q.

func (Vec) Scale

func (p Vec) Scale(f float64) Vec

Scale returns the vector p scaled by f.

func (Vec) Sub

func (p Vec) Sub(q Vec) Vec

Sub returns the vector sum of p and -q.

Jump to

Keyboard shortcuts

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