maf

package module
v0.0.0-...-c7e50b2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: CC0-1.0 Imports: 10 Imported by: 35

README

Package maf

import "gitlab.com/fospathi/maf"

Go package maf is a basic maths package.

Development status

Package maf is unstable; expect breaking changes with every commit.

License

CC0
To the extent possible under law, Christian Stewart has waived all copyright and related or neighboring rights to maf. This work is published from: United Kingdom.

Documentation

Overview

Package maf provides maths functions and types.

Index

Constants

View Source
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

View Source
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)
)
View Source
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}
)
View Source
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()
)
View Source
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}
)
View Source
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)
)
View Source
var (
	// AffIdentity is the identity transformation.
	AffIdentity = Aff{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}
)
View Source
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.

View Source
var (
	// Z0Refl is a reflection transformation in the XY plane at z=0.
	Z0Refl = NewXYRefl()
)

Functions

func AbsLen

func AbsLen(a, b float64) float64

AbsLen returns the magnitude of the length between the argument values.

func CompareAff

func CompareAff(a1, a2 Aff, precision int) bool

CompareAff returns whether two affine transformations are approximately equal in an element-wise comparison.

func CompareBasis

func CompareBasis(b1, b2 Basis, precision int) bool

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

func CompareFrame(f1, f2 Frame, precision int) bool

CompareFrame returns whether two frames are approximately equal.

func CompareLine

func CompareLine(l1, l2 Line, tolerance float64, precision int) bool

CompareLine reports whether two lines approximately coincide.

func CompareMat4

func CompareMat4(m1, m2 Mat4, precision int) bool

CompareMat4 returns whether two matrices are approximately equal.

func CompareOrderedSegs

func CompareOrderedSegs(s1, s2 []LineSeg, precision int) bool

CompareOrderedSegs reports whether two slices contain, in the same order, approximately equal line segments with the same directions.

func CompareOrderedTriangle

func CompareOrderedTriangle(t1, t2 Triangle, precision int) bool

CompareOrderedTriangle reports whether the given triangles approximately coincide and label the vertices the same way.

func CompareOrderedVecs

func CompareOrderedVecs(v1, v2 []Vec, precision int) bool

CompareOrderedVecs returns whether two vector slices contain, in the same order, approximately equal vectors.

func CompareSeg

func CompareSeg(s1, s2 LineSeg, precision int) bool

CompareSeg reports whether two line segments are approximately equal and have the same direction.

func CompareTriangle

func CompareTriangle(t1, t2 Triangle, precision int) bool

CompareTriangle reports whether the given triangles approximately coincide.

func CompareTriangles

func CompareTriangles(v1, v2 []Triangle, precision int) bool

CompareTriangles reports whether two vector slices contain in any order the same approximately coinciding triangles.

func CompareVec

func CompareVec(v1, v2 Vec, precision int) bool

CompareVec returns whether two vectors are approximately equal.

func CompareVec2

func CompareVec2(v1, v2 Vec2, precision int) bool

CompareVec2 returns whether two vectors are approximately equal.

func CompareVecs

func CompareVecs(v1, v2 []Vec, precision int) bool

CompareVecs returns whether two vector slices contain in any order the same approximately equal vectors.

func CosineRule

func CosineRule(a, b, c float64) float64

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 DegToRad

func DegToRad(deg float64) float64

DegToRad converts the argument angle measured in degrees to radians.

func EllipsePerimeter

func EllipsePerimeter(a, b float64) float64

EllipsePerimeter approximation for the ellipse with semi-major axis length a and semi-minor axis length b.

func Lowest

func Lowest(n1, n2 int) int

Lowest returns the smallest of the two integer arguments.

func MinMax

func MinMax(n1, n2, n3 float64) (float64, float64)

MinMax returns the lowest and highest of three numbers.

func MinMaxInt

func MinMaxInt(n1, n2, n3 int) (int, int)

MinMaxInt returns the lowest and highest of three integers.

func ModuloPi

func ModuloPi(angle float64) float64

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 RadToDeg

func RadToDeg(rad float64) float64

