Documentation ¶
Index ¶
- func Binomial(n, k int) int
- func BytePow(p int) byte
- func CCWEtoCWN(ccwe float64) float64
- func Dateday(t time.Time) time.Time
- func GradientDescent(A Matrix, B []float64, n int, alpha float64) []float64
- func IntPow(i, p int) int
- func LinearRegression(cs [][]float64) (m, b, r2 float64)
- func LinearTransform(l, h, u float64) float64
- func LogLinearTransform(l, h, u float64) float64
- func PnPoly(v [][]float64, p []float64) bool
- func PnPolyC(v []complex128, p complex128, tolerance float64) bool
- func PnPolyLong(v [][]float64, p []float64, tol float64) bool
- func Primes(k int) []int
- func QsortIndx(a QsortIndxInterface, prng *rand.Rand) []int
- func RelativeDifference(f0, f1 float64) float64
- func RoundRange(minVal, maxVal float64) (float64, float64)
- func RoundTo(f float64, places int) float64
- func RoundToValue(f, roundTo float64, roundUpDwn int) float64
- func SignificantFigure(f float64, sigFig int) float64
- func SortMapFloat(m map[int]float64, reverse bool) ([]int, []float64)
- func SortMapInt(m map[int]int) ([]int, []int)
- func ThomasBoundaryCondition(a, b, c, d, x map[int]float64, first, last int)
- func UniqueInts(input []int) []int
- func Wateryear(dt time.Time) int
- type BinaryNode
- type Circle
- type Extent
- type IndexedSlice
- type IntSlice
- type LineSegment
- type Matrix
- type Plane
- type Point
- type Polyline
- type PriorityQueue
- type Prism
- type QsortIndxInterface
- type QsortInterface
- type Triangle
- func (t *Triangle) Area() float64
- func (t *Triangle) BarycentricWeights(x, y float64) []float64
- func (t *Triangle) Circumcircle() *Circle
- func (t *Triangle) Contains(x, y float64) bool
- func (t *Triangle) EdgeLengths() []float64
- func (t *Triangle) MinMaxInteriorAngle() (float64, float64)
- func (t *Triangle) New(p0, p1, p2 []float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Binomial ¶
Binomial returns the binomial coefficient of (n,k), also commonly referred to as "n choose k".
The binomial coefficient, C(n,k), is the number of unordered combinations of k elements in a set that is n elements big, and is defined as
C(n,k) = n!/((n-k)!k!)
n and k must be non-negative with n >= k, otherwise Binomial will panic. No check is made for overflow.
func CCWEtoCWN ¶
CCWEtoCWN converts trig angles (counter-clockwise east) to clockwise north from https://math.stackexchange.com/questions/1589793/a-formula-to-convert-a-counter-clockwise-angle-to-clockwise-angle-with-an-offset: (−θ+90°) mod 360°: The negative on θ deals with the fact that we are changing from counterclockwise to clockwise. The +90° deals with the offset of ninety degrees. And lastly we need to mod by 360° to keep our angle in the desired range [0°,360°]
func GradientDescent ¶
GradientDescent is a first-order iterative optimization algorithm for finding the minimum of a function. used to solve for x in Ax=B from: https://stackoverflow.com/questions/16422287/linear-regression-library-for-go-language
func LinearRegression ¶
func LinearTransform ¶
LinearTransform linearly transforms U[0.0,1.0] to [l,h] space
func LogLinearTransform ¶
LogLinearTransform linearly transforms U[0.0,1.0] to 10^[l,h] space
func PnPolyC ¶
func PnPolyC(v []complex128, p complex128, tolerance float64) bool
PnPolyC determins whether a point lies within a polygon (using complex coordinates)
func PnPolyLong ¶
PnPolyLong determins whether a point lies within a polygon with more rigor: PnPoly requires the point to be completely within prism
func QsortIndx ¶
func QsortIndx(a QsortIndxInterface, prng *rand.Rand) []int
QsortIndx same as above, but preserves original slice index modified from: https://stackoverflow.com/questions/23276417/golang-custom-sort-is-faster-than-native-sort#23278451
func RelativeDifference ¶
RelativeDifference returns the relative difference between to values
func RoundRange ¶
RoundRange determines the likely range that encompasses the given values
func RoundToValue ¶
RoundToValue rounds to the nearest multiple of the given roundTo value
func SignificantFigure ¶
SignificantFigure converts the number to n significant figures ex: 1234567 to 1230000 at significant 3 figures
func SortMapFloat ¶
SortMapFloat returns the key-values sorted by value
func SortMapInt ¶
SortMapInt returns an IndexedSlice sorted by value
func ThomasBoundaryCondition ¶
ThomasBoundaryCondition is a Thomas algorithm solution which solves a tri-diagonal system of equations converted from python code in: Bittelli, M., Campbell, G.S., and Tomei, F., 2015. Soil Physics with Python. Oxford University Press.
func UniqueInts ¶
UniqueInts returns a unique subset of the int slice provided. from: https://kylewbanks.com/blog/creating-unique-slices-in-go
Types ¶
type BinaryNode ¶
type BinaryNode struct { Left *BinaryNode Right *BinaryNode Val float64 Indx int }
func (*BinaryNode) AddNode ¶
func (node *BinaryNode) AddNode(is *IndexedSlice, first, last int)
func (*BinaryNode) IndexOf ¶
func (n *BinaryNode) IndexOf(val float64) int
IndexOf -1: place at start; n: place at end; i: place after i, before i+1
func (*BinaryNode) Search ¶
func (n *BinaryNode) Search(val *float64, sid *int)
type IndexedSlice ¶
IndexedSlice alias to float array being sorted and interfaces to Go-native sort.Sort
func (IndexedSlice) Indices ¶
func (is IndexedSlice) Indices() []int
Indices returns the index property
func (IndexedSlice) Len ¶
func (is IndexedSlice) Len() int
func (IndexedSlice) Less ¶
func (is IndexedSlice) Less(i, j int) bool
func (*IndexedSlice) New ¶
func (is *IndexedSlice) New(v []float64)
New IndexSlice constructor, default indices
func (IndexedSlice) Partition ¶
func (is IndexedSlice) Partition(i int) (left QsortIndxInterface, right QsortIndxInterface)
Partition splits index array around pivot
func (IndexedSlice) Swap ¶
func (is IndexedSlice) Swap(i, j int)
type IntSlice ¶
type IntSlice []int
IntSlice : alias to index array being sorted
func (IntSlice) Partition ¶
func (is IntSlice) Partition(i int) (left QsortInterface, right QsortInterface)
Partition : splits index array around pivot
type LineSegment ¶
type LineSegment struct {
P0, P1 Point
// contains filtered or unexported fields
}
LineSegment represents a stright line between two points
func (*LineSegment) Build ¶
func (ls *LineSegment) Build()
func (*LineSegment) Intersection2D ¶
func (l0 *LineSegment) Intersection2D(l1 *LineSegment) (Point, float64)
Intersection2D returns the 2D intersection of two line segments. Returns nil if lines do not intersect.
func (*LineSegment) IntersectionX ¶
func (ls *LineSegment) IntersectionX(x float64) *Point
func (*LineSegment) IntersectionY ¶
func (ls *LineSegment) IntersectionY(y float64) *Point
func (*LineSegment) Intersects ¶
func (ls *LineSegment) Intersects(p Point, toWithin float64) bool
type Matrix ¶
type Matrix [][]float64
Matrix alias for a 2d slice
func (Matrix) GaussJordanElimination ¶
GaussJordanElimination is an algorithm for solving systems of linear equations. It is usually understood as a sequence of operations performed on the associated matrix of coefficients. This method can also be used to find the rank of a matrix, to calculate the determinant of a matrix, and to calculate the inverse of an invertible square matrix. from: http://www.sanfoundry.com/cpp-program-implement-gauss-jordan-elimination/
type Plane ¶
type Plane struct {
// contains filtered or unexported fields
}
Plane defined as: ax + by + cz + d = 0 normal vector is (-a,-b,1) slope = Sqrt(a ^ 2 + b ^ 2) aspect = Atan2(-b, -a) // Asin(-a / Sqrt(a ^ 2 + b ^ 2)) // theta = asin(-a/sqrt(a^2+b^2))
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue represents the queue
func NewPriorityQueue ¶
func NewPriorityQueue() PriorityQueue
NewPriorityQueue initializes an empty priority queue.
func (*PriorityQueue) Len ¶
func (p *PriorityQueue) Len() int
Len returns the number of elements in the queue.
func (*PriorityQueue) Pop ¶
func (p *PriorityQueue) Pop() (interface{}, error)
Pop removes the element with the highest priority from the queue and returns it. In case of an empty queue, an error is returned.
func (*PriorityQueue) Push ¶
func (p *PriorityQueue) Push(v interface{}, priority float64)
Push inserts a new element into the queue. No action is performed on duplicate elements.
func (*PriorityQueue) UpdatePriority ¶
func (p *PriorityQueue) UpdatePriority(x interface{}, newPriority float64)
UpdatePriority changes the priority of a given item. If the specified item is not present in the queue, no action is performed.
type Prism ¶
type Prism struct { Z []complex128 // complex coordinates Top, Bot, A float64 }
Prism struct represents a singular model prism
func (*Prism) Centroid ¶
func (q *Prism) Centroid() complex128
CentroidXY returns the coordinates of the prism centroid
func (*Prism) CentroidXY ¶
CentroidXY returns the coordinates of the prism centroid
func (*Prism) Contains ¶
Contains returns true if the given particle is contained by the prism bounds
func (*Prism) ContainsXY ¶
ContainsXY returns true if the given (x,y) coordinates are contained by the prism planform bounds
type QsortIndxInterface ¶
type QsortIndxInterface interface { sort.Interface // Partition returns slice[:i] and slice[i+1:] // These should references the original memory // since this does an in-place sort Partition(i int) (left QsortIndxInterface, right QsortIndxInterface) Indices() []int }
QsortIndxInterface interface to sort.Sort
type QsortInterface ¶
type QsortInterface interface { sort.Interface // Partition returns slice[:i] and slice[i+1:] // These should references the original memory // since this does an in-place sort Partition(i int) (left QsortInterface, right QsortInterface) }
QsortInterface interface to sort.Sort
func Qsort ¶
func Qsort(a QsortInterface, prng *rand.Rand) QsortInterface
Qsort a (quick) sorting algorithm that is apparently faster then Go's native sort.Sort from: https://stackoverflow.com/questions/23276417/golang-custom-sort-is-faster-than-native-sort#23278451
type Triangle ¶
type Triangle struct{ P0, P1, P2 Point }
func (*Triangle) BarycentricWeights ¶
func (*Triangle) Circumcircle ¶
func (*Triangle) EdgeLengths ¶
func (*Triangle) MinMaxInteriorAngle ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
modified from https://stackoverflow.com/questions/27161533/find-the-shortest-distance-between-a-point-and-line-segments-not-line
|
modified from https://stackoverflow.com/questions/27161533/find-the-shortest-distance-between-a-point-and-line-segments-not-line |