# sin and similar functions Classic List Threaded 12 messages Open this post in threaded view
|

## sin and similar functions

 Hi Friends Is there a possibility to have sin cos an acos, functions in sqlite? How to write it in? I really need it and i have fear, that sinus values table will be so slow and so big for critical precission. I will need to select coordinates which are laying in circle of known center and radius. Unfortunately at small time intervals and on a slow machine. Thanks Jakub ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] -----------------------------------------------------------------------------
Open this post in threaded view
|

## Re: sin and similar functions

 I am sorry, it seems to be unreadable bacause of my very bad english. I try to correct it little bit. Hi Friends :-) Is there a possibility to have sin, cos anD acos, functions in sqlite? How to write it in? I have read (Mike Owens article at LinuxJournal), that it is possible to write new function to expand standard set of functions as avg(), min(), sum() etc. I will have table with sequence of coordinates (two dimensional space) and corresponding radiuses, so sequence of circles. And i need to use a sqlite query to detect if a actual coordinates (after their measurement) match some of the circle's square or not. And which circle, if match. And this must be for low CPU consumption optimised, so i am not sure, if separate sin table queries will be enough as fast as i need at needed precission. The whole algorithm is proven on mssql by my colegue, but he is using the native math functions. Thanks Jakub ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] -----------------------------------------------------------------------------
Open this post in threaded view
|

## Re: sin and similar functions

 In reply to this post by Bugzilla from ladmanj@volny.cz Just add a sine function in the normal manner of adding a function.  It is very simple. Jakub Ladman wrote: > Hi Friends > > Is there a possibility to have sin cos an acos, functions in sqlite? > How to write it in? > I really need it and i have fear, that sinus values table will be so slow and > so big for critical precission. > > I will need to select coordinates which are laying in circle of known center > and radius. > Unfortunately at small time intervals and on a slow machine. > > Thanks > > Jakub > > ----------------------------------------------------------------------------- > To unsubscribe, send email to [hidden email] > ----------------------------------------------------------------------------- > ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] -----------------------------------------------------------------------------
Open this post in threaded view
|

## Re: sin and similar functions

 In reply to this post by Bugzilla from ladmanj@volny.cz Jakub Ladman wrote: > I will have table with sequence of coordinates (two dimensional space) and > corresponding radiuses, so sequence of circles. And i need to use a sqlite > query to detect if a actual coordinates (after their measurement) match some > of the circle's square or not. And which circle, if match. > And this must be for low CPU consumption optimised, so i am not sure, if > separate sin table queries will be enough as fast as i need at needed > precission. > > The whole algorithm is proven on mssql by my colegue, but he is using the > native math functions. > >   Jakub, I may not understand your problem completely, but it seems to me you can solve your problem without using any trigonometric functions. If you have a table of circles like this     create table circle (         id  integer primary key,         cx  real,         cy  real,         r   real     ); You can find all the circles that contain a given point (px,py) using a simple query based in the distance between the point and the center of the circle.     select id from circle     where (px-cx)*(px-cx)+(py-cy)*(py-cy) < r*r; If you want to create a user defined distance function you could possibly speed up the calculation somewhat. You could then use a query like:     select id from circle     where distance(cx, cy, px, py) < r; where     distance(cx, cy, px, py) = sqrt((px-cx)^2 + (py-cy)^2) HTH Dennis Cote         ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] -----------------------------------------------------------------------------
Open this post in threaded view
|

## Re: sin and similar functions

Open this post in threaded view
|