RadToDeg converts the argument angle measured in radians to degrees.

func Round

func Round(f float64, precision int) float64

Round to the given number of sig figs after the decimal point.

func ScalarTripleProduct

func ScalarTripleProduct(a, b, c Vec) float64

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.

func SolveSLE2

func SolveSLE2(a1, b1, c1, a2, b2, c2 float64) (x float64, y float64, ok bool)

SolveSLE2 returns the solution of a simultaneous linear equation system with two variables:

a1*x + b1*y + c1 = 0
a2*x + b2*y + c2 = 0

The bool return value is false if no unique solution can be found.

Types

type Aff

type Aff [12]float64

Aff is a 3x4 affine transformation matrix. Elements are stored in column order.

func NewORot

func NewORot(v Vec, angle float64) Aff

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 NewRefl

func NewRefl(p Plane) Aff

NewRefl constructs a new reflection transformation in the argument plane.

func NewRot

func NewRot(l Line, angle float64) Aff

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

func NewTranslation(t Vec) Aff

NewTranslation constructs a new translation transformation using the argument as the translation.

func NewXRot

func NewXRot(angle float64) Aff

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

func NewYRot(angle float64) Aff

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

func NewYZReflAt(x float64) Aff

NewYZReflAt constructs a new reflection transformation in the YZ plane given by x = argument value.

func NewZRot

func NewZRot(angle float64) Aff

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

func (a1 Aff) CSS() string

CSS transform property value.

https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d.

func (Aff) Inverse

func (a1 Aff) Inverse() Aff

Inverse of the matrix.

If the inverse does not exist the result is undefined.

func (Aff) Multiply

func (a1 Aff) Multiply(a2 Aff) (affine Aff)

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

func (a1 Aff) ToMat3() Mat3

ToMat3 returns the equivalent 3x3 matrix of the receiver matrix.

The translation components are dropped.

func (Aff) ToMat4

func (a1 Aff) ToMat4() Mat4

ToMat4 returns the equivalent 4x4 matrix of the receiver matrix.

func (Aff) ToOpenGLMat4x3

func (a1 Aff) ToOpenGLMat4x3() OpenGLMat4x3

ToOpenGLMat4x3 returns the equivalent OpenGL float32 format matrix of the receiver matrix.

func (Aff) Transform

func (a1 Aff) Transform(v Vec) Vec

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

func (a1 Aff) TransformBez(b Bez) Bez

TransformBez multiplies the receiver matrix with the vertices of the argument Bezier and returns the resulting Bezier.

func (Aff) TransformFrame

func (a1 Aff) TransformFrame(fr Frame) Frame

TransformFrame applies the receiver transformation to the given frame.

func (Aff) TransformRay

func (a1 Aff) TransformRay(r Ray) Ray

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

func (a1 Annulus2) LineIntersection(l Line2) ([2]LineSeg2, int)

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.

func (Annulus2) LineSegIntersection

func (a1 Annulus2) LineSegIntersection(seg LineSeg2) ([2]LineSeg2, int)

LineSegIntersection returns the non-zero length segments, if any, of the given line segment 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

func (b1 Basis) In() Mat3

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

func (b1 Basis) InFrom(b Basis) Mat3

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

func (b1 Basis) Local(a Aff) Basis

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.

func (Basis) Out

func (b1 Basis) Out() Mat3

Out returns a transformation matrix that transforms a vector's coordinates in the receiver basis to the vector's coordinates in the implied reference basis.

func (Basis) OutTo

func (b1 Basis) OutTo(b Basis) Mat3

OutTo returns a transformation matrix that transforms a vector's coordinates in the receiver basis to the vector's coordinates in the argument basis.

type Bez

type Bez Triangle

Bez is a 3D quadratic Bezier curve.

func (Bez) AngleB

func (b1 Bez) AngleB() float64

AngleB returns the positive angle subtended at the vertex B by the edge AC.

func (Bez) ArcLength

func (b1 Bez) ArcLength() float64

ArcLength returns the length of the receiver Bezier curve.

func (Bez) AtT

func (b1 Bez) AtT(t float64) Vec

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

