incorrect results with trig functions

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
twenty
Posts: 71
Joined: 20 Oct 2010 11:44

incorrect results with trig functions

#1 Post by twenty » 06 Dec 2012 12:42

Mikroe, please have a look at the program below. The result of a trig calculation appears to be incorrect. Any help would be appreciated.
Regards,

(Mikrobasic Pro for AVR, XMEGA 128a1)

program MyProject1

' Declarations section
const R= 6371000
dim lat1 as double
dim lat2 as double
dim lon1 as double
dim lon2 as double
dim distance as double

main:
lat1=-33*PI/180
lat2=-34*pi/180
lon1=151*pi/180
lon2=152*pi/180
'distance = acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2)*cos(lon2-lon1))*R
distance=sin(lat1) ' -5.446390E-001 should be 0.00100522 !!!!!!!!!!
nop

end.

twenty
Posts: 71
Joined: 20 Oct 2010 11:44

Re: incorrect results with trig functions

#2 Post by twenty » 07 Dec 2012 11:12

The ARM compiler for mikrobasic pro behaves the same way

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: incorrect results with trig functions

#3 Post by filip » 07 Dec 2012 14:14

Hi,

It behaves the same way, because the argument (-33*PI/180) is basically the -33 degrees, so you are actually calculating the sin(-33).

Regards,
Filip.

twenty
Posts: 71
Joined: 20 Oct 2010 11:44

Re: incorrect results with trig functions

#4 Post by twenty » 25 Dec 2012 09:34

You are correct. Thanks for your response

Post Reply

Return to “mikroBasic PRO for AVR General”