| 231 | | ' /* vac_duration in seconds */ |
| 232 | | '48 void move_boat_loxo(boat *aboat) { |
| 233 | | '49 double speed; |
| 234 | | '50 double latitude, t_lat; |
| 235 | | '51 double vac_l, d; |
| 236 | | '52 double longitude; |
| 237 | | '53 int vac_duration; |
| 238 | | '54 wind_info *wind; |
| 239 | | '55: |
| 240 | | '56 vac_duration = aboat->in_race->vac_duration; |
| 241 | | '57 /* compute the heading based on the function used */ |
| 242 | | '58 aboat->set_heading_func(aboat); |
| 243 | | '59 wind = &aboat->wind; |
| 244 | | '60: |
| 245 | | '61 speed = find_speed(aboat, wind->speed, wind->angle - aboat->heading); |
| 246 | | '62: |
| 247 | | '63 vac_l = speed*(vac_duration/3600.0); |
| 248 | | '64: |
| 249 | | '65 d = degToRad(vac_l/60.0); |
| | 199 | |
| 264 | | 'Public Function ReachDistanceGC(ByVal Dist As Double) As Coords |
| 265 | | |
| 266 | | ' Dim A As Double |
| 267 | | ' Dim B As Double |
| 268 | | ' Dim f As Double |
| 269 | | ' Dim x As Double |
| 270 | | ' Dim y As Double |
| 271 | | ' Dim z As Double |
| 272 | | ' Dim RetVal As New Coords |
| 273 | | |
| 274 | | |
| 275 | | ' Dist /= Earth_Radius |
| 276 | | ' f = Dist / DistanceAngle |
| 277 | | |
| 278 | | |
| 279 | | ' A = Sin((1 - f) * DistanceAngle) / Sin(DistanceAngle) |
| 280 | | ' B = Sin(f * DistanceAngle) / Sin(DistanceAngle) |
| 281 | | ' x = A * Cos(StartPoint.Lat) * Cos(StartPoint.Lon) + B * Cos(EndPoint.Lat) * Cos(EndPoint.Lon) |
| 282 | | ' y = A * Cos(StartPoint.Lat) * Sin(StartPoint.Lon) + B * Cos(EndPoint.Lat) * Sin(EndPoint.Lon) |
| 283 | | ' z = A * Sin(StartPoint.Lat) + B * Sin(EndPoint.Lat) |
| 284 | | ' RetVal.Lat = Atan2(z, Sqrt(x ^ 2 + y ^ 2)) |
| 285 | | ' RetVal.Lon = Atan2(y, x) |
| 286 | | |
| 287 | | ' Return RetVal |
| 288 | | |
| 289 | | 'End Function |
| 290 | | |
| 291 | | 'Public Function ReachLat(ByVal Lat As Double, ByVal Course As Double) As Boolean |
| 292 | | |
| 293 | | ' Dim d As Double |
| 294 | | ' Dim CourseCorrection As Double = Course |
| 295 | | |
| 296 | | ' SyncLock Me |
| 297 | | ' If EndPoint Is Nothing Then |
| 298 | | ' EndPoint = New Coords |
| 299 | | ' End If |
| 300 | | |
| 301 | | ' If Abs(Cos(Course)) < EPSILON Then |
| 302 | | ' EndPoint.Lat = Lat |
| 303 | | ' EndPoint.Lon = StartPoint.Lon + Math.PI |
| 304 | | ' Return True |
| 305 | | ' End If |
| 306 | | |
| 307 | | |
| 308 | | ' EndPoint.Lat = StartPoint.Lat |
| 309 | | ' EndPoint.Lon = StartPoint.Lon |
| 310 | | |
| 311 | | ' Do |
| 312 | | ' 'CourseCorrection = Course |
| 313 | | ' d = Abs(EndPoint.Lat - Lat) |
| 314 | | ' If Double.IsNaN(d) Then |
| 315 | | ' Return False |
| 316 | | ' End If |
| 317 | | ' EndPoint.Lat += d * Cos(CourseCorrection) |
| 318 | | ' EndPoint.Lon -= d * Sin(CourseCorrection) |
| 319 | | |
| 320 | | ' 'Correct coefficient for course error |
| 321 | | ' CourseCorrection += (TrueCourse() - Course) |
| 322 | | ' 'Debug.WriteLine("Course " & CourseCorrection / PI * 180 & " D : " & d & " endpoint " & EndPoint.Lat_Deg & " " & EndPoint.Lon_Deg) |
| 323 | | |
| 324 | | ' Loop Until Abs(EndPoint.Lat - Lat) < EPSILON 'Or Double.IsNaN(CourseCorrection) |
| 325 | | ' Return True |
| 326 | | ' End SyncLock |
| 327 | | 'End Function |
| 328 | | |
| 329 | | ' Public Function ReachLon(ByVal Lon As Double, ByVal Course As Double) As Boolean |
| 330 | | |
| 331 | | ' Dim d As Double |
| 332 | | ' Dim factor As Integer = 1 |
| 333 | | 'start: |
| 334 | | ' Dim CourseCorrection As Double = Course |
| 335 | | ' SyncLock Me |
| 336 | | ' If EndPoint Is Nothing Then |
| 337 | | ' EndPoint = New Coords |
| 338 | | ' End If |
| 339 | | |
| 340 | | ' If Abs(Sin(Course)) <= EPSILON Then |
| 341 | | ' EndPoint.Lat = StartPoint.Lat + Math.PI |
| 342 | | ' EndPoint.Lon = Lon |
| 343 | | ' Return True |
| 344 | | ' End If |
| 345 | | |
| 346 | | |
| 347 | | ' EndPoint.Lat = StartPoint.Lat |
| 348 | | ' EndPoint.Lon = StartPoint.Lon |
| 349 | | |
| 350 | | ' Do |
| 351 | | ' 'CourseCorrection = Course |
| 352 | | ' d = Abs(EndPoint.Lon - Lon) |
| 353 | | ' If Double.IsNaN(d) Then |
| 354 | | ' Dim i As Integer = 0 |
| 355 | | ' Return False |
| 356 | | ' End If |
| 357 | | ' If Abs(EndPoint.Lat + factor * d * Cos(CourseCorrection)) > PI / 2 Then |
| 358 | | ' factor = -factor |
| 359 | | |
| 360 | | ' End If |
| 361 | | ' EndPoint.Lat += factor * d * Cos(CourseCorrection) |
| 362 | | ' EndPoint.Lon -= d * Sin(CourseCorrection) |
| 363 | | |
| 364 | | |
| 365 | | ' 'Correct coefficient for course error |
| 366 | | ' CourseCorrection -= (TrueCourse() - Course) |
| 367 | | ' 'Debug.WriteLine("Course " & CourseCorrection / PI * 180 & " D : " & d & " endpoint " & EndPoint.Lat_Deg & " " & EndPoint.Lon_Deg) |
| 368 | | |
| 369 | | ' Loop Until Abs(EndPoint.Lon - Lon) < EPSILON OrElse Double.IsNaN(d) 'Or Double.IsNaN(CourseCorrection) |
| 370 | | ' Return True |
| 371 | | ' End SyncLock |
| 372 | | ' End Function |
| 373 | | |
| 388 | | |
| 389 | | 'Public Sub FindNextWindChangePoint(ByVal Cap As Double, ByVal Speed As Double) |
| 390 | | |
| 391 | | ' Dim DistLat As Double |
| 392 | | ' Dim DistLon As Double |
| 393 | | ' Dim NegLon As Boolean = StartPoint.Lon_Deg < 0 |
| 394 | | ' Static C As New Coords |
| 395 | | ' Static CachedLatPoint As New Coords |
| 396 | | ' Dim CapRad As Double |
| 397 | | |
| 398 | | ' CapRad = Math.PI * Cap / 180 |
| 399 | | |
| 400 | | ' Dim P1 As PrevDateInfo |
| 401 | | ' P1 = PrevDateInfo.GetKey(StartPoint) |
| 402 | | ' C.Lat_Deg = P1.Lat |
| 403 | | ' C.Lon_Deg = P1.lon |
| 404 | | |
| 405 | | |
| 406 | | ' Dim GridStepOffset As Double = 0.001 |
| 407 | | ' Dim MeteoGridStep As Double = 1 / RouteurModel.METEO_GRID_STEP / 2 + GridStepOffset |
| 408 | | ' If Math.Cos(CapRad) >= 0 Then |
| 409 | | ' C.Lat_Deg += MeteoGridStep |
| 410 | | ' Else |
| 411 | | ' C.Lat_Deg -= MeteoGridStep |
| 412 | | ' End If |
| 413 | | |
| 414 | | ' If Math.Sin(CapRad) * -C.Lon_Deg >= 0 Then |
| 415 | | ' C.Lon_Deg += MeteoGridStep |
| 416 | | ' Else |
| 417 | | ' C.Lon_Deg -= MeteoGridStep |
| 418 | | ' End If |
| 419 | | |
| 420 | | ' If NegLon Then |
| 421 | | ' C.Lon_Deg = -C.Lon_Deg |
| 422 | | ' End If |
| 423 | | |
| 424 | | ' 'Point 1 same lat |
| 425 | | ' If ReachLat(C.Lat, CapRad) Then |
| 426 | | ' CachedLatPoint.Lat = EndPoint.Lat |
| 427 | | ' CachedLatPoint.Lon = EndPoint.Lon |
| 428 | | ' DistLat = SurfaceDistance |
| 429 | | ' Else |
| 430 | | ' DistLat = 10000000 |
| 431 | | ' End If |
| 432 | | |
| 433 | | ' 'Point 1 same lon |
| 434 | | ' If ReachLon(C.Lon, CapRad) Then |
| 435 | | ' DistLon = SurfaceDistance |
| 436 | | ' Else |
| 437 | | ' DistLon = 1000000 |
| 438 | | ' End If |
| 439 | | |
| 440 | | ' If DistLat < DistLon Then |
| 441 | | ' EndPoint.Lat = CachedLatPoint.Lat |
| 442 | | ' EndPoint.Lon = CachedLatPoint.Lon |
| 443 | | ' End If |
| 444 | | |
| 445 | | ' Return |
| 446 | | |
| 447 | | 'End Sub |