Acos equation not matching calculator

My first topic. :slight_smile:
I'm working on a project for locating geostationary satellites and have already ran into an issue that I have been working on for a while now. posting on the forum was a last resort but I'm not sure what to do. i'm not a math wiz or anything and I don't fully understand all of the inner workings of what I'm doing.

The gamma calculation doesn't match or even get close to what I've been doing in online calculators. I know the answer of the equation should be close to 38.4 degrees but I am getting 1.44. I will have the screenshots of the equation I'm trying to copy at the bottom. I also ran the same equation ran through an online calculator and it turned out fine (close at least but I rounded variables).

//include libraries
#include <math.h>

//define constants
#define re 6378 //radius of earth
#define rs 42164 //radius of sat orbit

//define variables
float myLat  = 33.78;
float myLon = -84.40;

//define satellite target(s)
float satLat = 0.0; //will always equal 0 bc its a geosat
float satLon = -105.0;

void setup(){
  Serial.begin(9600);
  Serial.print("earth radius: ");
  Serial.print(re);
  Serial.println();
  Serial.print("orbit radius: ");
  Serial.print(rs);
  Serial.println();
  Serial.print("antenna location: ");
  Serial.print(myLat);
  Serial.print(", ");
  Serial.print(myLon);
  Serial.println();
  Serial.print("target sat is ");
  Serial.print(satLon);
  Serial.println();
  Serial.println();
}

void calculate(){
  //calculate gamma
  double gamma = acos(sin(satLat) * sin(myLat) + cos(satLat) * cos(myLat) * cos(satLon - myLon));
  Serial.print("gamma: ");
  Serial.print(gamma);
  Serial.println();
  
  //calculate el
  //double elevation = acos(sin(gamma) / sqrt(1 + sq(re / rs) - 2 * (re / rs) * cos(gamma)));
  //Serial.println(elevation);
  
  //calculate az 
  //double azimuth = asin(sin(abs(myLon - satLon)) * cos(0 / sin(gamma)));
  //Serial.println(azimuth);
}

void loop(){
  calculate();
  delay(10000);
}

Serial Monitor output:

earth radius: 6378
orbit radius: 42164
antenna location: 33.78, -84.40
target sat is -105.00

gamma: 1.44

Pics:
another sc of gamma formula (big L is latitude and little l is longitude):

calculation of gamma in an example:

gamma equation in a calculator:

All trig functions are in Radians.

then why does it work in the calculator but not in arduino? and would what would i need to convert to get it to come out correctly? i have tried converting the final result to radians and it comes out to be 82.50592 degrees which is no where near the correct answer.

then why does it work in the calculator but not in arduino?

Most calculators default to degrees for input to trig functions.

To convert degrees to radians for Arduino, multiply degrees by (PI/180.0). PI is a built in constant.

When comparing to calculators, on AVR based Arduinos like the Uno you are in addition limited to 6 to 7 total decimal digits of accuracy. That can introduce significant errors, especially for calculations like spherical trigonometry, or for astronomical calculations based on Julian days, etc.

Then your equation or implementation of it is wrong.

You have to convert each of the angles used in the trig functions to radians, then when you have the final answer convert it from radians back to degrees.
< edit > I see you already though of that while I was typing

i just finished converting before and after the equation and it worked :grin: thanks so much!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.