func (b1 Bez) BendingEnergy() float64

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

func (b1 Bez) IsCollinear(tolerance float64) bool

IsCollinear returns whether the receiver Bezier is, to within the argument tolerance, a degenerate straight line case.

func (Bez) Plane

func (b1 Bez) Plane() Plane

Plane returns a new plane which coincides with the receiver Bezier curve.

func (Bez) PlaneIntersections

func (b1 Bez) PlaneIntersections(p Plane) (int, float64, float64)

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

func (b1 Bez) PlaneTangencyLocus(plane Plane) Line

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

func (b1 Bez) Subdivide1(t float64) (Bez, Bez)

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

func (b1 Bez) Subdivide2(t1, t2 float64) (Bez, Bez, Bez)

Subdivide2 returns the result of dividing the receiver Bezier curve into three pieces at the two argument parameters in the interval 0..1.

func (Bez) Tangent

func (b1 Bez) Tangent(t float64) Line

Tangent returns the tangent line to the receiver Bezier curve at the argument parameter.

The argument parameter is valid in the closed interval 0..1.

type Bez2

type Bez2 Triangle2

Bez2 is a 2D quadratic Bezier curve.

func (Bez2) AtT

func (b1 Bez2) AtT(t float64) Vec2

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.

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

func (c1 Circle) PlaneIntersections(p Plane) (int, Vec, Vec)

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

func (c1 Circle) RandPoints(n int) []Vec

RandPoints anywhere on the surface of the circle.

func (Circle) TangentPositions

func (c1 Circle) TangentPositions(p Vec) (Vec, Vec)

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

func (c1 Circle2) LineIntersections(l Line2) ([2]Vec2, bool)

LineIntersections with the circle.

func (Circle2) RandPoints

func (c1 Circle2) RandPoints(n int) []Vec2

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)

func (ExpSin) At

func (es ExpSin) At(x float64) float64

At returns the value of the receiver expression at the argument variable value.

func (ExpSin) D

func (es ExpSin) D(n int) func(float64) float64

D returns the nth derivative of the receiver expression where n is given by the argument.

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

func NewFrame(parts ...Vec) Frame

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

func (f1 Frame) Global(a Aff) Frame

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

func (f1 Frame) GlobalDis(v Vec) Frame

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

func (f1 Frame) In() Aff

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

func (f1 Frame) InFrom(f Frame) Aff

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

func (f1 Frame) Local(a Aff) Frame

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

func (f1 Frame) LocalDis(v Vec) Frame

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

func (f1 Frame) LocalDisNegX(d float64) Frame

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

func (f1 Frame) LocalDisNegXNegZ(d float64) Frame

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

func (f1 Frame) LocalDisNegXPosZ(d float64) Frame

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

func (f1 Frame) LocalDisNegY(d float64) Frame

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

func (f1 Frame) LocalDisNegZ(d float64) Frame

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

func (f1 Frame) LocalDisPosX(d float64) Frame

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

func (f1 Frame) LocalDisPosXNegZ(d float64) Frame

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

func (f1 Frame) LocalDisPosXPosZ(d float64) Frame

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

func (f1 Frame) LocalDisPosY(d float64) Frame

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

func (f1 Frame) LocalDisPosZ(d float64) Frame

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

func (f1 Frame) LocalRot(l Line, angle float64) Frame

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

func (f1 Frame) LocalRotBasis(v Vec, angle float64) Frame

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

func (f1 Frame) LocalRotNegX(angle float64) Frame

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

func (f1 Frame) LocalRotNegY(angle float64) Frame

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

func (f1 Frame) LocalRotNegZ(angle float64) Frame

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

func (f1 Frame) LocalRotPosX(angle float64) Frame

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

func (f1 Frame) LocalRotPosY(angle float64) Frame

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

func (f1 Frame) LocalRotPosZ(angle float64) Frame

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

func (f1 Frame) Out() (affine Aff)

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

func (f1 Frame) OutTo(f Frame) Aff

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

func (f1 Frame) PlotXY(p Vec2) Vec

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

func (f1 Frame) View(p Vec) Frame

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

