View unanswered posts | View active topics It is currently Wed Sep 23, 2020 3:58 pm

Reply to topic  [ 1 post ] 
HELP ... NXT not computing properly ACOS math function 
Author Message

Joined: Fri Aug 14, 2009 11:36 pm
Posts: 15
Post HELP ... NXT not computing properly ACOS math function

I'm posting my question previously from NXT IDE forum to this section as it may be more appropriate here. Also as a background, the 2 latitudes and longitudes inputs will be provided by an external bluetooth GPS. I am just making sure that this computational section of the proposed bigger program works and here I am hitting a wall :( .

Any help will be much appreciated.




I'm trying to compute the distance between two lat long locations using Great Circle distance formula. All aspects of the formula works as expected except when acos value is computed! The results of running the program on the nxt running 1.4 firmware can be found in the 2nd image. The values that are not being computed properly starts on line 4 down to line 8. It should be a straight forward computations but for some reason, it is not coming out right. The first image shows the "right" values computed in excel.

Hope somebody out there can help.


The program is as follows:
  task main()
float LatA = 38.95425556;
float LatB = 38.96098333;
float LonA = -92.37601944;
float LonB = -92.36897778;
float RadLatA = (LatA/180)*PI;
float RadLatB = (LatB/180)*PI;

float SinLatA = sin(RadLatA);
float SinLatB   = sin(RadLatB);
float CosLatA   = cos(RadLatA);
float CosLatB   = cos(RadLatB);
float CosLonB_LonA = cos((LonB/180)*PI-(LonA/180)*PI);
float Distrad   = acos(SinLatA*SinLatB+CosLatA*CosLatB*CosLonB_LonA);
float Distdeg   = (Distrad/PI)*180;
float Distance_m = 1.852*60*Distdeg*1000;

nxtDisplayTextLine(0,"sina: %3.8f", SinLatA); //display target GPS heading
nxtDisplayTextLine(1,"sinb: %3.8f", SinLatB); //display target GPS heading
nxtDisplayTextLine(2,"cosa: %3.8f", CosLatA); //display target GPS heading
nxtDisplayTextLine(3,"cosb: %3.8f", CosLatB); //display target GPS heading
nxtDisplayTextLine(4,"coslbla: %3.8f", CosLonB_LonA); //display target GPS heading
nxtDisplayTextLine(5,"Drad: %3.8", Distrad); //display target GPS heading
nxtDisplayTextLine(6,"Ddeg: %3.8f", Distdeg); //display target GPS heading
nxtDisplayTextLine(7,"D_m: %3.8f", Distance_m); //display target GPS heading


File comment: Excel result
nxtout_compare.jpg [ 35.38 KiB | Viewed 3341 times ]
File comment: NXT display
nxtout.jpg [ 41.63 KiB | Viewed 3340 times ]
Sat Aug 15, 2009 9:19 am
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.