Skip to content

Commit

Permalink
Go: added function HorizonFromVector.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinekitty committed Nov 1, 2023
1 parent b742aac commit eba2b50
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 46 deletions.
28 changes: 28 additions & 0 deletions generate/template/astronomy.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,34 @@ func EquatorFromVector(vector AstroVector) Equatorial {
}
}

// Converts cartesian coordinates to horizontal coordinates.
// Given a horizontal Cartesian vector, returns horizontal azimuth and altitude.
//
// IMPORTANT: This function differs from SphereFromVector in two ways:
// - SphereFromVector returns a `Lon` value that represents azimuth defined counterclockwise
// from north (e.g., west = +90), but this function represents a clockwise rotation
// (e.g., east = +90). The difference is because `SphereFromVector` is intended
// to preserve the vector "right-hand rule", while this function defines azimuth in a more
// traditional way as used in navigation and cartography.
// - This function optionally corrects for atmospheric refraction, while `SphereFromVector`
// does not.
//
// The returned structure contains the azimuth in `Lon`.
// It is measured in degrees clockwise from north: east = +90 degrees, west = +270 degrees.
//
// The altitude is stored in `Lat`.
//
// The distance to the observed object is stored in `Dist`,
// and is expressed in astronomical units (AU).
func HorizonFromVector(vector AstroVector, refraction Refraction) Spherical {
sphere := SphereFromVector(vector)
return Spherical{
sphere.Lat + RefractionAngle(refraction, sphere.Lat),
toggleAzimuthDirection(sphere.Lon),
sphere.Dist,
}
}

// Converts spherical coordinates to Cartesian coordinates.
func VectorFromSphere(sphere Spherical, time AstroTime) AstroVector {
radlat := RadiansFromDegrees(sphere.Lat)
Expand Down
Loading

0 comments on commit eba2b50

Please sign in to comment.