Documentation
¶
Overview ¶
package ms1 implements basic 1D math useful for 3D graphics applications. Functions in this package have their OpenGL equivalent which is usually of the same name.
Index ¶
- func Clamp(v, Min, Max float32) float32
- func EqualWithinAbs(a, b, tol float32) bool
- func GridSubdomain(domMin, domMax float32, nGridPoints int, subMin, subMax float32) (iStart, nSub int)
- func Interp(x, y, a float32) float32
- func InterpWrap(wrapAt, x, y, a float32) float32
- func Sign(x float32) float32
- func SmoothStep(edge0, edge1, x float32) float32
- type NewtonRaphsonSolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EqualWithinAbs ¶
EqualWithinAbs checks if a and b are within tol of eachother.
func GridSubdomain ¶
func GridSubdomain(domMin, domMax float32, nGridPoints int, subMin, subMax float32) (iStart, nSub int)
GridSubdomain returns the indexing for a 1D subdomain contained within a larger gridded domain of equally spaced nGridPoints points.
- iStart contains the starting index of the first point contained within the subdomain.
- nSub is the number of consecutive grid points contained within the subdomain.
This function is primarily used for higher dimension GridSubdomain calls in 2D and 3D packages
func Interp ¶
Interp performs the linear interpolation between x and y, mapping with a in interval [0,1]. This function is known as "mix" in OpenGL.
func InterpWrap ¶
InterpWrap returns the linear interpolation between x and y on the cyclic domain [0,wrapAt].
- x and y define interpolation domain and must be contained within cyclic domain [0,wrapAt]
- a is the interpolation parameter and must be contained within [0,1]. a=0 returns x, a=1 returns y.
- wrapAt defines the period of the cyclic domain, specifically the point at which the domain wraps back to 0. Typically 2*math.Pi radians, 360 degrees or 1 for unit phases. wrapAt must be positive.
If above rules are followed the result is guaranteed to lie in [x,y] which in turn is contained in [0,wrapAt].
func Sign ¶
Sign returns -1, 0, or 1 for negative, zero or positive x argument, respectively, just like OpenGL's "sign" function.
func SmoothStep ¶
SmoothStep performs smooth cubic hermite interpolation between 0 and 1 when edge0 < x < edge1.
Types ¶
type NewtonRaphsonSolver ¶
type NewtonRaphsonSolver struct { // MaxIterations specifies how many iterations of Newton's succesive // approximations to perform. Each iteration evaluates function 3 times. Parameter is required. MaxIterations int // Tolerance sets the criteria for ending the root search when f(x)/f'(x) <= Tolerance. Tolerance float32 // Dx is the step with which the gradient is calculated with central-finite-differences. Dx float32 // Relaxation is optional parameter to avoid overshooting during gradient descent for ill conditioned functions, i.e: large gradient near root. Relaxation float32 // AdaptiveDxMaxIterations sets maximum amount of changes to step (Dx) throughout root search when encountering numerical issues. // If not set then not used. AdaptiveDxMaxIterations int // RootLims clamps search for root to x_min=RootLims[0], x_max=RootLims[1]. RootLims [2]float32 }
NewtonRaphsonSolver implements Newton-Raphson root finding algorithm for an arbitrary function.
func DefaultNewtonRaphsonSolver ¶
func DefaultNewtonRaphsonSolver() NewtonRaphsonSolver
DefaultNewtonRaphsonSolver returns a NewtonRaphsonSolver with recommended parameters.
func (NewtonRaphsonSolver) Root ¶
func (nra NewtonRaphsonSolver) Root(x0 float32, f func(xGuess float32) float32) (x_root float32, convergedIn int)
Root solves for a root of f such that f(x)=0 by starting guessing at x0 solving using Newton-Raphson method. Root returns the first root found and the amount of interations before converging.
If the convergence parameter returned is negative a solution was not found within the desired tolerance.