func EquiangularLatitudes(R float64, n int) []LatHR

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

func EquidistantLatitudes(R float64, n int) []LatHR

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) Closest

func (l1 Line) Closest(p Vec) Vec

Closest point on the receiver line to the argument point.

func (Line) ClosestPoint

func (l1 Line) ClosestPoint(l2 Line) Vec

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

func (l1 Line) ClosestPoints(l2 Line) (Vec, Vec, bool)

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

func (l1 Line) DistTo(p Vec) float64

DistTo returns the magnitude of the orthogonal distance of the argument position vector to the receiver line.

func (Line) IsParallel

func (l1 Line) IsParallel(l2 Line, tolerance float64) bool

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

func (l1 Line) PlaneIntersection(p Plane) Vec

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

func (l1 Line2) Closest(l2 Line2) (Vec2, Vec2, bool)

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

func (l1 Line2) ClosestApproach(p Vec2) Vec2

ClosestApproach on the line to the given point.

func (Line2) ClosestPoint

func (l1 Line2) ClosestPoint(l2 Line2) Vec2

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

func (l1 LineSeg) AtT(t float64) Vec

AtT returns the position vector on the receiver line segment at the argument proportion of the distance from P1 to P2.

func (LineSeg) Closest

func (l1 LineSeg) Closest(p Vec) Vec

Closest returns the point on the receiver line segment that is closest to the argument point.

func (LineSeg) Midpoint

func (l1 LineSeg) Midpoint() Vec

Midpoint of the line segment.

type LineSeg2

type LineSeg2 struct {
	P1, P2 Vec2
}

LineSeg2 is a line segment in 2D space defined by two points.

func (LineSeg2) AtT

func (ls1 LineSeg2) AtT(t float64) Vec2

AtT maps a parameterisation of a point on the receiver segment's extended line back to a point on the line.

func (LineSeg2) Canonical

func (ls1 LineSeg2) Canonical() LineSeg2

Canonical undirected form of the line segment.

func (LineSeg2) DistTo

func (ls1 LineSeg2) DistTo(P Vec2) float64

DistTo returns the shortest distance from the receiver line segment to the argument point.

func (LineSeg2) Higher

func (ls1 LineSeg2) Higher(z float64) LineSeg

Higher dimension triangle with the new dimension set to the given value.

func (LineSeg2) InteriorsIntersect

func (ls1 LineSeg2) InteriorsIntersect(ls2 LineSeg2) bool

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

func (ls1 LineSeg2) InteriorsIntersectAny(lineSegs ...LineSeg2) bool

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) Len

func (ls1 LineSeg2) Len() float64

Len is the length of the line segment.

func (LineSeg2) Line

func (ls1 LineSeg2) Line() Line2

Line through the line segment.

func (LineSeg2) PerpBis

func (ls1 LineSeg2) PerpBis() Line2

PerpBis returns the perpendicular bisector of the line segment.

func (LineSeg2) Right

func (ls1 LineSeg2) Right(p Vec2) bool

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

func (ls1 LineSeg2) T(p Vec2) float64

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.

func New2DRotO

func New2DRotO(angle float64) Mat2

New2DRotO constructs a new rotation around the origin in the XY-plane.

The argument specifies the angle of rotation measured in radians.

A positive rotation angle indicates an anticlockwise rotation.

func (Mat2) Transform

func (m1 Mat2) Transform(v Vec2) Vec2

Transform multiplies the receiver matrix with the argument vector and returns the resulting vector.

type Mat3

type Mat3 [9]float64

Mat3 is a square 3x3 matrix. Elements are stored in column order.

func (Mat3) CSS

func (m1 Mat3) CSS() string

CSS transform property value.

https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d.

func (Mat3) Det

func (m1 Mat3) Det() float64

Det is the determinant.

func (Mat3) Inverse

func (m1 Mat3) Inverse() Mat3

Inverse of the matrix.

If the inverse does not exist, return the identity matrix.

func (Mat3) Multiply

func (m1 Mat3) Multiply(m2 Mat3) Mat3

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 (Mat3) ToAff

