Documentation ¶
Overview ¶
Package maf provides maths functions and types.
Index ¶
- Constants
- Variables
- func AbsLen(a, b float64) float64
- func CompareAff(a1, a2 Aff, precision int) bool
- func CompareBasis(b1, b2 Basis, precision int) bool
- func CompareComplex(c1, c2 complex128, precision int) bool
- func CompareFrame(f1, f2 Frame, precision int) bool
- func CompareLine(l1, l2 Line, tolerance float64, precision int) bool
- func CompareMat4(m1, m2 Mat4, precision int) bool
- func CompareOrderedSegs(s1, s2 []LineSeg, precision int) bool
- func CompareOrderedTriangle(t1, t2 Triangle, precision int) bool
- func CompareOrderedVecs(v1, v2 []Vec, precision int) bool
- func CompareSeg(s1, s2 LineSeg, precision int) bool
- func CompareTriangle(t1, t2 Triangle, precision int) bool
- func CompareTriangles(v1, v2 []Triangle, precision int) bool
- func CompareVec(v1, v2 Vec, precision int) bool
- func CompareVec2(v1, v2 Vec2, precision int) bool
- func CompareVecs(v1, v2 []Vec, precision int) bool
- func CosineRule(a, b, c float64) float64
- func CubeRoots(c complex128) (complex128, complex128, complex128)
- func DegToRad(deg float64) float64
- func EllipsePerimeter(a, b float64) float64
- func Lowest(n1, n2 int) int
- func MinMax(n1, n2, n3 float64) (float64, float64)
- func MinMaxInt(n1, n2, n3 int) (int, int)
- func ModuloPi(angle float64) float64
- func NewtonsMethod(f func(float64) float64, d func(float64) float64, guess float64, ...) float64
- func RadToDeg(rad float64) float64
- func Round(f float64, precision int) float64
- func ScalarTripleProduct(a, b, c Vec) float64
- func SolveSLE2(a1, b1, c1, a2, b2, c2 float64) (x float64, y float64, ok bool)
- type Aff
- func NewORot(v Vec, angle float64) Aff
- func NewRefl(p Plane) Aff
- func NewRot(l Line, angle float64) Aff
- func NewTranslation(t Vec) Aff
- func NewXRot(angle float64) Aff
- func NewXYRefl() Aff
- func NewXZRefl() Aff
- func NewYRot(angle float64) Aff
- func NewYZRefl() Aff
- func NewYZReflAt(x float64) Aff
- func NewZRot(angle float64) Aff
- func (a1 Aff) CSS() string
- func (a1 Aff) Inverse() Aff
- func (a1 Aff) Multiply(a2 Aff) (affine Aff)
- func (a1 Aff) ToMat3() Mat3
- func (a1 Aff) ToMat4() Mat4
- func (a1 Aff) ToOpenGLMat4x3() OpenGLMat4x3
- func (a1 Aff) Transform(v Vec) Vec
- func (a1 Aff) TransformBez(b Bez) Bez
- func (a1 Aff) TransformFrame(fr Frame) Frame
- func (a1 Aff) TransformRay(r Ray) Ray
- type Annulus2
- type Basis
- type Bez
- func (b1 Bez) AngleB() float64
- func (b1 Bez) ArcLength() float64
- func (b1 Bez) AtT(t float64) Vec
- func (b1 Bez) BendingEnergy() float64
- func (b1 Bez) CircleTangency(sph Sphere) BezCircleTangency
- func (b1 Bez) Closest(p Vec) BezClosest
- func (b1 Bez) ClosestPoints(p Vec) (int, BezClosest, BezClosest)
- func (b1 Bez) IsCollinear(tolerance float64) bool
- func (b1 Bez) Plane() Plane
- func (b1 Bez) PlaneIntersections(p Plane) (int, float64, float64)
- func (b1 Bez) PlaneTangencyLocus(plane Plane) Line
- func (b1 Bez) Subdivide1(t float64) (Bez, Bez)
- func (b1 Bez) Subdivide2(t1, t2 float64) (Bez, Bez, Bez)
- func (b1 Bez) Tangent(t float64) Line
- type Bez2
- type BezCircleTangency
- type BezClosest
- type Circle
- type Circle2
- type Cubic
- type ExpSin
- type Frame
- func (f1 Frame) Global(a Aff) Frame
- func (f1 Frame) GlobalDis(v Vec) Frame
- func (f1 Frame) In() Aff
- func (f1 Frame) InFrom(f Frame) Aff
- func (f1 Frame) Local(a Aff) Frame
- func (f1 Frame) LocalDis(v Vec) Frame
- func (f1 Frame) LocalDisNegX(d float64) Frame
- func (f1 Frame) LocalDisNegXNegZ(d float64) Frame
- func (f1 Frame) LocalDisNegXPosZ(d float64) Frame
- func (f1 Frame) LocalDisNegY(d float64) Frame
- func (f1 Frame) LocalDisNegZ(d float64) Frame
- func (f1 Frame) LocalDisPosX(d float64) Frame
- func (f1 Frame) LocalDisPosXNegZ(d float64) Frame
- func (f1 Frame) LocalDisPosXPosZ(d float64) Frame
- func (f1 Frame) LocalDisPosY(d float64) Frame
- func (f1 Frame) LocalDisPosZ(d float64) Frame
- func (f1 Frame) LocalRot(l Line, angle float64) Frame
- func (f1 Frame) LocalRotBasis(v Vec, angle float64) Frame
- func (f1 Frame) LocalRotNegX(angle float64) Frame
- func (f1 Frame) LocalRotNegY(angle float64) Frame
- func (f1 Frame) LocalRotNegZ(angle float64) Frame
- func (f1 Frame) LocalRotPosX(angle float64) Frame
- func (f1 Frame) LocalRotPosY(angle float64) Frame
- func (f1 Frame) LocalRotPosZ(angle float64) Frame
- func (f1 Frame) Out() (affine Aff)
- func (f1 Frame) OutTo(f Frame) Aff
- func (f1 Frame) PlotXY(p Vec2) Vec
- func (f1 Frame) View(p Vec) Frame
- type LatHR
- type Line
- type Line2
- type LineSeg
- type LineSeg2
- func (ls1 LineSeg2) AtT(t float64) Vec2
- func (ls1 LineSeg2) Canonical() LineSeg2
- func (ls1 LineSeg2) DistTo(P Vec2) float64
- func (ls1 LineSeg2) Higher(z float64) LineSeg
- func (ls1 LineSeg2) InteriorsIntersect(ls2 LineSeg2) bool
- func (ls1 LineSeg2) InteriorsIntersectAny(lineSegs ...LineSeg2) bool
- func (ls1 LineSeg2) Len() float64
- func (ls1 LineSeg2) Line() Line2
- func (ls1 LineSeg2) PerpBis() Line2
- func (ls1 LineSeg2) Right(p Vec2) bool
- func (ls1 LineSeg2) T(p Vec2) float64
- type Mat2
- type Mat3
- type Mat4
- type OpenGLMat4
- type OpenGLMat4x3
- type Plane
- type Poly
- type Quadratic
- type Ray
- type Sphere
- type Triangle
- func (t1 Triangle) BisectorAC() Vec
- func (t1 Triangle) Centroid() Vec
- func (t1 Triangle) Circumcircle() Circle
- func (t1 Triangle) Coincide(t2 Triangle) bool
- func (t1 Triangle) DivideAC(s, t float64) Vec
- func (t1 Triangle) EnclosingSphere() Sphere
- func (t1 Triangle) Plane() Plane
- func (t1 Triangle) Scale(k float64) Triangle
- type Triangle2
- func (tr1 Triangle2) AltitudeRatioA(P Vec2) float64
- func (tr1 Triangle2) AltitudeRatioB(P Vec2) float64
- func (tr1 Triangle2) AltitudeRatioC(P Vec2) float64
- func (t1 Triangle2) Anticlockwise() Triangle2
- func (t1 Triangle2) Canonical() Triangle2
- func (t1 Triangle2) Circumcircle() Circle2
- func (t1 Triangle2) CircumcircleContains(p Vec2) bool
- func (tr1 Triangle2) ClosureIncludes(P Vec2) bool
- func (tr1 Triangle2) ClosureIncludesAll(points ...Vec2) bool
- func (tr1 Triangle2) ClosureIncludesAny(points ...Vec2) bool
- func (t1 Triangle2) CoincidesWith(t2 Triangle2) bool
- func (t1 Triangle2) Edges() [3]LineSeg2
- func (t1 Triangle2) Higher(z float64) Triangle
- func (tr1 Triangle2) InteriorIncludes(P Vec2) bool
- func (tr1 Triangle2) InteriorIncludesAny(points ...Vec2) bool
- func (tr1 Triangle2) InteriorsIntersect(tr2 Triangle2) bool
- func (tr1 Triangle2) InteriorsIntersectLineSeg(ls LineSeg2) bool
- func (t1 Triangle2) SharesAnyVertexWith(t2 Triangle2) bool
- func (t1 Triangle2) Vertices() [3]Vec2
- func (tr1 Triangle2) Winding() bool
- type Vec
- func (v1 Vec) AcuteAngle(v2 Vec) (rads float64)
- func (v1 Vec) Add(v2 Vec) Vec
- func (v1 Vec) Angle(v2 Vec) (rads float64)
- func (v1 Vec) Cross(v2 Vec) Vec
- func (v1 Vec) DistTo(v2 Vec) float64
- func (v1 Vec) DistToSqd(v2 Vec) float64
- func (v1 Vec) DivTo(v2 Vec, a float64, b float64) Vec
- func (v1 Vec) Dot(v2 Vec) float64
- func (v1 Vec) Higher(w float64) Vec4
- func (v1 Vec) IsParallel(v2 Vec, tolerance float64) bool
- func (v1 Vec) IsPerpendicular(v2 Vec, tolerance float64) bool
- func (v1 Vec) Lower() Vec2
- func (v1 Vec) Mag() float64
- func (v1 Vec) MagSqd() float64
- func (v1 Vec) Map(f func(float64) float64) Vec
- func (v1 Vec) MidTo(v2 Vec) Vec
- func (v1 Vec) Opposite() Vec
- func (v1 Vec) Perpendicular() Vec
- func (v1 Vec) PlaneResolution(p Plane) Vec
- func (v1 Vec) Resolution(v2 Vec) Vec
- func (v1 Vec) Scale(k float64) Vec
- func (v1 Vec) Subtract(v2 Vec) Vec
- func (v1 Vec) To(v2 Vec) Vec
- func (v1 Vec) Unit() Vec
- type Vec2
- func (v1 Vec2) Add(v2 Vec2) Vec2
- func (v1 Vec2) Angle(v2 Vec2) (rads float64)
- func (v1 Vec2) Anticlockwise(v2 Vec2) float64
- func (v1 Vec2) Clockwise(v2 Vec2) float64
- func (v1 Vec2) CosAngle(v2 Vec2) float64
- func (v1 Vec2) DistTo(v2 Vec2) float64
- func (v1 Vec2) DistToSqd(v2 Vec2) float64
- func (v1 Vec2) Dot(v2 Vec2) float64
- func (v1 Vec2) Higher(z float64) Vec
- func (v1 Vec2) IsParallel(v2 Vec2, tolerance float64) bool
- func (v1 Vec2) Mag() float64
- func (v1 Vec2) MagSqd() float64
- func (v1 Vec2) MidTo(v2 Vec2) Vec2
- func (v1 Vec2) Normal() Vec2
- func (v1 Vec2) Scale(k float64) Vec2
- func (v1 Vec2) To(v2 Vec2) Vec2
- func (v1 Vec2) Unit() Vec2
- func (v1 Vec2) Vec() Vec
- type Vec4
Constants ¶
const ( // SmallAngle is an arbitrary small angle measured in radians. // // It is used in situations that need to take into account floating point // numerical approximations like testing for parallelism. SmallAngle = 1e-6 // TwoPi is the angle subtended at the centre of a whole circle by its // perimeter, measured in radians. TwoPi = math.Pi * 2 // HalfPi is the angle subtended at the centre of a quarter circle by its // arc, measured in radians. HalfPi = math.Pi / 2 // QuartPi is the angle subtended at the centre of a 1/8th circle by its // arc, measured in radians. QuartPi = math.Pi / 4 )
Variables ¶
var ( // CosPiOver6 is the value of Cos(Pi/6). CosPiOver6 = math.Sqrt(3) / 2.0 // TanSmallAngle is the value of the tan of a small angle. TanSmallAngle = math.Tan(SmallAngle) )
var ( // StdBasis is a standard basis with axis directions (1, 0, 0), (0, 1, 0), // (0, 0, 1). StdBasis = Basis{PosX, PosY, PosZ} // StdFrame is a standard frame with origin (0, 0, 0) and axis directions // (1, 0, 0), (0, 1, 0), (0, 0, 1). StdFrame = Frame{O: Zero, Axes: StdBasis} )
var ( // Zero is the zero length vector. Zero = Vec{X: 0, Y: 0, Z: 0} // NegZ is the unit direction vector of the negative Z-axis. NegZ = Vec{X: 0, Y: 0, Z: -1} // PosZ is the unit direction vector of the positive Z-axis. PosZ = Vec{X: 0, Y: 0, Z: 1} // NegY is the unit direction vector of the negative Y-axis. NegY = Vec{X: 0, Y: -1, Z: 0} // PosY is the unit direction vector of the positive Y-axis. PosY = Vec{X: 0, Y: 1, Z: 0} // NegX is the unit direction vector of the negative X-axis. NegX = Vec{X: -1, Y: 0, Z: 0} // PosX is the unit direction vector of the positive X-axis. PosX = Vec{X: 1, Y: 0, Z: 0} // NegXNegZ is the unit direction vector of the vector sum of the negative // X-axis and negative Z-axis. NegXNegZ = NegX.Add(NegZ).Unit() // NegXPosZ is the unit direction vector of the vector sum of the negative // X-axis and positive Z-axis. NegXPosZ = NegX.Add(PosZ).Unit() // PosXNegZ is the unit direction vector of the vector sum of the positive // X-axis and negative Z-axis. PosXNegZ = PosX.Add(NegZ).Unit() // PosXPosZ is the unit direction vector of the vector sum of the positive // X-axis and positive Z-axis. PosXPosZ = PosX.Add(PosZ).Unit() )
var ( // X0Plane is the plane through the origin which coincides with the Y and Z // axes. X0Plane = Plane{Normal: PosX} // Y0Plane is the plane through the origin which coincides with the Z and X // axes. Y0Plane = Plane{Normal: PosY} // Z0Plane is the plane through the origin which coincides with the X and Y // axes. Z0Plane = Plane{Normal: PosZ} )
var ( // XRotPi is a rotation around the X-axis by Pi radians. It is its own // inverse transformation. XRotPi = NewXRot(math.Pi) // YRotPi is a rotation around the Y-axis by Pi radians. It is its own // inverse transformation. YRotPi = NewYRot(math.Pi) // ZRotPi is a rotation around the Z-axis by Pi radians. It is its own // inverse transformation. ZRotPi = NewZRot(math.Pi) )
var ( // AffIdentity is the identity transformation. AffIdentity = Aff{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0} )
var CubeRootsOfOne = [3]complex128{ 1 + 0i, complex(-0.5, CosPiOver6), complex(-0.5, -CosPiOver6), }
CubeRootsOfOne are the three possible complex solutions of z = 1^(1/3).
The order of the roots is anticlockwise around the origin starting from the real solution.
var ( // Z0Refl is a reflection transformation in the XY plane at z=0. Z0Refl = NewXYRefl() )
Functions ¶
func CompareAff ¶
CompareAff returns whether two affine transformations are approximately equal in an element-wise comparison.
func CompareBasis ¶
CompareBasis returns whether two basis' are approximately equal.
func CompareComplex ¶
func CompareComplex(c1, c2 complex128, precision int) bool
CompareComplex returns whether two complex numbers are approximately equal.
func CompareFrame ¶
CompareFrame returns whether two frames are approximately equal.
func CompareLine ¶
CompareLine reports whether two lines approximately coincide.
func CompareMat4 ¶
CompareMat4 returns whether two matrices are approximately equal.
func CompareOrderedSegs ¶
CompareOrderedSegs reports whether two slices contain, in the same order, approximately equal line segments with the same directions.
func CompareOrderedTriangle ¶
CompareOrderedTriangle reports whether the given triangles approximately coincide and label the vertices the same way.
func CompareOrderedVecs ¶
CompareOrderedVecs returns whether two vector slices contain, in the same order, approximately equal vectors.
func CompareSeg ¶
CompareSeg reports whether two line segments are approximately equal and have the same direction.
func CompareTriangle ¶
CompareTriangle reports whether the given triangles approximately coincide.
func CompareTriangles ¶
CompareTriangles reports whether two vector slices contain in any order the same approximately coinciding triangles.
func CompareVec ¶
CompareVec returns whether two vectors are approximately equal.
func CompareVec2 ¶
CompareVec2 returns whether two vectors are approximately equal.
func CompareVecs ¶
CompareVecs returns whether two vector slices contain in any order the same approximately equal vectors.
func CosineRule ¶
CosineRule figures out the angle C, measured in radians, in a triangle with side lengths a, b, and c.
The side c subtends the angle C.
func CubeRoots ¶
func CubeRoots(c complex128) (complex128, complex128, complex128)
CubeRoots returns the cube roots of a complex number.
func EllipsePerimeter ¶
EllipsePerimeter approximation for the ellipse with semi-major axis length a and semi-minor axis length b.
func ModuloPi ¶
ModuloPi returns the trigonometrically equivalent angle to the argument angle, measured in radians, in the range -Pi to Pi.
func NewtonsMethod ¶
func NewtonsMethod( f func(float64) float64, d func(float64) float64, guess float64, tolerance float64, maxIterations int, ) float64
NewtonsMethod returns an approximate value of a root of a function.
The two argument functions required are the function and its derivative function. The argument initial guess should be your closest guess to the desired root.
The algorithm will halt when the magnitude of the change between a guess and its next guess is reduced below the argument tolerance or when the number of iterations of the algorithm reaches the argument limit.
func ScalarTripleProduct ¶
ScalarTripleProduct returns the signed volume of the parallelpiped spanned by three vectors.
volume = a⋅(b×c) == c⋅(a×b) == b⋅(c×a) and a⋅(b×c) = (a×b)⋅c
The returned value is zero if all three vectors are coplanar or one of them is zero.
The returned value is < 0 for a left-handed set and > 0 for a right-handed set.
Types ¶
type Aff ¶
type Aff [12]float64
Aff is a 3x4 affine transformation matrix. Elements are stored in column order.
func NewORot ¶
NewORot constructs a new rotation around a line through the origin.
The argument direction vector is parallel to the line. The argument angle is measured in radians.
func NewRot ¶
NewRot constructs a new rotation around a line.
The angle argument specifies the angle of rotation measured in radians.
Suppose the line's direction vector was pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func NewTranslation ¶
NewTranslation constructs a new translation transformation using the argument as the translation.
func NewXRot ¶
NewXRot constructs a new rotation around the X-axis.
The argument specifies the angle of rotation measured in radians.
Suppose the X-axis was pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func NewXYRefl ¶
func NewXYRefl() Aff
NewXYRefl constructs a new reflection transformation in the XY plane at z=0.
func NewXZRefl ¶
func NewXZRefl() Aff
NewXZRefl constructs a new reflection transformation in the XZ plane at y=0.
func NewYRot ¶
NewYRot constructs a new rotation around the Y-axis.
The argument specifies the angle of rotation measured in radians.
Suppose the Y-axis was pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func NewYZRefl ¶
func NewYZRefl() Aff
NewYZRefl constructs a new reflection transformation in the YZ plane at x=0.
func NewYZReflAt ¶
NewYZReflAt constructs a new reflection transformation in the YZ plane given by x = argument value.
func NewZRot ¶
NewZRot constructs a new rotation around the Z-axis.
The argument specifies the angle of rotation measured in radians.
Suppose the Z-axis was pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Aff) CSS ¶
CSS transform property value.
https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d.
func (Aff) Multiply ¶
Multiply multiplies its receiver matrix with the argument matrix and returns the resulting matrix. The receiver matrix is the left hand side operand of the matrix multiplication. The argument matrix is the right hand side operand of the matrix multiplication.
func (Aff) ToMat3 ¶
ToMat3 returns the equivalent 3x3 matrix of the receiver matrix.
The translation components are dropped.
func (Aff) ToOpenGLMat4x3 ¶
func (a1 Aff) ToOpenGLMat4x3() OpenGLMat4x3
ToOpenGLMat4x3 returns the equivalent OpenGL float32 format matrix of the receiver matrix.
func (Aff) Transform ¶
Transform multiplies the receiver matrix with the argument vector and returns the resulting vector. The argument vector is an augmented vector with an implied 1 as the fourth element.
func (Aff) TransformBez ¶
TransformBez multiplies the receiver matrix with the vertices of the argument Bezier and returns the resulting Bezier.
func (Aff) TransformFrame ¶
TransformFrame applies the receiver transformation to the given frame.
func (Aff) TransformRay ¶
TransformRay multiplies the receiver matrix with the argument ray.
The direction vector of the returned ray is a unit vector.
type Annulus2 ¶
type Annulus2 struct { // The position vector of the circles' centre. C Vec2 // The radius of the inner circle. R1 float64 // The radius of the outer circle. R2 float64 }
Annulus2 is an annulus which is a circular ring shaped region enclosed by two concentric circles.
func (Annulus2) LineIntersection ¶
LineIntersection returns the non-zero length segments, if any, of the given line which overlap the receiver annulus.
Return the number of line segments which can be 0, 1, or 2.
type Basis ¶
type Basis struct {
X, Y, Z Vec
}
Basis is a three-dimensional Cartesian coordinate system whose axis directions are defined by three orthogonal unit vectors. The origin of the basis coincides with the origin of the implied reference basis.
func (Basis) In ¶
In returns a transformation matrix that transforms a vector's coordinates in the implied reference basis to the vector's coordinates in the receiver basis.
func (Basis) InFrom ¶
InFrom returns a transformation matrix that transforms a vector's coordinates in the argument basis to the vector's coordinates in the receiver basis.
func (Basis) Local ¶
Local returns a new Basis which is the result of applying, to the receiver basis, the argument transformation expressed in the coordinates of the receiver basis.
type Bez ¶
type Bez Triangle
Bez is a 3D quadratic Bezier curve.
func (Bez) AtT ¶
AtT returns the position vector on the receiver Bezier curve at the argument parameter.
The argument parameter is valid in the range 0..1 inclusive.
func (Bez) BendingEnergy ¶
BendingEnergy returns the bending energy of the receiver Bezier curve.
func (Bez) CircleTangency ¶
func (b1 Bez) CircleTangency(sph Sphere) BezCircleTangency
CircleTangency returns the tangency information for the Bezier and the circle which is the intersection of the given sphere's surface with the plane of the receiver Bezier.
The returned sets of control points will coincide with the intrinsic plane of the receiver Bezier curve.
The distance of the receiver Bezier's plane from the argument sphere's centre shall be less than the sphere's radius, that is, they shall intersect forming a circle.
For more details and special cases see
Geometric constraints on quadratic Bézier curves using minimal length and energy Ahn, Young Joon Hoffmann, Christoph Rosen, Paul https://www.sciencedirect.com/science/article/pii/S037704271300349X#s000040
func (Bez) Closest ¶
func (b1 Bez) Closest(p Vec) BezClosest
Closest returns information about the closest point of approach on the receiver Bezier curve to the argument point.
The receiver Bezier curve shall not have collinear control points. In the case of two equidistant closest points either one can be returned.
func (Bez) ClosestPoints ¶
func (b1 Bez) ClosestPoints(p Vec) (int, BezClosest, BezClosest)
ClosestPoints returns information about the one or two closest points of approach on the receiver Bezier curve to the argument point.
The special case of two closest points, as opposed to a single point, can occur for example when
* the control points are collinear. The two closest points coincide but have different values of the curve's parameter t
* the control points are symmetrical about a line and the point lies on the line
The returned integer value is the number of solutions and can be 1 or 2. If its value is 1 then the second BezClosest is identical to the first.
func (Bez) IsCollinear ¶
IsCollinear returns whether the receiver Bezier is, to within the argument tolerance, a degenerate straight line case.
func (Bez) PlaneIntersections ¶
PlaneIntersections finds the intersection(s) of the receiver Bezier curve with the argument plane.
Returns the values of the parameter t at the intersection points in the range 0..1 inclusive. The int return value is the number of intersections in the parameter range 0..1 inclusive. In the case of no intersections in the parameter range 0..1 both float return values are NaN. In the case of a single intersection in the parameter range 0..1 the second float return value is NaN.
func (Bez) PlaneTangencyLocus ¶
PlaneTangencyLocus returns the set of control point positions, for the middle control point B, that would make the receiver Bezier curve tangential to the argument plane.
The start and end control points, A and C, of the receiver Bezier shall be on the same side of the argument plane.
The returned set of control points will coincide with the intrinsic plane of the receiver Bezier curve and will be parallel to the argument plane.
func (Bez) Subdivide1 ¶
Subdivide1 returns the result of dividing the receiver Bezier curve into two pieces at the argument parameter in the interval 0..1.
func (Bez) Subdivide2 ¶
Subdivide2 returns the result of dividing the receiver Bezier curve into three pieces at the two argument parameters in the interval 0..1.
type BezCircleTangency ¶
type BezCircleTangency struct {
// The fixed first and last control points of the quadratic Bezier curve.
A, C Vec
// The angles in the intervals and used by the locus/tangent functions are
// relative to a hypothetical frame with this basis at the centre of the
// circle.
AnglesBasis Basis
// The circle which is touched tangentially by the Bezier curve.
Circle Circle
// An interval of angle values, measured in radians, each of which
// corresponds to a unique Bezier curve which makes a tangent with the
// closer arc on the circle.
Closer interval.In
// An interval of angle values, measured in radians, each of which
// corresponds to a unique Bezier curve which makes a tangent with the
// farther arc on the circle.
Farther interval.In
// The middle control point of the Bezier curve, so that the curve is
// tangential. Valid only for angle values contained in the intervals.
B func(theta float64) Vec
// The contact point/tangent position where the Bezier curve is a tangent to
// the circle. Valid only for angle values contained in the intervals.
T func(theta float64) Vec
// A Non-zero value implies a special case.
SpecialCase uint8
}
BezCircleTangency is a solution to the problem of finding positions, for a quadratic Bezier curve's middle control point, that make the Bezier curve tangential to a coplanar circle.
The positions are relative to the same frame that the Bezier and circle are defined in, the angles however are relative to the provided angle's basis.
func (BezCircleTangency) TangentialBez ¶
func (tang BezCircleTangency) TangentialBez(theta float64) Bez
TangentialBez returns a new tangential Bezier at the argument angle value.
type BezClosest ¶
type BezClosest struct { // The distance between the points. D float64 // The point on the Bezier curve corresponging to the parameter value. P Vec // The value of the quadratic Bezier curve's parameter, in the range 0 to 1, // which generates the closest point. // // In the case of a Bezier that has two closest points of approach to the // point, either parameter may be returned. T float64 }
BezClosest is the closest point on a Bezier curve to some other point.
type Circle ¶
type Circle struct { // The position vector of the circle centre. C Vec // The radius of the circle. R float64 // The unit vector in the direction of the normal to the circle's intrinsic // plane. Normal Vec }
Circle is a circle in three-dimensional space defined by its centre, radius and orientation.
func (Circle) PlaneIntersections ¶
PlaneIntersections finds the intersection(s) of the receiver circle with the argument plane. The int return value is the number of intersections, which may be 0, 1, or 2.
func (Circle) RandPoints ¶
RandPoints anywhere on the surface of the circle.
func (Circle) TangentPositions ¶
TangentPositions returns the position vectors where the two possible tangent lines from the argument point to the receiver circle touch the circle.
The argument point shall be in the same plane as the receiver circle and be outside of the circle.
type Circle2 ¶
type Circle2 struct { // The position vector of the circle centre. C Vec2 // The radius of the circle. R float64 }
Circle2 is a circle in 2D space defined by its centre and radius.
func (Circle2) LineIntersections ¶
LineIntersections with the circle.
func (Circle2) RandPoints ¶
RandPoints anywhere on the surface of the circle.
type Cubic ¶
type Cubic struct {
// The real coefficients of the cubic equation Ax³ + Bx² + Cx + D = 0.
//
// A shall be non-zero.
A, B, C, D float64
}
Cubic is a cubic equation with real coefficients.
func (Cubic) Roots ¶
func (c Cubic) Roots() (complex128, complex128, complex128)
Roots returns the complex values which are the solutions to the receiver cubic equation.
type ExpSin ¶
type ExpSin struct { // A is the coefficient of the variable in the exponential function. A float64 // B is the coefficient of the variable in the sin function. B float64 }
ExpSin represents a product of two functions: an exponential function and a sin function.
y = e^(Ax) * sin(Bx)
type Frame ¶
type Frame struct { // The origin of the frame. O Vec // The axis directions of the frame. Axes Basis }
Frame is a floating three-dimensional Cartesian coordinate system defined by a basis and an origin.
func NewFrame ¶
NewFrame returns a new frame.
If no arguments are provided the returned frame is a standard frame. If arguments are provided up to four arguments are used and interpreted as follows:
1st: origin 2nd: X-axis unit vector 3rd: Y-axis unit vector 4th: Z-axis unit vector
If only three arguments are provided, the fourth argument is calculated as the cross product of the second and third arguments in that order.
func (Frame) Global ¶
Global returns a new Frame which is the result of applying, to the receiver frame, the argument transformation expressed in the coordinates of the implied reference frame.
func (Frame) GlobalDis ¶
GlobalDis returns a new Frame which results from applying, to the receiver frame, the argument global displacement expressed in the coordinates of the implied reference frame.
func (Frame) In ¶
In returns a transformation matrix that transforms a vector's coordinates in the implied reference frame to the vector's coordinates in the receiver frame.
func (Frame) InFrom ¶
InFrom returns a transformation matrix that transforms a vector's coordinates in the argument frame to the vector's coordinates in the receiver frame.
func (Frame) Local ¶
Local returns a new Frame which is the result of applying, to the receiver frame, the argument transformation expressed in the coordinates of the receiver frame.
func (Frame) LocalDis ¶
LocalDis returns a new Frame which results from applying, to the receiver frame, the argument local displacement expressed in the coordinates of the receiver frame.
func (Frame) LocalDisNegX ¶
LocalDisNegX returns a new Frame which results from applying, to the receiver frame, a local displacement along its negative X-axis by the argument distance.
func (Frame) LocalDisNegXNegZ ¶
LocalDisNegXNegZ returns a new Frame which results from applying, to the receiver frame, a local displacement, by the argument distance, along the direction which is the sum of its negative X-axis and negative Z-axis directions.
func (Frame) LocalDisNegXPosZ ¶
LocalDisNegXPosZ returns a new Frame which results from applying, to the receiver frame, a local displacement, by the argument distance, along the direction which is the sum of its negative X-axis and positive Z-axis directions.
func (Frame) LocalDisNegY ¶
LocalDisNegY returns a new Frame which results from applying, to the receiver frame, a local displacement along its negative Y-axis by the argument distance.
func (Frame) LocalDisNegZ ¶
LocalDisNegZ returns a new Frame which results from applying, to the receiver frame, a local displacement along its negative Z-axis by the argument distance.
func (Frame) LocalDisPosX ¶
LocalDisPosX returns a new Frame which results from applying, to the receiver frame, a local displacement along its positive X-axis by the argument distance.
func (Frame) LocalDisPosXNegZ ¶
LocalDisPosXNegZ returns a new Frame which results from applying, to the receiver frame, a local displacement, by the argument distance, along the direction which is the sum of its positive X-axis and negative Z-axis directions.
func (Frame) LocalDisPosXPosZ ¶
LocalDisPosXPosZ returns a new Frame which results from applying, to the receiver frame, a local displacement, by the argument distance, along the direction which is the sum of its positive X-axis and positive Z-axis directions.
func (Frame) LocalDisPosY ¶
LocalDisPosY returns a new Frame which results from applying, to the receiver frame, a local displacement along its positive Y-axis by the argument distance.
func (Frame) LocalDisPosZ ¶
LocalDisPosZ returns a new Frame which results from applying, to the receiver frame, a local displacement along its positive Z-axis by the argument distance.
func (Frame) LocalRot ¶
LocalRot returns a new Frame which results from applying, to the receiver frame, a rotation about the argument line expressed in the coordinates of the receiver frame.
The argument angle shall be measured in radians. Suppose the line's direction vector is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) LocalRotBasis ¶
LocalRotBasis returns a new Frame which results from applying a local rotation around the argument direction vector by the argument angle.
Like the argument direction vector shall be, the rotation which is applied to the axes/basis of the receiver frame is expressed in the coordinates of the receiver frame.
The argument angle shall be measured in radians. Suppose the direction vector is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) LocalRotNegX ¶
LocalRotNegX returns a new Frame which results from applying a local rotation of the receiver frame's negative X-axis by the argument angle.
The argument angle shall be measured in radians. Suppose the negative X-axis is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) LocalRotNegY ¶
LocalRotNegY returns a new Frame which results from applying a local rotation of the receiver frame's negative Y-axis by the argument angle.
The argument angle shall be measured in radians. Suppose the negative Y-axis is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) LocalRotNegZ ¶
LocalRotNegZ returns a new Frame which results from applying a local rotation of the receiver frame's negative Z-axis by the argument angle.
The argument angle shall be measured in radians. Suppose the negative Z-axis is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) LocalRotPosX ¶
LocalRotPosX returns a new Frame which results from applying a local rotation of the receiver frame's positive X-axis by the argument angle.
The argument angle shall be measured in radians. Suppose the positive X-axis is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) LocalRotPosY ¶
LocalRotPosY returns a new Frame which results from applying a local rotation of the receiver frame's positive Y-axis by the argument angle.
The argument angle shall be measured in radians. Suppose the positive Y-axis is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) LocalRotPosZ ¶
LocalRotPosZ returns a new Frame which results from applying a local rotation of the receiver frame's positive Z-axis by the argument angle.
The argument angle shall be measured in radians. Suppose the positive Z-axis is pointing out of the screen towards you, then a positive rotation angle indicates an anticlockwise rotation.
func (Frame) Out ¶
Out returns a transformation matrix that transforms a vector's coordinates in the receiver frame to the vector's coordinates in the implied reference frame.
func (Frame) OutTo ¶
OutTo returns a transformation matrix that transforms a vector's coordinates in the receiver frame to the vector's coordinates in the argument frame.
func (Frame) PlotXY ¶
PlotXY interprets the given position vector as local coordinates on the receiver frame's XY plane and returns the position's equivalent in coordinates of the frame's implied reference frame.
func (Frame) View ¶
View returns a frame with the same origin as the receiver frame but reorientated so that its negative Z-axis points at the argument position vector and its Y-axis points, where possible, upwards.
The argument position vector shall be given in implied reference frame coordinates and it shan't coincide with the receiver frame's origin.
Special cases:
p is vertical wrt O: returned frame's Y-axis = standard frame's Z-axis.
type LatHR ¶
type LatHR struct { // The latitudinal circle's signed perpendicular distance from the sphere's // equatorial plane. H float64 // The latitudinal circle's radius around the pole axis. R float64 }
LatHR specifies a latitudinal circle on a sphere.
func EquiangularLatitudes ¶
EquiangularLatitudes returns for a sphere with the argument radius the height and radius of latitudinal circles (separated by equal angles subtended at the sphere's centre) beginning with the bottom most latitude.
func EquidistantLatitudes ¶
EquidistantLatitudes returns for a sphere with the argument radius the height and radius of latitudinal circles (equidistantly spaced along the axis) beginning with the bottom most latitude.
type Line ¶
type Line struct { // Any position vector on the line. P Vec // The unit vector in the direction of the line. Dir Vec }
Line is a line in three-dimensional space defined by any point on the line and the direction of the line.
func (Line) ClosestPoint ¶
ClosestPoint returns the closest point on the receiver line to the argument line. This function assumes that a unique solution definitely exists.
func (Line) ClosestPoints ¶
ClosestPoints returns the closest points of approach between the receiver line and the argument line.
The first return value is a point on the receiver line. The second return value is a point on the argument line. The returned bool value is false if there is no unique solution.
func (Line) DistTo ¶
DistTo returns the magnitude of the orthogonal distance of the argument position vector to the receiver line.
func (Line) IsParallel ¶
IsParallel returns whether the positive angle between the receiver and argument lines directions is either zero or Pi to within the given positive tolerance argument, measured in radians.
func (Line) PlaneIntersection ¶
PlaneIntersection returns the intersection point of the receiver line and argument plane.
The argument plane shall not be parallel to the receiver line.
type Line2 ¶
type Line2 struct { // Any position vector on the line. P Vec2 // The unit vector in the direction of the line. Dir Vec2 }
Line2 is a line in 2D space defined by any point on the line and the direction of the line.
func (Line2) Closest ¶
Closest returns the closest points of approach between the receiver line and the argument line.
The first return value is a point on the receiver line. The second return value is a point on the argument line. The returned bool value is false if there is no unique solution.
func (Line2) ClosestApproach ¶
ClosestApproach on the line to the given point.
func (Line2) ClosestPoint ¶
ClosestPoint returns the closest point on the receiver line to the argument line. This function assumes that a unique solution definitely exists.
type LineSeg ¶
type LineSeg struct {
// The end points of the line segment.
P1, P2 Vec
}
LineSeg is a line segment in three-dimensional space.
func (LineSeg) AtT ¶
AtT returns the position vector on the receiver line segment at the argument proportion of the distance from P1 to P2.
type LineSeg2 ¶
type LineSeg2 struct {
P1, P2 Vec2
}
LineSeg2 is a line segment in 2D space defined by two points.
func (LineSeg2) AtT ¶
AtT maps a parameterisation of a point on the receiver segment's extended line back to a point on the line.
func (LineSeg2) DistTo ¶
DistTo returns the shortest distance from the receiver line segment to the argument point.
func (LineSeg2) InteriorsIntersect ¶
InteriorsIntersect returns whether the argument and receiver line segments are non parallel and intersect at a single point, not including their end points.
func (LineSeg2) InteriorsIntersectAny ¶
InteriorsIntersectAny returns whether the receiver line segment is non parallel to and intersects at a single point any of the argument line segments, not including their end points.
func (LineSeg2) Right ¶
Right reports whether the given point is to the right of the extended line through the line segment.
It is the implied direction of the line segment that gives meaning to the concepts of left and right in this case.
func (LineSeg2) T ¶
T is a parameterisation of the position of the given point upon the extended line of the receiver line segment.
For t = 0, the closest point is the segment's first point. For t = 1, then the closest point of approach is the segment's second point.
t ~ -0.5 t ~ 0.5 t ~ 2 * * * - - - - - - - P1 - - - - - - P2 - - - - - - - - * * t = 0 t = 1
type Mat2 ¶
type Mat2 [4]float64
Mat2 is a square 2x2 matrix. Elements are stored in column order.
type Mat3 ¶
type Mat3 [9]float64
Mat3 is a square 3x3 matrix. Elements are stored in column order.
func (Mat3) CSS ¶
CSS transform property value.
https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d.
func (Mat3) Inverse ¶
Inverse of the matrix.
If the inverse does not exist, return the identity matrix.
func (Mat3) Multiply ¶
Multiply multiplies its receiver matrix with the argument matrix and returns the resulting matrix. The receiver matrix is the left hand side operand of the matrix multiplication. The argument matrix is the right hand side operand of the matrix multiplication.
type Mat4 ¶
type Mat4 [16]float64
Mat4 is a square 4x4 matrix. Elements are stored in column order.
func (Mat4) CSS ¶
CSS transform property value.
https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d.
func (Mat4) Multiply ¶
Multiply multiplies its receiver matrix with the argument matrix and returns the resulting matrix. The receiver matrix is the left hand side operand of the matrix multiplication. The argument matrix is the right hand side operand of the matrix multiplication.
func (Mat4) RowMajorSlice ¶
RowMajorSlice expresses the receiver matrix in a new slice with the elements in row-major order.
func (Mat4) ToOpenGLMat4 ¶
func (m1 Mat4) ToOpenGLMat4() OpenGLMat4
ToOpenGLMat4 returns the equivalent OpenGL float32 format matrix of the receiver matrix.
type OpenGLMat4 ¶
type OpenGLMat4 [16]float32
OpenGLMat4 is a square 4x4 matrix with openGL sized floats. Elements are stored in column order.
type OpenGLMat4x3 ¶
type OpenGLMat4x3 [12]float32
OpenGLMat4x3 is a 4x3 matrix (4 columns and 3 rows) with openGL sized floats. Elements are stored in column order.
type Plane ¶
type Plane struct { // Any position vector on the plane. P Vec // The unit vector in the direction of the plane's normal. Normal Vec }
Plane is a two-dimensional plane in three-dimensional space defined by any position vector on the plane and a normal vector to the plane.
func (Plane) Closest ¶
Closest returns the closest point on the receiver plane to the argument point.
func (Plane) DistTo ¶
DistTo returns the magnitude of the orthogonal distance of the argument position vector to the receiver plane.
func (Plane) IsParallel ¶
IsParallel is true if the argument direction vector is perpendicular to the normal of the argument plane, to within the argument positive tolerance angle measured in radians.
func (Plane) PlaneIntersection ¶
PlaneIntersection returns the intersection line of the receiver plane and argument plane.
The argument plane shall not be parallel to the receiver plane.
func (Plane) SignedDistTo ¶
SignedDistTo returns a signed value whose magnitude is the orthogonal distance of the argument position vector to the receiver plane.
The returned value is > 0 if the position vector is on that side of the plane that the normal points into.
type Poly ¶
type Poly []float64
Poly is a single variable polynomial with real coefficients.
The degree of the polynomial is one less than the length of the slice.
The elements of the slice are the coefficients of the constituent monomial terms. The index of the coefficient in the slice is the power of the monomial term to which the coefficient corresponds.
func (Poly) At ¶
At evaluates the polynomial as a function at the argument polynomial variable value.
func (Poly) Derivative ¶
Derivative returns the result of differentiating the receiver polynomial with respect to the variable.
Special cases are:
The derivative of an empty polynomial is the zero polynomial. The derivative of a constant polynomial is the zero polynomial.
type Quadratic ¶
type Quadratic struct {
// The real coefficients of the cubic equation Ax² + Bx + C = 0.
//
// A shall be be non-zero.
A, B, C float64
}
Quadratic is a quadratic equation with real coefficients.
func (Quadratic) Root ¶
func (q Quadratic) Root() complex128
Root returns a single complex value which is a solution to the receiver quadratic equation.
The value returned is derived from the plus option in the quadratic formula: (-b + sqrt(b*b-4ac))/2a
func (Quadratic) Roots ¶
func (q Quadratic) Roots() (complex128, complex128)
Roots returns the complex values which are the solutions to the receiver quadratic equation.
type Ray ¶
type Ray struct { // The origin of the ray. O Vec // A unit vector in the same direction as a translation vector from the // origin to any other point on the ray. Dir Vec }
A Ray is an infinitely long half line that begins at a point called its origin.
type Sphere ¶
type Sphere struct { // The position vector of the sphere centre. C Vec // The radius of the sphere. R float64 }
Sphere is a sphere in three-dimensional space defined by its centre and radius.
func (Sphere) Circle ¶
Circle returns the circle containing the set of points on the receiver sphere's surface that coincide with the argument plane.
If the argument plane does not generate a circle then the returned bool value is false and the returned circle empty.
func (Sphere) InteriorsIntersect ¶
InteriorsIntersect returns whether the argument sphere's interior contains any points from the receiver sphere's interior or vice versa.
Here, spheres that only touch at a single point on their surfaces are not considered as intersecting.
type Triangle ¶
type Triangle struct {
// The triangle's vertices.
A, B, C Vec
}
Triangle is a triangle in three-dimensional space defined by three vertices.
func (Triangle) BisectorAC ¶
BisectorAC returns the position vector of the point on the receiver triangle's segment AC such that a line through vertex B and it bisects angle B.
func (Triangle) Centroid ¶
Centroid returns the arithmetic mean of the receiver triangle's vertices.
func (Triangle) Circumcircle ¶
Circumcircle returns the unique circle that circumscribes the receiver triangle's vertices.
func (Triangle) DivideAC ¶
DivideAC returns the position vector P on the receiver triangle's segment AC such that the ratio of magnitude AP to magnitude PC equals the ratio of argument1 to argument2.
|AP|/|PC| = s/t
func (Triangle) EnclosingSphere ¶
EnclosingSphere returns a sphere that the receiver triangle's vertices are not outside of.
type Triangle2 ¶
type Triangle2 struct {
// The triangle's vertices.
A, B, C Vec2
}
Triangle2 is a triangle in 2D space defined by three vertices.
func (Triangle2) AltitudeRatioA ¶
AltitudeRatioA returns the signed ratio that is a measure of the perpendicular distance of the argument point from the receiver triangle's A vertex as measured along the altitude line through the A vertex to the extended line BC.
func (Triangle2) AltitudeRatioB ¶
AltitudeRatioB returns the signed ratio that is a measure of the perpendicular distance of the argument point from the receiver triangle's B vertex as measured along the altitude line through the B vertex to the extended line CA.
func (Triangle2) AltitudeRatioC ¶
AltitudeRatioC returns the signed ratio that is a measure of the perpendicular distance of the argument point from the receiver triangle's C vertex as measured along the altitude line through the C vertex to the extended line AB.
Using the altitude line through vertex C, which is perpendicular to AB, as an axis with C at the origin, then if the returned ratio is:
* 0: the argument point is vertically above or below the vertex C
* 1: the argument point is somewhere on the extended line AB
* between 0 and 1: the argument point is somewhere within, above or below the triangle
* negative, the argument point is to the left of the C vertex
* greater than 1, the argument point is to the right of the triangle's base AB
func (Triangle2) Anticlockwise ¶
Anticlockwise triangle with the same vertices.
func (Triangle2) Circumcircle ¶
Circumcircle returns the unique circle that circumscribes the receiver triangle's vertices.
func (Triangle2) CircumcircleContains ¶
CircumcircleContains reports whether the given point is inside the bounds of the right handed triangle's circumcircle.
The triangle's vertices shall be in anticlockwise order.
func (Triangle2) ClosureIncludes ¶
ClosureIncludes returns whether the argument point is included in the set of points that make up the receiver triangle's interior or its edges and vertices.
func (Triangle2) ClosureIncludesAll ¶
ClosureIncludesAll returns whether any of the argument points are included in the set of points that make up the receiver triangle's interior or its edges and vertices.
func (Triangle2) ClosureIncludesAny ¶
ClosureIncludesAny returns whether any of the argument points are included in the set of points that make up the receiver triangle's interior or its edges and vertices.
func (Triangle2) CoincidesWith ¶
CoincidesWith reports whether the triangles share the same vertices.
func (Triangle2) InteriorIncludes ¶
InteriorIncludes returns whether the argument point is included in the set of points that make up the receiver triangle's interior.
Here, points that coincide with the edges or vertices are not considered as included.
func (Triangle2) InteriorIncludesAny ¶
InteriorIncludesAny returns whether any of the argument points are included in the set of points that make up the receiver triangle's interior.
Here, points that coincide with the edges or vertices are not considered as included.
func (Triangle2) InteriorsIntersect ¶
InteriorsIntersect returns whether the argument triangle's interior contains any points from the receiver triangle's interior or vice versa.
Here, triangles that only touch on their edges are not considered as overlapping.
func (Triangle2) InteriorsIntersectLineSeg ¶
InteriorsIntersectLineSeg returns whether the argument line segment shares any of its interior points with the receiver triangles interior.
Here, exterior line segments that only touch the edges or vertices of a triangle are not considered as overlapping.
func (Triangle2) SharesAnyVertexWith ¶
SharesAnyVertexWith reports whether the triangles share at least one vertex.
func (Triangle2) Winding ¶
Winding returns true if the receiver triangle's vertices are in anticlockwise order around the triangle's interior.
The viewpoint for defining the anticlockwise direction is that of a viewpoint somewhere on the positive Z-axis of a right handed coordinate system looking down on the triangle in the z=0 plane.
type Vec ¶
type Vec struct {
X, Y, Z float64
}
Vec is a three-dimensional position/direction vector.
func (Vec) AcuteAngle ¶
AcuteAngle returns the positive angle, measured in radians, in the range 0..Pi/2 inclusive between the directional line implied by the receiver vector and the directional line implied by the argument vector.
func (Vec) Add ¶
Add adds the receiver vector to the argument vector and returns the resulting vector.
func (Vec) Angle ¶
Angle returns the positive angle, measured in radians, between the receiver vector and the argument vector.
Special cases are:
- either vector is the zero vector: returns NaN
- either vector has an Inf or NaN element: returns NaN
func (Vec) DistTo ¶
DistTo returns the distance between the receiver position vector and the argument position vector.
func (Vec) DistToSqd ¶
DistToSqd returns the square of the distance between the receiver position vector and the argument position vector.
func (Vec) DivTo ¶
DivTo returns the position vector that divides the line segment from the receiver to the argument vector in the ratio a to b.
func (Vec) IsParallel ¶
IsParallel returns whether the positive angle between the receiver and argument vector's directions is either zero or Pi to within the given positive tolerance argument, measured in radians.
func (Vec) IsPerpendicular ¶
IsPerpendicular returns whether the positive angle between the receiver and argument vector's directions is Pi/2 to within the given positive tolerance argument, measured in radians.
func (Vec) Map ¶
Map returns the vector whose components are obtained by applying the argument function to each of the receiver vector's components.
func (Vec) MidTo ¶
MidTo adds the receiver vector to the argument vector, scales the result by 0.5, and returns the resulting vector.
func (Vec) Opposite ¶
Opposite returns a vector with the same magnitude as the receiver vector but with the opposite direction.
func (Vec) Perpendicular ¶
Perpendicular returns a unit vector which is normal to the receiver vector.
func (Vec) PlaneResolution ¶
PlaneResolution is the orthogonal projection of the receiver vector onto the argument plane.
func (Vec) Resolution ¶
Resolution is the orthogonal projection of the receiver vector onto a straight line parallel to the argument vector.
func (Vec) Scale ¶
Scale returns the scalar multiple of the receiver vector.
The magnitude of the returned vector is the product of the receiver vector's magnitude and the argument.
func (Vec) Subtract ¶
Subtract subtracts the receiver vector from the argument vector and returns the resulting vector.
type Vec2 ¶
type Vec2 struct {
X, Y float64
}
Vec2 is a two-dimensional position/direction vector.
func (Vec2) Add ¶
Add adds the receiver vector to the argument vector and returns the resulting vector.
func (Vec2) Angle ¶
Angle returns the positive angle, measured in radians, between the receiver vector and the argument vector.
Special cases are:
either vector is the zero vector = NaN either vector has an Inf or NaN element = NaN
func (Vec2) Anticlockwise ¶
Anticlockwise positive angle, measured in radians, between the receiver vector and the argument vector.
func (Vec2) Clockwise ¶
Clockwise positive angle, measured in radians, between the receiver vector and the argument vector.
func (Vec2) CosAngle ¶
CosAngle returns the cosine of the angle between the receiver vector and the argument vector.
func (Vec2) DistTo ¶
DistTo returns the distance between the receiver position vector and the argument position vector.
func (Vec2) DistToSqd ¶
DistToSqd returns the square of the distance between the receiver position vector and the argument position vector.
func (Vec2) IsParallel ¶
IsParallel returns whether the positive angle between the receiver and argument vector's directions is either zero or Pi to within the given positive tolerance argument, measured in radians.
func (Vec2) MidTo ¶
MidTo adds the receiver vector to the argument vector, scales the result by 0.5, and returns the resulting vector.
func (Vec2) Normal ¶
Normal returns a unit vector which has the direction of the result of rotating the receiver vector anticlockwise by Pi/2 radians.
func (Vec2) Scale ¶
Scale returns the scalar multiple of the receiver vector.
The magnitude of the returned vector is the product of the receiver vector's magnitude and the argument.
func (Vec2) To ¶
To returns the translation vector that if added to the receiver vector would yield the argument vector.