Azimuth calculator error

This is a discussion on Azimuth calculator error within the C++ Programming forums, part of the General Programming Boards category; Hi all, I am making a C++ azimuth calculator using the formula at the top of this page: Launch Azimuth ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    Azimuth calculator error

    Hi all,

    I am making a C++ azimuth calculator using the formula at the top of this page:

    Launch Azimuth - OrbiterWiki

    I am using the formula to calculate 'example 1' on the page, with the Cape Canaveral - ISS launch. Instead of the 45 degree answer, I get -144 degrees. Here is the code:

    Code:
    #include <iostream>
    #include <math.h>
    #include <process.h>
    #include <conio.h>
    
    using namespace std;
    
    int main ()
    {
    
      double lat;
      double az;
      double inc;
      char ch;
    
    start:
      cout << "To calculate azimuth (degrees), enter target inclination and press enter: " << "\n";
      cin >> inc;
      cout << "To calculate azimuth (degrees), enter departure latitude and press enter: " << "\n";
      cin >> lat;
      if (lat > inc) goto error;
      az = asin(cos (inc)/cos (lat));
      cout << "\n" << "Azimuth is: " << az * 100 << " degrees";
      goto end;
    
    end:
      cout << "\n" << "\n" << "Press enter to recalculate.";
      ch = _getch();
      if (ch == 13)
      system("cls");
      goto start;
    
    error:
      cout << "\n" << "Can't calculate if inclination is lower than latitude.";
      goto end;
    
      return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    128
    Not to worry - it's the degrees/radians problem. Solved.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21