Documentation
¶
Index ¶
- Constants
- type Equation
- func (l1 Equation) CancelTerm(target Equation, termIndex int) (Equation, error)
- func (l1 Equation) Eq(l2 Equation) (bool, error)
- func (l1 Equation) FirstNonZeroCoefficient() (index int, value float64, ok bool)
- func (l1 Equation) IntersectionWith(l2 Equation) (intersection Vector, intersects bool, equal bool, err error)
- func (l1 Equation) IsParallelTo(l2 Equation) (bool, error)
- func (l1 Equation) NonZeroValuePoint() (nonzero Vector, ok bool)
- func (l1 Equation) Scale(scalar float64) Equation
- func (l1 Equation) String() string
- func (l1 Equation) X(y float64) (float64, error)
- func (l1 Equation) Y(x float64) (float64, error)
- type Parameterization
- type Radian
- type System
- func (s1 System) Add(srcIndex int, dstIndex int, coefficient int) (System, error)
- func (s1 System) AllEquationsHaveSameNumberOfTerms() bool
- func (s1 System) ComputeRREF() (s System, ok bool, err error)
- func (s1 System) Eq(s2 System) (bool, error)
- func (s1 System) FindFirstNonZeroCoefficients() (indices []int)
- func (s1 System) IsRREF() (bool, error)
- func (s1 System) IsTriangularForm() (triangular bool, allLeadingTermsAreOne bool, err error)
- func (s1 System) Multiply(index int, coefficient float64) (System, error)
- func (s1 System) Parameterize() (Parameterization, error)
- func (s1 System) Solve() (solution Vector, noSolution bool, infiniteSolutions bool, err error)
- func (s1 System) String() string
- func (s1 System) Swap(a int, b int) (System, error)
- func (s1 System) TriangularForm() (System, error)
- type Vector
- func (v1 Vector) Add(v2 Vector) (Vector, error)
- func (v1 Vector) AngleBetween(v2 Vector) (Radian, error)
- func (v1 Vector) AreaOfParallelogram(v2 Vector) (float64, error)
- func (v1 Vector) AreaOfTriangle(v2 Vector) (float64, error)
- func (v1 Vector) CrossProduct(v2 Vector) (Vector, error)
- func (v1 Vector) DotProduct(v2 Vector) (float64, error)
- func (v1 Vector) Eq(v2 Vector) bool
- func (v1 Vector) EqWithinTolerance(v2 Vector, tolerance float64) bool
- func (v1 Vector) IsOrthogonalTo(v2 Vector) (bool, error)
- func (v1 Vector) IsParallelTo(v2 Vector) (bool, error)
- func (v1 Vector) IsZeroVector() bool
- func (v1 Vector) Magnitude() float64
- func (v1 Vector) Mul(v2 Vector) (Vector, error)
- func (v1 Vector) Normalize() Vector
- func (v1 Vector) Projection(v2 Vector) (Vector, error)
- func (v1 Vector) ProjectionOrthogonalComponent(v2 Vector) (Vector, error)
- func (v1 Vector) Round(decimals int) Vector
- func (v1 Vector) Scale(scalar float64) Vector
- func (v1 Vector) String() string
- func (v1 Vector) Sub(v2 Vector) (Vector, error)
Constants ¶
const DefaultTolerance = 1e-10
DefaultTolerance is the tolerance to use for comparisons.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Equation ¶
Equation consists of a normal vector which specifies the direction, and a constant term. The basepoint is calculated as required.
func NewEquation ¶
NewEquation creates a new Equation based on the variable terms, e.g.: Ax + By = C For example, for a 2D vector (2, 3) and constant 5 would result in 2x + 3y = 5 The slope intercept (y = mx + b) form of that would be:
2x + 3y = 5
3y = 5 - 2x
y = 1/3(5-2x)
To get back to standard form: To find the y intercept (a point on the line), set x to zero.
2x + 3y = 5
3y = 5 - 0
y = 5/3
y intercept = (0, 5/3)
To find the x intercept, set y to zero.
2x + 3y = 5 2x - 0 = 5 2x = 5 x = 5/2 x intercept = (5/2, 0)
func (Equation) CancelTerm ¶
CancelTerm cancels a term in the target line by determining the coefficient which links them and applying the first term to the second term to cancel them out.
func (Equation) FirstNonZeroCoefficient ¶
FirstNonZeroCoefficient finds the first non-zero coefficient of the normal vector of the plane. If a non-zero coefficient is not found, ok is set to false.
func (Equation) IntersectionWith ¶
func (l1 Equation) IntersectionWith(l2 Equation) (intersection Vector, intersects bool, equal bool, err error)
IntersectionWith calculates the intersection with another 2D line. intersects is set to true if the lines intersect. equal is set to true if the lines are equal and therefore intersect infinitely many times.
func (Equation) IsParallelTo ¶
IsParallelTo determines whether two lines are parallel to each other.
func (Equation) NonZeroValuePoint ¶
NonZeroValuePoint finds a point on the Line where one of the dimension values is not zero. If a non-zero coefficient is not found, ok is set to false.
type Parameterization ¶
Parameterization provides a way of enumerating the many possible solutions to a system of equations which has infinite solutions.
func (Parameterization) String ¶
func (p1 Parameterization) String() string
type System ¶
type System []Equation
System defines a system of equations, where each equation is a linear equation.
func (System) Add ¶
Add adds the equation with srcIndex multiplied by the coefficient to the equation with index dstIndex.
func (System) AllEquationsHaveSameNumberOfTerms ¶
AllEquationsHaveSameNumberOfTerms returns true when all equations in the system have the same number of terms.
func (System) ComputeRREF ¶
ComputeRREF computes the Reduced Row Echelon Form of the system. ok returns whether all of the terms in the equation have got a value (i.e. there is a solution.)
func (System) FindFirstNonZeroCoefficients ¶
FindFirstNonZeroCoefficients finds the indices of the first non-zero coefficient of each equation in the system. If a non-zero coefficient is not found, then -1 is returned for that item.
func (System) IsTriangularForm ¶
IsTriangularForm determines whether the system is in triangular form, where the top row starts with a non-zero term, the next one down starts with a zero etc., the one after that starts with two zero terms etc.
func (System) Parameterize ¶
func (s1 System) Parameterize() (Parameterization, error)
Parameterize handles the case when an infinite number of solutions is found to a system of equations. This occurs when one or more of the coefficients is "free". The function returns a Parameterization object, which consists of a basepoint vector (the )
func (System) Solve ¶
Solve solves the equation using Gaussian Elimination and returns whether the solution has a single solution, no solutions, infinite solutions or can't be calculated due to an error.
func (System) String ¶
String writes out each equation in the system, delineated by commas and surrounded by braces, e.g. { 1x₁ + 2x₂ + 3x₃ = 4, 5x₁ + 6x₂ + 7x₃ = 8 }
func (System) TriangularForm ¶
TriangularForm organises the system by leading term.
type Vector ¶
type Vector []float64
Vector represents an array of values.
func (Vector) AngleBetween ¶
AngleBetween returns the angle (in radians) between the current vector and v2, or an error if the dimensions of the vectors do not match.
func (Vector) AreaOfParallelogram ¶
AreaOfParallelogram calculates the area of a parallelogram spanned by the basis vector and input vector for 2D and 3D inputs.
func (Vector) AreaOfTriangle ¶
AreaOfTriangle calculates the area of a parallelogram spanned by the basis vector and input vector for 2D and 3D inputs.
func (Vector) CrossProduct ¶
CrossProduct calculates the cross product of the current vector and the input vector. The cross product produces a vector which is:
- orthogonal to both v1 and v2.
- has a magnitude of the magnitude of v1 * the magnitude of v2 * the sine of the angle between v1 and v2
v2 must be a vector with 3 dimensions.
func (Vector) DotProduct ¶
DotProduct calculates the dot product of the current vector and the input vector, or an error if the dimensions of the vectors do not match.
func (Vector) EqWithinTolerance ¶
EqWithinTolerance tests that a vector is equal, within a given tolerance.
func (Vector) IsOrthogonalTo ¶
IsOrthogonalTo calculates whether the current vector is orthogonal to the input vector by calculating the dot product. If the dot product is zero, then the vectors are orthogonal.
func (Vector) IsParallelTo ¶
IsParallelTo calculates whether the current vector is parallel to the input vector by normalizing both vectors, and comparing them. In the case that the
func (Vector) IsZeroVector ¶
IsZeroVector returns true if all of the values in the vector are within tolerance of zero.
func (Vector) Magnitude ¶
Magnitude calculates the magnitude of the vector by calculating the square root of the sum of each element squared.
func (Vector) Mul ¶
Mul muliplies the input vector and the current vector together and returns a new vector.
func (Vector) Normalize ¶
Normalize normalizes the magnitude of a vector to 1 and returns a new vector.
func (Vector) Projection ¶
Projection calculates the projection of the v2 vector onto the basis vector (v1) by calculating the unit vector of v1 and scaling it.
func (Vector) ProjectionOrthogonalComponent ¶
ProjectionOrthogonalComponent calculates the projection of v2 onto the basis vector (v1) and uses that to calculate a component which is orthogonal to the basis vector and perpendicular to v2.