Documentation
¶
Index ¶
- Constants
- Variables
- func Abs[V constraints.Integer | constraints.Float](x V) V
- func Add2f(a [2]float32, b [2]float32) [2]float32
- func AngleBetween(v1, v2 [2]float32) float32
- func Atan(xFull float32) float32
- func Atan2(y, x float32) float32
- func BitsToFloat(ui uint32) float32
- func Ceil(v float32) float32
- func CirclePoints(nsegs int) [][2]float32
- func Clamp[T constraints.Ordered](x T, low T, high T) T
- func ClosestPointOnLine(line [2][2]float32, p [2]float32) [2]float32
- func Compass[T HeadingT](heading T) string
- func ConvexHull(points [][2]float32) [][2]float32
- func Cos(x float32) float32
- func Degrees(r float32) float32
- func Distance2f(a [2]float32, b [2]float32) float32
- func Dot(a, b [2]float32) float32
- func EquilateralTriangleVertices(height float32) [3][2]float32
- func Exponent(v float32) int
- func FastExp(x float32) float32
- func FloatToBits(f float32) uint32
- func Floor(v float32) float32
- func Heading2LL(from Point2LL, to Point2LL, nmPerLongitude float32, magCorrection float32) float32
- func HeadingAsHour[T HeadingT](heading T) int
- func HeadingDifference[T HeadingT](a, b T) T
- func HeadingSignedTurn[T HeadingT](cur, target T) T
- func HeadingVector(hdg float32) [2]float32
- func IsHeadingBetween[T HeadingT](h, h1, h2 T) bool
- func LL2NM(p Point2LL, nmPerLongitude float32) [2]float32
- func Length2f(v [2]float32) float32
- func Lerp(x, a, b float32) float32
- func Lerp2f(x float32, a [2]float32, b [2]float32) [2]float32
- func LineLineIntersect(p1f, p2f, p3f, p4f [2]float32) ([2]float32, bool)
- func Log(x float32) float32
- func Mid2f(a [2]float32, b [2]float32) [2]float32
- func Mod(a, b float32) float32
- func NMDistance2LL(a Point2LL, b Point2LL) float32
- func NMDistance2LLFast(a Point2LL, b Point2LL, nmPerLongitude float32) float32
- func NMLength2LL(a Point2LL, nmPerLongitude float32) float32
- func NMPerLongitudeAt(p Point2LL) float32
- func Normalize2f(a [2]float32) [2]float32
- func NormalizeHeading[T HeadingT](h T) T
- func OppositeHeading[T HeadingT](h T) T
- func Overlaps(a Extent2D, b Extent2D) bool
- func PointInPolygon(p [2]float32, pts [][2]float32) bool
- func PointInPolygon2LL(p Point2LL, pts []Point2LL) bool
- func PointLineDistance(p, p0, p1 [2]float32) float32
- func PointSegmentDistance(p, v, w [2]float32) float32
- func Pow(a, b float32) float32
- func Radians(d float32) float32
- func RayRayMinimumDistance(p0, d0, p1, d1 [2]float32) float32
- func Rotator2f(angle float32) func([2]float32) [2]float32
- func Round(v float32) float32
- func SafeACos(a float32) float32
- func SafeASin(a float32) float32
- func Scale2f(a [2]float32, s float32) [2]float32
- func SegmentSegmentIntersect(p1, p2, p3, p4 [2]float32) ([2]float32, bool)
- func SetLocationResolver(r LocationResolver)
- func ShortCompass[T HeadingT](heading T) string
- func Sign(v float32) float32
- func SignBit(v float32) bool
- func SignedPointLineDistance(p, p0, p1 [2]float32) float32
- func Significand(v float32) int
- func Sin(x float32) float32
- func SinCos(xFull float32) [2]float32
- func Sqr[V constraints.Integer | constraints.Float](v V) V
- func Sqrt(a float32) float32
- func Sub2f(a [2]float32, b [2]float32) [2]float32
- func Tan(xFull float32) float32
- func VectorHeading(v [2]float32) float32
- type CardinalOrdinalDirection
- type Extent2D
- func (e Extent2D) Center() [2]float32
- func (e Extent2D) ClosestPointInBox(p [2]float32) [2]float32
- func (e Extent2D) Expand(d float32) Extent2D
- func (e Extent2D) Height() float32
- func (e Extent2D) Inside(p [2]float32) bool
- func (e Extent2D) IntersectRay(org, dir [2]float32) (bool, float32, float32)
- func (e Extent2D) Lerp(p [2]float32) [2]float32
- func (e Extent2D) Offset(p [2]float32) Extent2D
- func (e Extent2D) Scale(s float32) Extent2D
- func (e Extent2D) Width() float32
- type HeadingT
- type LocationResolver
- type Matrix3
- func (m Matrix3) Determinant() float32
- func (m Matrix3) Inverse() Matrix3
- func (m Matrix3) Ortho(x0, x1, y0, y1 float32) Matrix3
- func (m Matrix3) PostMultiply(m2 Matrix3) Matrix3
- func (m Matrix3) Rotate(theta float32) Matrix3
- func (m Matrix3) Scale(x, y float32) Matrix3
- func (m Matrix3) TransformPoint(p [2]float32) [2]float32
- func (m Matrix3) TransformVector(p [2]float32) [2]float32
- func (m Matrix3) Translate(x, y float32) Matrix3
- type Point2LL
- func Add2LL(a Point2LL, b Point2LL) Point2LL
- func Mid2LL(a Point2LL, b Point2LL) Point2LL
- func NM2LL(p [2]float32, nmPerLongitude float32) Point2LL
- func Offset2LL(pll Point2LL, hdg float32, dist float32, ...) Point2LL
- func ParseLatLong(llstr []byte) (Point2LL, error)
- func Sub2LL(a Point2LL, b Point2LL) Point2LL
Constants ¶
const ( Pi = gomath.Pi InvPi = 0.31830988618379067154 Inv2Pi = 0.15915494309189533577 Inv4Pi = 0.07957747154594766788 PiOver2 = 1.57079632679489661923 PiOver4 = 0.78539816339744830961 FourOverPi = 1.27323949337005615234375 Sqrt2 = 1.41421356237309504880 )
Mathematical Constants
const ( North = iota NorthEast East SouthEast South SouthWest West NorthWest )
const FeetToNauticalMiles = 1 / NauticalMilesToFeet
const NMPerLatitude = 60
const NauticalMilesToFeet = 6076.12
Variables ¶
var Infinity float32 = float32(gomath.Inf(1))
Functions ¶
func Abs ¶
func Abs[V constraints.Integer | constraints.Float](x V) V
Abs returns the absolute value of x
func AngleBetween ¶
Equivalent to acos(Dot(a, b)), but more numerically stable. via http://www.plunk.org/~hatch/rightway.html
func Atan ¶
Atan computes atan(x) for a single float32 value Ported from syrah/FixedVectorMath.h:289
func Atan2 ¶
Atan2 computes atan2(y, x) for single float32 values Ported from syrah/FixedVectorMath.h:327
func BitsToFloat ¶
BitsToFloat converts a bit representation to float32
func CirclePoints ¶
CirclePoints returns the vertices for a unit circle at the origin with the given number of segments; it creates the vertex slice if this tessellation rate hasn't been seen before and otherwise returns a preexisting one.
func Clamp ¶
func Clamp[T constraints.Ordered](x T, low T, high T) T
Clamp restricts x to the range [low, high]
func ClosestPointOnLine ¶
ClosestPointOnLine returns the closest point on the (infinite) line to the given point p.
func Compass ¶
compass converts a heading expressed into degrees into a string corresponding to the closest compass direction.
func ConvexHull ¶
https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
func EquilateralTriangleVertices ¶
Returns the vertex coordinates of an equilateral triangle centered at the origin with specified height.
func FastExp ¶
FastExp computes e^x using a fast approximation Based on https://stackoverflow.com/a/10792321, translated from pbrt-v4's FastExp.
func FloatToBits ¶
FloatToBits converts a float32 to its bit representation
func Heading2LL ¶
Heading2LL returns the heading from the point |from| to the point |to| in degrees. The provided points should be in latitude-longitude coordinates and the provided magnetic correction is applied to the result.
func HeadingAsHour ¶
headingAsHour converts a heading expressed in degrees into the closest "o'clock" value, with an integer result in the range [1,12].
func HeadingDifference ¶
func HeadingDifference[T HeadingT](a, b T) T
HeadingDifference returns the minimum difference between two headings. (i.e., the result is always in the range [0,180].)
func HeadingSignedTurn ¶
func HeadingSignedTurn[T HeadingT](cur, target T) T
Figure out which way is closest: first find the angle to rotate the target heading by so that it's aligned with 180 degrees. This lets us not worry about the complexities of the wrap around at 0/360..
func HeadingVector ¶ added in v0.13.0
func IsHeadingBetween ¶ added in v0.13.0
IsHeadingBetween checks if heading h is between h1 and h2 (clockwise from h1 to h2). Returns true if h is in the clockwise arc from h1 to h2, inclusive of both endpoints.
func LL2NM ¶
LL2NM converts a point expressed in latitude-longitude coordinates to nautical mile coordinates; this is useful for example for reasoning about distances, since both axes then have the same measure.
func Lerp2f ¶
Linearly interpolate x of the way between a and b. x==0 corresponds to a, x==1 corresponds to b, etc.
func LineLineIntersect ¶
LineLineIntersect returns the intersection point of the two lines specified by the vertices (p1f, p2f) and (p3f, p4f). An additional returned Boolean value indicates whether a valid intersection was found. (There's no intersection for parallel lines, and none may be found in cases with tricky numerics.)
func Log ¶ added in v0.13.0
Log computes the natural logarithm (ln) for a single float32 value Ported from syrah/FixedVectorMath.h:495
func NMDistance2LL ¶
NMDistance2LL returns the distance in nautical miles between two provided lat-long coordinates.
func NMDistance2LLFast ¶
Fast but approximate distance between latlongs.
func NMLength2LL ¶
NMLength2ll returns the length of a vector expressed in lat-long coordinates.
func NMPerLongitudeAt ¶
NMPerLongitudeAt returns the number of nautical miles spanned by one degree of longitude at the given lat-long point.
func OppositeHeading ¶
func OppositeHeading[T HeadingT](h T) T
func PointInPolygon ¶
PointInPolygon checks whether the given point is inside the given polygon; it assumes that the last vertex does not repeat the first one, and so includes the edge from pts[len(pts)-1] to pts[0] in its test.
func PointInPolygon2LL ¶
func PointLineDistance ¶
PointLineDistance returns the minimum distance from the point p to the infinite line defined by (p0, p1).
func PointSegmentDistance ¶
Return minimum distance between line segment vw and point p https://stackoverflow.com/a/1501725
func RayRayMinimumDistance ¶
RayRayMinimumDistance takes two rays p0+d0*t and p1+d1*t and returns the value of t where their distance is minimized.
func Rotator2f ¶
rotator2f returns a function that rotates points by the specified angle (given in degrees).
func SegmentSegmentIntersect ¶
SegmentSegmentIntersect returns the intersection point of the two line segments specified by the vertices (p1, p2) and (p3, p4). An additional returned Boolean value indicates whether a valid intersection was found within both segments.
func SetLocationResolver ¶
func SetLocationResolver(r LocationResolver)
func ShortCompass ¶
ShortCompass converts a heading expressed in degrees into an abbreviated string corresponding to the closest compass direction.
func SignBit ¶
SignBit returns true if the given float32's sign bit is set. (i.e., it's non-negative)
func SignedPointLineDistance ¶
SignedPointLineDistance returns the signed distance from the point p to the infinite line defined by (p0, p1) where points to the right of the line have negative distances.
func SinCos ¶
SinCos computes sin(x) and cos(x) simultaneously for a single float32 value Ported from syrah/FixedVectorMath.h:152, which is via Abramowitz and Stegun.
func Sqr ¶
func Sqr[V constraints.Integer | constraints.Float](v V) V
func VectorHeading ¶
Types ¶
type CardinalOrdinalDirection ¶
type CardinalOrdinalDirection int
func ParseCardinalOrdinalDirection ¶
func ParseCardinalOrdinalDirection(s string) (CardinalOrdinalDirection, error)
func (CardinalOrdinalDirection) Heading ¶
func (co CardinalOrdinalDirection) Heading() float32
func (CardinalOrdinalDirection) ShortString ¶
func (co CardinalOrdinalDirection) ShortString() string
type Extent2D ¶
type Extent2D struct {
P0, P1 [2]float32
}
Extent2D represents a 2D bounding box with the two vertices at its opposite minimum and maximum corners.
func BoundLatLongCircle ¶
func EmptyExtent2D ¶
func EmptyExtent2D() Extent2D
EmptyExtent2D returns an Extent2D representing an empty bounding box.
func Extent2DFromP2LLs ¶
Extent2DFromP2LLs returns an Extent2D that bounds all of the provided points.
func Extent2DFromPoints ¶
Extent2DFromPoints returns an Extent2D that bounds all of the provided points.
func (Extent2D) ClosestPointInBox ¶
ClosestPointInBox returns the closest point to p that is inside the Extent2D. (If p is already inside it, then it is returned.)
func (Extent2D) IntersectRay ¶
IntersectRay find the intersections of the ray with given origin and direction with the Extent2D. The returned Boolean value indicates whether an intersection was found. If true, the two returned floating-point values give the parametric distances along the ray where the intersections occurred.
type LocationResolver ¶
type Matrix3 ¶
type Matrix3 [3][3]float32
func Identity3x3 ¶
func Identity3x3() Matrix3
func MakeMatrix3 ¶
func (Matrix3) Determinant ¶
func (Matrix3) PostMultiply ¶
func (Matrix3) TransformPoint ¶
func (Matrix3) TransformVector ¶
type Point2LL ¶
type Point2LL [2]float32
Point2LL represents a 2D point on the Earth in latitude-longitude. Important: 0 (x) is longitude, 1 (y) is latitude
func Offset2LL ¶
func Offset2LL(pll Point2LL, hdg float32, dist float32, nmPerLongitude, magneticVariation float32) Point2LL
Offset2LL returns the point at distance dist along the vector with heading hdg from the given point. It assumes a (locally) flat earth.
func ParseLatLong ¶
func (Point2LL) DDString ¶
DDString returns the position in decimal degrees, e.g.: (39.860901, -75.274864)
func (Point2LL) DMSString ¶
DMSString returns the position in degrees minutes, seconds, e.g. N039.51.39.243,W075.16.29.511
func (Point2LL) MarshalJSON ¶
Store Point2LLs as strings is JSON, for compactness/friendliness...