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 cmp.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 DMEDistance(a Point2LL, aAltitude float32, b Point2LL, bAltitude float32) float32
- func DecodePathBytes(stream []byte, out []Point2LL) (int, error)
- func Degrees(r float32) float32
- func Distance2f(a [2]float32, b [2]float32) float32
- func Dot(a, b [2]float32) float32
- func EncodePathBytes(b []byte, pts []Point2LL) []byte
- 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 HeadingAsHour[T HeadingT](heading T) int
- func HeadingDifference[T HeadingT](a, b T) float32
- func HeadingInTurnArc[T HeadingT](from, heading, to T, turn TurnDirection) bool
- func HeadingSignedTurn[T HeadingT](cur, target T) float32
- func HeadingVector(hdg TrueHeading) [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 NMDistanceToSegment2LL(p, a, b Point2LL) 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 OffsetHeading[T ~float32, D ~float32 | ~int](h T, delta D) 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[T ~float32](d T) float32
- func RayRayMinimumDistance(p0, d0, p1, d1 [2]float32) float32
- func RaySegmentIntersect(org, dir, p0, p1 [2]float32) ([2]float32, float32, float32, bool)
- 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 SplitSelfIntersectingPolygon(poly []Point2LL) [][]Point2LL
- 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
- type CardinalOrdinalDirection
- type Extent2D
- func BoundLatLongCircle(c Point2LL, r float32) Extent2D
- func EmptyExtent2D() Extent2D
- func Extent2DFromP2LLs(pts []Point2LL) Extent2D
- func Extent2DFromPoints(pts [][2]float32) Extent2D
- func Extent2DFromSeq(it iter.Seq[Point2LL]) Extent2D
- func Intersect(a, b Extent2D) Extent2D
- func Union(e Extent2D, p [2]float32) Extent2D
- func (e Extent2D) Center() [2]float32
- func (e Extent2D) ClosestPointInBox(p [2]float32) [2]float32
- func (e Extent2D) Corners() [][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) IsEmpty() bool
- 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 MagneticHeading
- 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 TrueHeading, dist float32, nmPerLongitude float32) Point2LL
- func ParseLatLong(llstr []byte) (Point2LL, error)
- func Sub2LL(a Point2LL, b Point2LL) Point2LL
- type RayRouteIntersection
- type TrueHeading
- type TurnDirection
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 FeetToNauticalMiles = 1 / NauticalMilesToFeet
const NMPerLatitude = 60
const NauticalMilesToFeet = 6076.12
const StatuteMilesToNauticalMiles = 1 / 1.15078
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 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 DMEDistance ¶ added in v0.14.3
DMEDistance returns the straight-line distance in nautical miles between two lat-long positions at the given altitudes in feet.
func DecodePathBytes ¶ added in v0.14.4
DecodePathBytes reads len(out)*8 bytes from stream and writes the decoded path into out. It returns the number of bytes consumed, or an error if stream is too short.
func EncodePathBytes ¶ added in v0.14.4
EncodePathBytes appends the encoded representation of pts to b and returns the extended slice. The output length is 8*len(pts).
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 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 ¶
HeadingDifference returns the minimum difference between two headings. (i.e., the result is always in the range [0,180].) The result is a plain angular delta, not a heading.
func HeadingInTurnArc ¶ added in v0.14.3
func HeadingInTurnArc[T HeadingT](from, heading, to T, turn TurnDirection) bool
func HeadingSignedTurn ¶
HeadingSignedTurn returns the signed angular delta to turn from cur to target. Positive is a right turn, negative is a left turn.
func HeadingVector ¶ added in v0.13.0
func HeadingVector(hdg TrueHeading) [2]float32
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 NMDistanceToSegment2LL ¶ added in v0.15.0
NMDistanceToSegment2LL returns the distance in nautical miles from p to the great-circle segment between a and b: the spherical cross-track distance where p lies abeam the segment and otherwise the distance to the nearer endpoint.
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 OffsetHeading ¶ added in v0.14.2
OffsetHeading adds an angular delta to a heading and normalizes the result, preserving the heading's type.
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 RaySegmentIntersect ¶ added in v0.14.3
RaySegmentIntersect returns the intersection point of the ray org+dir*t with the segment p0+(p1-p0)*u. The returned values include the ray parameter t and the segment parameter u.
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 SplitSelfIntersectingPolygon ¶ added in v0.14.1
SplitSelfIntersectingPolygon decomposes a possibly self-intersecting polygon into a slice of simple (non-self-intersecting) polygons. If the polygon is already simple, it is returned as a single-element slice.
func Sqr ¶
func Sqr[V constraints.Integer | constraints.Float](v V) V
Types ¶
type CardinalOrdinalDirection ¶
type CardinalOrdinalDirection int
const ( North CardinalOrdinalDirection = iota NorthEast East SouthEast South SouthWest West NorthWest )
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 Intersect ¶ added in v0.14.3
Intersect returns the rectangle that is the intersection of a and b. If the inputs do not overlap, the returned extent has P1 < P0 and IsEmpty returns true.
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) Corners ¶ added in v0.14.6
Corners returns the 4 corners of the associated box in counter-clockwise order.
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 MagneticHeading ¶ added in v0.14.2
type MagneticHeading float32
func TrueToMagnetic ¶ added in v0.14.2
func TrueToMagnetic(h TrueHeading, magneticVariation float32) MagneticHeading
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 TrueHeading, dist float32, nmPerLongitude float32) Point2LL
Offset2LL returns the point at distance dist along the vector with true 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...
func (*Point2LL) UnmarshalJSON ¶
type RayRouteIntersection ¶ added in v0.14.3
RayRouteIntersection describes a single point where a ray crosses a polyline segment. Index is the segment index in the polyline (the segment runs from route[Index] to route[Index+1]); SegT is the 0..1 parameter along that segment. Callers that need the nautical-mile distance from the ray origin compute it from (origin, Location) via NMDistance2LL.
func IntersectRayWithRoute ¶ added in v0.14.3
func IntersectRayWithRoute(origin Point2LL, heading TrueHeading, route []Point2LL) []RayRouteIntersection
IntersectRayWithRoute returns all segments of the polyline route that the ray from origin along the given true heading crosses, in route order. Internally converts to a local NM frame anchored at origin so the caller does not need to supply nmPerLongitude.
type TrueHeading ¶ added in v0.14.2
type TrueHeading float32
func GreatCircleHeading ¶ added in v0.15.0
func GreatCircleHeading(from, to Point2LL) TrueHeading
GreatCircleHeading returns the initial true heading from one point toward another along a great circle. The flat approximation Heading2LL uses is fine over a TRACON but not over an ocean: Tokyo is west of Anchorage the way an airplane flies and southeast of it the way a flat map draws, and it is the airplane that matters when the question is where traffic comes from.
func Heading2LL ¶
func Heading2LL(from Point2LL, to Point2LL, nmPerLongitude float32) TrueHeading
Heading2LL returns the true heading from the point |from| to the point |to| in degrees. The provided points should be in latitude-longitude coordinates.
func MagneticToTrue ¶ added in v0.14.2
func MagneticToTrue(h MagneticHeading, magneticVariation float32) TrueHeading
func VectorHeading ¶
func VectorHeading(v [2]float32) TrueHeading
type TurnDirection ¶ added in v0.14.3
type TurnDirection int
TurnDirection specifies the direction of a turn.
const ( TurnClosest TurnDirection = iota // default: turn the shortest direction TurnLeft TurnRight )