func (m1 Mat3) ToAff() Aff

ToAff returns the equivalent Affine matrix of the receiver matrix.

func (Mat3) Transform

func (m1 Mat3) Transform(v Vec) Vec

Transform multiplies the receiver matrix with the argument vector and returns the resulting vector.

func (Mat3) Transpose

func (m1 Mat3) Transpose() Mat3

Transpose returns the transpose of the receiver matrix.

The ith rows in the receiver matrix are the ith columns of the returned matrix.

type Mat4

type Mat4 [16]float64

Mat4 is a square 4x4 matrix. Elements are stored in column order.

func (Mat4) CSS

func (m1 Mat4) CSS() string

CSS transform property value.

https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d.

func (Mat4) Det

func (m1 Mat4) Det() float64

Det is the determinant.

func (Mat4) Multiply

func (m1 Mat4) Multiply(m2 Mat4) Mat4

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

func (m1 Mat4) RowMajorSlice() []float64

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.

func (Mat4) Transform

func (m1 Mat4) Transform(v Vec4) Vec4

Transform multiplies the receiver matrix with the argument vector and returns the resulting vector.

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

func (p1 Plane) Closest(p Vec) Vec

Closest returns the closest point on the receiver plane to the argument point.

func (Plane) DistTo

func (p1 Plane) DistTo(p Vec) float64

DistTo returns the magnitude of the orthogonal distance of the argument position vector to the receiver plane.

func (Plane) IsParallel

func (p1 Plane) IsParallel(v Vec, tolerance float64) bool

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

func (p1 Plane) PlaneIntersection(p2 Plane) Line

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

func (p1 Plane) SignedDistTo(p Vec) float64

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

func (p Poly) At(x float64) float64

At evaluates the polynomial as a function at the argument polynomial variable value.

func (Poly) Derivative

func (p Poly) Derivative() Poly

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.

func (Poly) Integral

func (p Poly) Integral(integral, variable float64) Poly

Integral returns the result of integrating the receiver polynomial with respect to the variable.

In order that the constant of integration can be found the required arguments are the value of the integrated polynomial for a particular value of the variable.

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.

func (Ray) PlaneIntersection

func (r1 Ray) PlaneIntersection(p Plane) (Vec, bool)

PlaneIntersection returns, if it exists, the single intersection point of the receiver ray and argument plane.

If there is no single intersection point the returned bool value is false.

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

func (s1 Sphere) Circle(plane Plane) 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

func (s1 Sphere) InteriorsIntersect(s2 Sphere) bool

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

func (t1 Triangle) BisectorAC() Vec

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

func (t1 Triangle) Centroid() Vec

Centroid returns the arithmetic mean of the receiver triangle's vertices.

func (Triangle) Circumcircle

func (t1 Triangle) Circumcircle() Circle

Circumcircle returns the unique circle that circumscribes the receiver triangle's vertices.

func (Triangle) Coincide

func (t1 Triangle) Coincide(t2 Triangle) bool

Coincide reports whether the triangles share the same vertices.

func (Triangle) DivideAC

func (t1 Triangle) DivideAC(s, t float64) Vec

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

func (t1 Triangle) EnclosingSphere() Sphere

EnclosingSphere returns a sphere that the receiver triangle's vertices are not outside of.

func (Triangle) Plane

func (t1 Triangle) Plane() Plane

Plane returns a new plane which coincides with the receiver triangle's intrinsic plane.

func (Triangle) Scale

func (t1 Triangle) Scale(k float64) Triangle

Scale the triangle about its centroid.

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

func (tr1 Triangle2) AltitudeRatioA(P Vec2) float64

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

func (tr1 Triangle2) AltitudeRatioB(P Vec2) float64

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

func (tr1 Triangle2) AltitudeRatioC(P Vec2) float64

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

func (t1 Triangle2) Anticlockwise() Triangle2

Anticlockwise triangle with the same vertices.

func (Triangle2) Canonical

func (t1 Triangle2) Canonical() Triangle2

Canonical form of the triangle.

func (Triangle2) Circumcircle

func (t1 Triangle2) Circumcircle() Circle2

