 
Junior Member
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 
Super Member
Re: Sin(X), Cos(X), acos(X) You can write the functions...or buy some functions/classes to use. 
Super Member
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. Chris R Mead
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. 
Senior Member
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 
Junior Member
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 
Senior Member
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="fontsize:xsmall; fontfamily: monospace;"> http://www.planetsourcecode.com/vb...6&lngWId=3
#include <math.h>
#define pi 3.14159265358979323846
double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta, dist;
theta = lon1  lon2;
dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));
dist = acos(dist);
dist = rad2deg(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 :*/
/*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::*/
double deg2rad(double deg) {
return (deg * pi / 180);
}
/*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::*/
/*:: this function converts radians to decimal degrees :*/
/*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::*/
double rad2deg(double rad) {
return (rad * 180 / pi);
}</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Good Luck 
Super Member
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. Chris R Mead
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. 
Super Member
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. Chris R Mead
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. 
Junior Member
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 
Super Member
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 Chris R Mead
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules 