package r2
import "gonum.org/v1/gonum/spatial/r2"
Package r2 provides 2D vectors and boxes and operations on them.
Index ¶
- func Cos(p, q Vec) float64
- func Cross(p, q Vec) float64
- func Dot(p, q Vec) float64
- func Norm(p Vec) float64
- func Norm2(p Vec) float64
- type Box
- func NewBox(x0, y0, x1, y1 float64) Box
- func (a Box) Add(v Vec) Box
- func (b Box) Canon() Box
- func (a Box) Center() Vec
- func (a Box) Contains(v Vec) bool
- func (a Box) Empty() bool
- func (a Box) Scale(v Vec) Box
- func (a Box) Size() Vec
- func (a Box) Union(b Box) Box
- func (a Box) Vertices() []Vec
- type Rotation
- type Triangle
- func (t Triangle) Area() float64
- func (t Triangle) Centroid() Vec
- func (t Triangle) IsDegenerate(tol float64) bool
- type Vec
Functions ¶
func Cos ¶
Cos returns the cosine of the opening angle between p and q.
func Cross ¶
Cross returns the cross product p×q.
func Dot ¶
Dot returns the dot product p·q.
func Norm ¶
Norm returns the Euclidean norm of p
|p| = sqrt(p_x^2 + p_y^2).
func Norm2 ¶
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. Well formed Boxes have Min components smaller than Max components.
func NewBox ¶
NewBox is shorthand for Box{Min:Vec{x0,y0}, Max:Vec{x1,y1}}. The sides are swapped so that the resulting Box is well formed.
func (Box) Add ¶
Add adds v to the bounding box components. It is the equivalent of translating the Box by v.
func (Box) Canon ¶
Canon returns the canonical version of b. The returned Box has minimum and maximum coordinates swapped if necessary so that it is well-formed.
func (Box) Center ¶
Center returns the center of the Box.
func (Box) Contains ¶
Contains returns true if v is contained within the bounds of the Box.
func (Box) Empty ¶
Empty returns true if a Box's volume is zero or if a Min component is greater than its Max component.
func (Box) Scale ¶
Scale returns a new Box scaled by a size vector around its center. The scaling is done element wise, which is to say the Box's X size is scaled by v.X. Negative components of v are interpreted as zero.
func (Box) Size ¶
Size returns the size of the Box.
func (Box) Union ¶
Union returns a box enclosing both the receiver and argument Boxes.
func (Box) Vertices ¶
Vertices returns a slice of the 4 vertices corresponding to each of the Box's corners.
The order of the vertices is CCW in the XY plane starting at the box minimum. If viewing box from +Z position the ordering is as follows:
- Bottom left.
- Bottom right.
- Top right.
- Top left.
type Rotation ¶
type Rotation struct {
// contains filtered or unexported fields
}
Rotation describes a rotation in 2D.
func NewRotation ¶
NewRotation creates a rotation by alpha, around p.
func (Rotation) Rotate ¶
Rotate returns p rotated according to the parameters used to construct the receiver.
type Triangle ¶
type Triangle [3]Vec
Triangle represents a triangle in 2D space and is composed by 3 vectors corresponding to the position of each of the vertices.
func (Triangle) Area ¶
Area returns the surface area of the triangle.
func (Triangle) Centroid ¶
Centroid returns the intersection of the three medians of the triangle as a point in space.
func (Triangle) IsDegenerate ¶
IsDegenerate returns true if all of triangle's vertices are within tol distance of its longest side.
type Vec ¶
type Vec struct { X, Y float64 }
Vec is a 2D vector.
func Add ¶
Add returns the vector sum of p and q.
func Rotate ¶
Rotate returns a new vector, rotated by alpha around the provided point, q.
func Scale ¶
Scale returns the vector p scaled by f.
func Sub ¶
Sub returns the vector sum of p and -q.
func Unit ¶
Unit returns the unit vector colinear to p. Unit returns {NaN,NaN} for the zero vector.
Source Files ¶
box.go doc.go triangle.go vector.go
- Version
- v0.15.1 (latest)
- Published
- Aug 16, 2024
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 12 hours ago –
Tools for package owners.