mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-12 15:33:45 +08:00
1ce9f73ae2
Add navigation and map matching providers with the vendored map service sources.
21 lines
368 B
Go
21 lines
368 B
Go
package math
|
|
|
|
type Line struct {
|
|
Start, End Position
|
|
}
|
|
|
|
type LinePosition struct {
|
|
Pos Position
|
|
T float64
|
|
}
|
|
|
|
func (l *Line) NearestPosition(pos Position) LinePosition {
|
|
AB := l.End.Subtract(l.Start)
|
|
AP := pos.Subtract(l.Start)
|
|
t := AP.Dot(AB) / AB.Dot(AB)
|
|
|
|
t = max(0, min(1, t))
|
|
closest := l.Start.Add(AB.Scale(t))
|
|
return LinePosition{Pos: closest, T: t}
|
|
}
|