How To Make A Function For Atan. I Want To Get Result Manually For Sqllite
Solution 1:
Distance function for sqlite..... in SQL acos working can manage using this .. May Be helpfull
As part of an iPhone SDK project, I have an sqlite database with a table full of geographic locations, each stored as a latitude and longitude value in degrees. I wanted to be able to perform an SQL SELECT on this table and ORDER BY each row’s distance from an arbitrary point. I’ve achieved this by defining a custom sqlite function. This article contains the code for the function, together with instructions on using it.
Here’s the function, together with a convenience macro to convert from degrees to radians. This function is based on an online distance calculator I found which makes use of the spherical law of cosines.
#define DEG2RAD(degrees) (degrees * 0.01745327) // degrees * pi over 180staticvoiddistanceFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
// check that we have four arguments (lat1, lon1, lat2, lon2)assert(argc == 4);
// check that all four arguments are non-nullif (sqlite3_value_type(argv[0]) == SQLITE_NULL || sqlite3_value_type(argv[1]) == SQLITE_NULL || sqlite3_value_type(argv[2]) == SQLITE_NULL || sqlite3_value_type(argv[3]) == SQLITE_NULL) {
sqlite3_result_null(context);
return;
}
// get the four argument valuesdouble lat1 = sqlite3_value_double(argv[0]);
double lon1 = sqlite3_value_double(argv[1]);
double lat2 = sqlite3_value_double(argv[2]);
double lon2 = sqlite3_value_double(argv[3]);
// convert lat1 and lat2 into radians now, to avoid doing it twice belowdouble lat1rad = DEG2RAD(lat1);
double lat2rad = DEG2RAD(lat2);
// apply the spherical law of cosines to our latitudes and longitudes, and set the result appropriately// 6378.1 is the approximate radius of the earth in kilometressqlite3_result_double(context, acos(sin(lat1rad) * sin(lat2rad) + cos(lat1rad) * cos(lat2rad) * cos(DEG2RAD(lon2) - DEG2RAD(lon1))) * 6378.1);
}
This defines an SQL function distance(Latitude1, Longitude1, Latitude2, Longitude2), which returns the distance (in kilometres) between two points.
To use this function, add the code above to your Xcode project, and then add this line immediately after you call sqlite3_open:
sqlite3_create_function(sqliteDatabasePtr, "distance", 4, SQLITE_UTF8, NULL, &distanceFunc, NULL, NULL);
…where sqliteDatabasePtr is the database pointer returned by your call to sqlite3_open.
Assuming you have a table called Locations, with columns called Latitude and Longitude (both of type double) containing values in degrees, you can then use this function in your SQL like this:
SELECT * FROM Locations ORDERBY distance(Latitude, Longitude, 51.503357, -0.1199)
Solution 2:
Your question is a bit unclear but it seems that you know how to write your own custom SQLite functions meaning that your actual question is about how to write the various trigonometric functions.
You don't need to write them. Simply use the standard math functions.
#import <math.h>double newCos = cos(someRadianAngle);
See the man page for cos, sin, tan, atan, etc.
Solution 3:
Do 1 thing pass var1 & var2 to function & then use getValue in query. Xcode has in built atan,acos function you just need to pass value in radians.
float getValue=[self calculatetan:(float)var1 withSecondValue:(float)var2];
-(float)calculatetan:(float)var1 withSecondValue:(float)var2
{
newCos = 2 * atan( sqrt(1-pow(var,2))/(1+var) )// or split this return newCos;
}
Post a Comment for "How To Make A Function For Atan. I Want To Get Result Manually For Sqllite"