A PX4 based camera pointer

types.go 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2017 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. package pipoint
  16. // Position is a 3D point in geographic coordinates.
  17. type Position struct {
  18. Time float64
  19. Lat float64
  20. Lon float64
  21. Alt float64
  22. Heading float64
  23. }
  24. // NEUPosition is a 3D point on the local tangent plane.
  25. type NEUPosition struct {
  26. Time float64
  27. North float64
  28. East float64
  29. Up float64
  30. }
  31. // Attitude is the orientation of a body, often to the local tangent
  32. // plane.
  33. type Attitude struct {
  34. Roll float64
  35. Pitch float64
  36. Yaw float64
  37. }
  38. // ToNEU converts a geographic position to local tangent plane.
  39. func (p *Position) ToNEU() *NEUPosition {
  40. lat := AsRad(p.Lat)
  41. return &NEUPosition{
  42. Time: p.Time,
  43. North: LatLength(lat) * p.Lat,
  44. East: LonLength(lat) * p.Lon,
  45. Up: p.Alt,
  46. }
  47. }
  48. // Sub returns piecewise this minus right.
  49. func (p *NEUPosition) Sub(right *NEUPosition) *NEUPosition {
  50. return &NEUPosition{
  51. Time: p.Time - right.Time,
  52. North: p.North - right.North,
  53. East: p.East - right.East,
  54. Up: p.Up - right.Up,
  55. }
  56. }
  57. // Add returns piecewise this plus right.
  58. func (p *NEUPosition) Add(right *NEUPosition) *NEUPosition {
  59. return &NEUPosition{
  60. Time: p.Time + right.Time,
  61. North: p.North + right.North,
  62. East: p.East + right.East,
  63. Up: p.Up + right.Up,
  64. }
  65. }