Circumcircle returns the unique circle that circumscribes the receiver triangle's vertices.

func (Triangle2) CircumcircleContains

func (t1 Triangle2) CircumcircleContains(p Vec2) bool

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

func (tr1 Triangle2) ClosureIncludes(P Vec2) bool

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

func (tr1 Triangle2) ClosureIncludesAll(points ...Vec2) bool

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

func (tr1 Triangle2) ClosureIncludesAny(points ...Vec2) bool

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

func (t1 Triangle2) CoincidesWith(t2 Triangle2) bool

CoincidesWith reports whether the triangles share the same vertices.

func (Triangle2) Edges

func (t1 Triangle2) Edges() [3]LineSeg2

Edges of the triangle.

func (Triangle2) Higher

func (t1 Triangle2) Higher(z float64) Triangle

Higher dimension triangle with the new dimension set to the given value.

func (Triangle2) InteriorIncludes

func (tr1 Triangle2) InteriorIncludes(P Vec2) bool

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

func (tr1 Triangle2) InteriorIncludesAny(points ...Vec2) bool

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

func (tr1 Triangle2) InteriorsIntersect(tr2 Triangle2) bool

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

func (tr1 Triangle2) InteriorsIntersectLineSeg(ls LineSeg2) bool

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

func (t1 Triangle2) SharesAnyVertexWith(t2 Triangle2) bool

SharesAnyVertexWith reports whether the triangles share at least one vertex.

func (Triangle2) Vertices

func (t1 Triangle2) Vertices() [3]Vec2

Vertices of the triangle.

func (Triangle2) Winding

func (tr1 Triangle2) Winding() bool

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 RoundVec

func RoundVec(v Vec, precision int) Vec

RoundVec components to the given number of sig figs after the decimal point.

func (Vec) AcuteAngle

func (v1 Vec) AcuteAngle(v2 Vec) (rads float64)

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

func (v1 Vec) Add(v2 Vec) Vec

Add adds the receiver vector to the argument vector and returns the resulting vector.

func (Vec) Angle

func (v1 Vec) Angle(v2 Vec) (rads float64)

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) Cross

func (v1 Vec) Cross(v2 Vec) Vec

Cross returns the vector product of the receiver vector and the argument vector.

func (Vec) DistTo

func (v1 Vec) DistTo(v2 Vec) float64

DistTo returns the distance between the receiver position vector and the argument position vector.

func (Vec) DistToSqd

func (v1 Vec) DistToSqd(v2 Vec) float64

DistToSqd returns the square of the distance between the receiver position vector and the argument position vector.

func (Vec) DivTo

func (v1 Vec) DivTo(v2 Vec, a float64, b float64) Vec

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) Dot

func (v1 Vec) Dot(v2 Vec) float64

Dot returns the dot product of the receiver vector and the argument vector.

func (Vec) Higher

func (v1 Vec) Higher(w float64) Vec4

Higher dimension vector with the new dimension set to the given value.

func (Vec) IsParallel

func (v1 Vec) IsParallel(v2 Vec, tolerance float64) bool

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

func (v1 Vec) IsPerpendicular(v2 Vec, tolerance float64) bool

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) Lower

func (v1 Vec) Lower() Vec2

Lower dimension vector.

func (Vec) Mag

func (v1 Vec) Mag() float64

Mag returns the length of the receiver vector.

func (Vec) MagSqd

func (v1 Vec) MagSqd() float64

MagSqd returns the square of the length of the receiver vector.

func (Vec) Map

func (v1 Vec) Map(f func(float64) float64) Vec

Map returns the vector whose components are obtained by applying the argument function to each of the receiver vector's components.

func (Vec) MidTo

func (v1 Vec) MidTo(v2 Vec) Vec

MidTo adds the receiver vector to the argument vector, scales the result by 0.5, and returns the resulting vector.

func (Vec) Opposite

func (v1 Vec) Opposite() Vec

Opposite returns a vector with the same magnitude as the receiver vector but with the opposite direction.

func (Vec) Perpendicular

func (v1 Vec) Perpendicular() Vec

