help converting C code to Basic for use with BS2

Hi all,
I am having trouble getting around the integer math limitations of the BS2, but I know there are ways to do so. I was hoping someone (with a
lot more BS2 experience than me) can take a look at the C code below and suggest modifications that would yield the same result in Basic (or something close as I know there will be rounding errors). The values I get when compiling the code below are: distance!44 and anglef. I really appreciate everyone's time!!!
Thanks in advance!
// declare variables float degrees_LAT1, minutes_LAT1, seconds_LAT1, degrees_LONG1, minutes_LONG1, seconds_LONG1; float degrees_LAT2, minutes_LAT2, seconds_LAT2, degrees_LONG2, minutes_LONG2, seconds_LONG2; float LAT_1, LAT_2, LONG_1, LONG_2; float D=0, courseAngle=0;
// initialize variables degrees_LAT1 = 33.0; minutes_LAT1 = 57.0; seconds_LAT1 = 30.0; degrees_LONG1 = 118.0; minutes_LONG1 = 24.0; seconds_LONG1 = 50.0; degrees_LAT2 = 40.0; minutes_LAT2 = 38.0; seconds_LAT2 = 55.0; degrees_LONG2 = 73.0; minutes_LONG2 = 47.0; seconds_LONG2 = 35.0;
// code that needs to be converted to basic for use with BS2... LAT_1 = (degrees_LAT1 + minutes_LAT1/60 + seconds_LAT1/3600) * (Pi/180); LONG_1 = (degrees_LONG1 + minutes_LONG1/60 + seconds_LONG1/3600) * (Pi/180); LAT_2 = (degrees_LAT2 + minutes_LAT2/60 + seconds_LAT2/3600) * (Pi/180); LONG_2 = (degrees_LONG2 + minutes_LONG2/60 + seconds_LONG2/3600) * (Pi/180);
D = acos(sin(LAT_1)*sin(LAT_2) + cos(LAT_1)*cos(LAT_2)*cos(LONG_1-LONG_2)); courseAngle = acos((sin(LAT_2)-sin(LAT_1)*cos(D))/(sin(D)*cos(LAT_1))); D = D*60*180/Pi; printf("distance = %f\n", D); printf("angle = %f\n\n", courseAngle*180/Pi);
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
If you don't get a response here, keep in mind that Parallax sponsors a very active user-to-user forum on their site. Someone may have already written a routine for handling simple floating point math.
-- Gordon
snipped-for-privacy@drexel.edu wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Yeah, I tried there first and am still waiting a reply :-(
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Ooh, fun.
I don't have acces to my code any more, but the last time I tried to solve this type of problem in BS2 I used fixed point , not floating point. And I used lookup tables for the trig functions.
I did a quick check: for the data values in your exanmple, I got the identical results by rounding the seconds. This might allow you to use word sized variables. Even though the degrees can range from 0..360, the _difference_ between the two vectors will never be more than 180 degrees, so this should fit OK in a word that can handle 32768 or 65536.
Fixed point means that you use integer values but you choose a location as the decimal point and it's fixed at that point. Your distance can be an integer and results of the forward trig functions are always between -1.0 and 1.0. The inverse trig functions can vary, but it is doable.
Not trivial, but doable.
Sorry, again, I don't have any access to any pre-written routines, but you can do it if you're motivated.
Jim

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.