math2

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package math2 provides 2D math helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Angle

type Angle float64

Angle helper type.

func GetAngle

func GetAngle(origin, p1, p2 Point) Angle

GetAngle returns the angle between lines origin->p1 and origin->p2.

func NewDegAngle

func NewDegAngle[T ~int | ~float32 | ~float64](degrees T) Angle

NewDegAngle returns a new angle from a degrees values.

func NewRadAngle

func NewRadAngle[T ~int | ~float32 | ~float64](radians T) Angle

NewRadAngle returns a new angle from a radians value.

func (Angle) Between

func (a Angle) Between(start, end Angle) bool

Between checks if the angle is in between the parameter range.

func (Angle) Degrees

func (a Angle) Degrees() float64

Degrees returns the degress value of the angle.

func (Angle) Normalize

func (a Angle) Normalize() Angle

Normalize the angle on -pi to +pi. i.e. 270 degrees -> -90 degrees.

func (Angle) Radians

func (a Angle) Radians() float64

Radians returns the radians value of the angle.

func (Angle) String

func (a Angle) String() string

String in degrees.

type Point

type Point struct{ X, Y float64 }

Point represents a 2D point.

func CoordinatesFromAngleDist

func CoordinatesFromAngleDist(origin, p1 Point, a Angle, length float64) Point

CoordinatesFromAngleDist returns the coordinates from 0,0 of a point p1 offseted by origin from an angle and length.

func Pt

func Pt[T ~int | ~float32 | ~float64](x, y T) Point

Pt is a helper to create a point.

func Rotate

func Rotate(p Point, alpha Angle, origin Point) Point

Rotate the point around origin by angle.

func Scale

func Scale[T ~int | ~float32 | ~float64](p Point, n T) Point

Scale is a generic helper wrapping p.Scale(n).

func (Point) Add

func (p Point) Add(p2 Point) Point

Add p2 to p.

func (Point) CoordinatesFromAngleDist

func (p Point) CoordinatesFromAngleDist(a Angle, length float64) Point

CoordinatesFromAngleDist returns the coordinates from 0,0 of the point from an angle and length.

func (Point) Div

func (p Point) Div(p2 Point) Point

Div p with p2. NOTE: Go handles div by 0 by setting the value to Inf.

func (Point) GetAngle

func (p Point) GetAngle(p2 Point) Angle

GetAngle returns the angle between 0,0 -> p and 0,0 -> p2.

func (Point) Magnitude

func (p Point) Magnitude(p2 Point) float64

Magnitude returns the length of the line p->p2.

func (Point) Mul

func (p Point) Mul(p2 Point) Point

Mul p and p2.

func (Point) Norm

func (p Point) Norm() float64

Norm returns the point's norm. aka length aka magnitude aka hypot.

func (Point) Rotate

func (p Point) Rotate(alpha Angle) Point

Rotate the point by angle. See math2.Rotate to rotate around a given point.

func (Point) Scale

func (p Point) Scale(n float64) Point

Scale the point by the given factor.

func (Point) String

func (p Point) String() string

String representation.

func (Point) Sub

func (p Point) Sub(p2 Point) Point

Sub p2 from p.

Jump to

Keyboard shortcuts

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