Perpendicular returns a unit vector which is normal to the receiver vector.

func (Vec) PlaneResolution

func (v1 Vec) PlaneResolution(p Plane) Vec

PlaneResolution is the orthogonal projection of the receiver vector onto the argument plane.

func (Vec) Resolution

func (v1 Vec) Resolution(v2 Vec) Vec

Resolution is the orthogonal projection of the receiver vector onto a straight line parallel to the argument vector.

func (Vec) Scale

func (v1 Vec) Scale(k float64) Vec

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

func (v1 Vec) Subtract(v2 Vec) Vec

Subtract subtracts the receiver vector from the argument vector and returns the resulting vector.

func (Vec) To

func (v1 Vec) To(v2 Vec) Vec

To returns the translation vector that if added to the receiver vector would yield the argument vector.

func (Vec) Unit

func (v1 Vec) Unit() Vec

Unit returns a vector which has the same direction as the receiver vector and a magnitude of 1. The receiver vector shall have non-zero magnitude.

type Vec2

type Vec2 struct {
	X, Y float64
}

Vec2 is a two-dimensional position/direction vector.

func (Vec2) Add

func (v1 Vec2) Add(v2 Vec2) Vec2

Add adds the receiver vector to the argument vector and returns the resulting vector.

func (Vec2) Angle

func (v1 Vec2) Angle(v2 Vec2) (rads float64)

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

func (v1 Vec2) Anticlockwise(v2 Vec2) float64

Anticlockwise positive angle, measured in radians, between the receiver vector and the argument vector.

func (Vec2) Clockwise

func (v1 Vec2) Clockwise(v2 Vec2) float64

Clockwise positive angle, measured in radians, between the receiver vector and the argument vector.

func (Vec2) CosAngle

func (v1 Vec2) CosAngle(v2 Vec2) float64

CosAngle returns the cosine of the angle between the receiver vector and the argument vector.

func (Vec2) DistTo

func (v1 Vec2) DistTo(v2 Vec2) float64

DistTo returns the distance between the receiver position vector and the argument position vector.

func (Vec2) DistToSqd

func (v1 Vec2) DistToSqd(v2 Vec2) float64

DistToSqd returns the square of the distance between the receiver position vector and the argument position vector.

func (Vec2) Dot

func (v1 Vec2) Dot(v2 Vec2) float64

Dot returns the dot product of the receiver vector and the argument vector.

func (Vec2) Higher

func (v1 Vec2) Higher(z float64) Vec

Higher dimension vector with the new dimension set to the given value.

func (Vec2) IsParallel

func (v1 Vec2) IsParallel(v2 Vec2, tolerance float64) bool

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) Mag

func (v1 Vec2) Mag() float64

Mag returns the length of the receiver vector.

func (Vec2) MagSqd

func (v1 Vec2) MagSqd() float64

MagSqd returns the square of the length of the receiver vector.

func (Vec2) MidTo

func (v1 Vec2) MidTo(v2 Vec2) Vec2

MidTo adds the receiver vector to the argument vector, scales the result by 0.5, and returns the resulting vector.

func (Vec2) Normal

func (v1 Vec2) Normal() Vec2

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

func (v1 Vec2) Scale(k float64) Vec2

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

func (v1 Vec2) To(v2 Vec2) Vec2

To returns the translation vector that if added to the receiver vector would yield the argument vector.

func (Vec2) Unit

func (v1 Vec2) Unit() Vec2

Unit returns a vector which has the same direction as the receiver vector and a magnitude of 1. The receiver vector shall have non-zero magnitude.

func (Vec2) Vec

func (v1 Vec2) Vec() Vec

Vec returns the three dimensional equivalent of the receiver vector.

type Vec4

type Vec4 struct {
	X, Y, Z, W float64
}

Vec4 is a four-dimensional position/direction vector.

func (Vec4) Lower

func (v1 Vec4) Lower() Vec

Lower dimension vector.

Directories

Path Synopsis
Package kirv is a library of elementary curves.
Package kirv is a library of elementary curves.

Jump to

Keyboard shortcuts

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