* Calculates the speed vector based on the * great circle distance to destination and * current raw speed. */
| 146 | * current raw speed. |
| 147 | */ |
| 148 | void MovingTarget::calculateSpeed() |
| 149 | { |
| 150 | if (_dest != 0) |
| 151 | { |
| 152 | double dLon, dLat, length; |
| 153 | dLon = sin(_dest->getLongitude() - _lon) * cos(_dest->getLatitude()); |
| 154 | dLat = cos(_lat) * sin(_dest->getLatitude()) - sin(_lat) * cos(_dest->getLatitude()) * cos(_dest->getLongitude() - _lon); |
| 155 | length = sqrt(dLon * dLon + dLat * dLat); |
| 156 | _speedLat = dLat / length * _speedRadian; |
| 157 | _speedLon = dLon / length * _speedRadian / cos(_lat + _speedLat); |
| 158 | // Check for invalid speeds when a division by zero occurs due to near-zero values |
| 159 | if (!(_speedLon == _speedLon) || !(_speedLat == _speedLat)) |
| 160 | { |
| 161 | _speedLon = 0; |
| 162 | _speedLat = 0; |
| 163 | } |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | _speedLon = 0; |
| 168 | _speedLat = 0; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Checks if the moving target has reached its destination. |
nothing calls this directly
no test coverage detected