## Re: sin and similar functions

 In reply to this post by Dennis Cote Thank you very much. Not only my english is poor, but my coordinated geometry too :-( But my software will make much more geometrical computations, so probably some in queries too. Please let You (or someone) direct me to the relevant part of documentation for defining new functions. Thank You Jakub Dne pátek 09 březen 2007 23:35 Dennis Cote napsal(a): > Jakub Ladman wrote: > > I will have table with sequence of coordinates (two dimensional space) > > and corresponding radiuses, so sequence of circles. And i need to use a > > sqlite query to detect if a actual coordinates (after their measurement) > > match some of the circle's square or not. And which circle, if match. > > And this must be for low CPU consumption optimised, so i am not sure, if > > separate sin table queries will be enough as fast as i need at needed > > precission. > > > > The whole algorithm is proven on mssql by my colegue, but he is using the > > native math functions. > > Jakub, > > I may not understand your problem completely, but it seems to me you can > solve your problem without using any trigonometric functions. > > If you have a table of circles like this > >     create table circle ( >         id  integer primary key, >         cx  real, >         cy  real, >         r   real >     ); > > You can find all the circles that contain a given point (px,py) using a > simple query based in the distance between the point and the center of > the circle. > >     select id from circle >     where (px-cx)*(px-cx)+(py-cy)*(py-cy) < r*r; > > If you want to create a user defined distance function you could > possibly speed up the calculation somewhat. You could then use a query > like: > >     select id from circle >     where distance(cx, cy, px, py) < r; > > where > >     distance(cx, cy, px, py) = sqrt((px-cx)^2 + (py-cy)^2) > > HTH > Dennis Cote > > > --------------------------------------------------------------------------- >-- To unsubscribe, send email to [hidden email] > --------------------------------------------------------------------------- >-- ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] -----------------------------------------------------------------------------
Open this post in threaded view
|

## Re: sin and similar functions

Open this post in threaded view
|

## Re: sin and similar functions

Open this post in threaded view
|

## Re: sin and similar functions

 In reply to this post by Bugzilla from ladmanj@volny.cz A poster here, "Mikey C", wrote some math functions and posted them a month or so ago.  You might have a look at http://www.mail-archive.com/sqlite-users@.../msg21791.html -Clark ----- Original Message ---- From: Jakub Ladman <[hidden email]> To: [hidden email] Sent: Friday, March 9, 2007 3:00:22 PM Subject: Re: [sqlite] sin and similar functions Thank you very much. Not only my english is poor, but my coordinated geometry too :-( But my software will make much more geometrical computations, so probably some in queries too. Please let You (or someone) direct me to the relevant part of documentation for defining new functions. Thank You Jakub Dne pátek 09 březen 2007 23:35 Dennis Cote napsal(a): > Jakub Ladman wrote: > > I will have table with sequence of coordinates (two dimensional space) > > and corresponding radiuses, so sequence of circles. And i need to use a > > sqlite query to detect if a actual coordinates (after their measurement) > > match some of the circle's square or not. And which circle, if match. > > And this must be for low CPU consumption optimised, so i am not sure, if > > separate sin table queries will be enough as fast as i need at needed > > precission. > > > > The whole algorithm is proven on mssql by my colegue, but he is using the > > native math functions. > > Jakub, > > I may not understand your problem completely, but it seems to me you can > solve your problem without using any trigonometric functions. > > If you have a table of circles like this > >     create table circle ( >         id  integer primary key, >         cx  real, >         cy  real, >         r   real >     ); > > You can find all the circles that contain a given point (px,py) using a > simple query based in the distance between the point and the center of > the circle. > >     select id from circle >     where (px-cx)*(px-cx)+(py-cy)*(py-cy) < r*r; > > If you want to create a user defined distance function you could > possibly speed up the calculation somewhat. You could then use a query > like: > >     select id from circle >     where distance(cx, cy, px, py) < r; > > where > >     distance(cx, cy, px, py) = sqrt((px-cx)^2 + (py-cy)^2) > > HTH > Dennis Cote > > > --------------------------------------------------------------------------- >-- To unsubscribe, send email to [hidden email] > --------------------------------------------------------------------------- >-- ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] -----------------------------------------------------------------------------
Open this post in threaded view
|

## Re: sin and similar functions

 In reply to this post by Bugzilla from ladmanj@volny.cz Jakub Ladman wrote: > Thank you very much. > Not only my english is poor, but my coordinated geometry too :-( > But my software will make much more geometrical computations, so probably some > in queries too. > Please let You (or someone) direct me to the relevant part of documentation > for defining new functions. > >   Jakub, SQLite itself use the public C API to add the standard functions when it initializes, so there are some very good examples of writing custom functions in the sqlite source file func.c (see http://www.sqlite.org/cvstrac/fileview?f=sqlite/src/func.c&v=1.136 ). You will need to write C functions that do similar things as the samples in func.c and add them to your instance of sqlite using the API at http://www.sqlite.org/capi3ref.html#sqlite3_create_function. Then you can call your custom functions from your SQL statements. I have also posted some samples of user defined functions on this list. You may want to search for them if you don't finfd the sqlite source clear enough. HTH Dennis Cote ----------------------------------------------------------------------------- To unsubscribe, send email to [hidden email] -----------------------------------------------------------------------------