github.com/liucxer/courier@v1.7.1/h3/vec3d.go (about)

     1  package h3
     2  
     3  import "math"
     4  
     5  type Vec3d struct {
     6  	x float64 /// < x component
     7  	y float64 /// < y component
     8  	z float64 /// < z component
     9  }
    10  
    11  /**
    12   * Square of a number
    13   *
    14   * @param x The input number.
    15   * @return The square of the input number.
    16   */
    17  func _square(x float64) float64 { return x * x }
    18  
    19  /**
    20   * Calculate the square of the distance between two 3D coordinates.
    21   *
    22   * @param v1 The first 3D coordinate.
    23   * @param v2 The second 3D coordinate.
    24   * @return The square of the distance between the given points.
    25   */
    26  func _pointSquareDist(v1 *Vec3d, v2 *Vec3d) float64 {
    27  	return _square(v1.x-v2.x) + _square(v1.y-v2.y) + _square(v1.z-v2.z)
    28  }
    29  
    30  /**
    31   * Calculate the 3D coordinate on unit sphere from the latitude and longitude.
    32   *
    33   * @param geo The latitude and longitude of the point.
    34   * @param v The 3D coordinate of the point.
    35   */
    36  func _geoToVec3d(geo *GeoCoord, v *Vec3d) {
    37  	r := math.Cos(geo.Lat)
    38  	v.z = math.Sin(geo.Lat)
    39  	v.x = math.Cos(geo.Lon) * r
    40  	v.y = math.Sin(geo.Lon) * r
    41  }