Documentation
¶
Index ¶
- Constants
- 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 Atan2(y, x float32) 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(heading float32) string
- func Cos(a 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 Exp(x float32) float32
- func Floor(v float32) float32
- func GCD(a, b int) int
- func GenRange[T constraints.Integer | constraints.Float](low, high, step T) []T
- func Heading2LL(from Point2LL, to Point2LL, nmPerLongitude float32, magCorrection float32) float32
- func HeadingAsHour(heading float32) int
- func HeadingDifference(a float32, b float32) float32
- func LCM(a, b int) int
- 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 Max[T constraints.Ordered](a, b T) T
- func Mid2f(a [2]float32, b [2]float32) [2]float32
- func Min[T constraints.Ordered](a, b T) T
- func Mod(a, b float32) float32
- func NMDistance2LL(a Point2LL, b Point2LL) float32
- func NMLength2LL(a Point2LL, nmPerLongitude float32) float32
- func NMPerLongitude(p Point2LL) float32
- func Normalize2f(a [2]float32) [2]float32
- func NormalizeHeading(h float32) float32
- func OppositeHeading(h float32) float32
- 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 SafeACos(a float32) float32
- func SafeASin(a float32) float32
- func Scale2f(a [2]float32, s float32) [2]float32
- func SetLocationResolver(r LocationResolver)
- func ShortCompass(heading float32) string
- func Sign(v float32) float32
- func SignedPointLineDistance(p, p0, p1 [2]float32) float32
- func Sin(a float32) 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(a 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 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
Constants ¶
const ( North = iota NorthEast East SouthEast South SouthWest West NorthWest )
const FeetToNauticalMiles = 1 / NauticalMilesToFeet
const NMPerLatitude = 60
const NauticalMilesToFeet = 6076.12
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[V constraints.Integer | constraints.Float](x V) V
func AngleBetween ¶
Equivalent to acos(Dot(a, b)), but more numerically stable. via http://www.plunk.org/~hatch/rightway.html
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
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 EquilateralTriangleVertices ¶
Returns the vertex coordinates of an equilateral triangle centered at the origin with specified height.
func GenRange ¶
func GenRange[T constraints.Integer | constraints.Float](low, high, step T) []T
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 ¶
HeadingDifference returns the minimum difference between two headings. (i.e., the result is always in the range [0,180].)
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 Max ¶
func Max[T constraints.Ordered](a, b T) T
func Min ¶
func Min[T constraints.Ordered](a, b T) T
func NMDistance2LL ¶
NMDistance2ll returns the distance in nautical miles between two provided lat-long coordinates.
func NMLength2LL ¶
NMLength2ll returns the length of a vector expressed in lat-long coordinates.
func NMPerLongitude ¶
func OppositeHeading ¶
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 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 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 Sqr ¶
func Sqr[V constraints.Integer | constraints.Float](v V) V
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 EmptyExtent2D ¶
func EmptyExtent2D() Extent2D
EmptyExtent2D returns an Extent2D representing an empty bounding box.
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 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...