1. ## Sin(X), Cos(X), acos(X)

Hi,

if I have a float variable called fX, how can I do:

sin(fX)
cos(fX)
acos(fX)

There is nothing about those functions in the help, and I didn't found any information on this forum.

Thanks

Jake

2. ## Re: Sin(X), Cos(X), acos(X)

You can write the functions...or buy some functions/classes to use.

3. ## Re: Sin(X), Cos(X), acos(X)

VBScript has trig functions you can use. Javascript might also. It would be interesting to try to use a javascript and run the script using ExecScript. Would be cool if it worked. You could also write a C/C++ DLL and call into it from silktest.

4. ## Re: Sin(X), Cos(X), acos(X)

Depending on how dynamic you need it to be you could also just create a lookup table. If you are only going to calculating basic values (pi/3, pi/2 etc) that would be much easier and quicker than finding or writing a DLL of your own.

Brendan

5. ## Re: Sin(X), Cos(X), acos(X)

Here are some precisions on what I'm doing.

I have the latitude and longitude of two elements on the Earth, and I want the distance between them. The only way I found was by using sin(X), cos(X) and acos(x). Sadly, the elements can be anywhere on the planet, so I cannot use a lookup table.

Thanks

Jake

6. ## Re: Sin(X), Cos(X), acos(X)

Jake:

You are lucky today I found the following.
Just make a DLL project now and import this in Silk.

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">
http://www.planet-source-code.com/vb...6&amp;lngWId=3

#include &lt;math.h&gt;
#define pi 3.14159265358979323846

double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta, dist;
theta = lon1 - lon2;
dist = acos(dist);
dist = dist * 60 * 1.1515;

switch(unit) {
case 'M':
break;
case 'K':
dist = dist * 1.609344;
break;
case 'N':
dist = dist * 0.8684;
break;
}
return (dist);
}
/*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::*/
/*:: this function converts decimal degrees to radians :*/
/*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::*/

return (deg * pi / 180);
}
/*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::*/
/*:: this function converts radians to decimal degrees :*/
/*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::*/

return (rad * 180 / pi);
}</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Good Luck

7. ## Re: Sin(X), Cos(X), acos(X)

Be careful what you use those estimates for. The code GodKnows posted is an approximation based on a model of the earth as a sphere. Since the earth is really an ellipsoid you will run into rather significant errors if you use this code to compare against real data. The error will be worse in certain regions on the earth.

If you need accurate data, you may want to find a program which correctly implements great circle computations and then automate it. Check out FliteStar/FliteMap. Writing this code yourself is definitely more time consuming than finding someone else's data. You could also just make a lookup table of values to use for testing with a handheld GPS.

8. ## Re: Sin(X), Cos(X), acos(X)

I would try this if I were you:

http://williams.best.vwh.net/gccalc.htm

You can see all the source with 'View Source'. You could even move this code to a local server if you don't want to use this internet site.

Test it against some Jeppesen maps or something first, of course.

9. ## Re: Sin(X), Cos(X), acos(X)

Thanks to all for your help.

Finally, here is what I have decided to do.

I have calculated manually the distance for 1 degree of latitude and 1 degree of longitude. Since the elements that I'm testing are always in the same region of the Earth, I always take those two distances. For that specific region, I have verified and my calculated distances have a maximum error of .8 meter, which is precise enough for what I do.

Thanks

Jake

10. ## Re: Sin(X), Cos(X), acos(X)

Sounds good. Sounds like you've made you own grid system (projection):

http://www.uwgb.edu/dutchs/FieldMethods/UTMSystem.htm

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.