Обсуждение: Trigonometry

Поиск
Список
Период
Сортировка

Trigonometry

От
lynch@cognitivearts.com (Richard Lynch)
Дата:
I'm using:

PostgreSQL 6.3.2 on i686-pc-linux-gnu, compiled by gcc 2.7.2.3
('cuz that's what my ISP gots)

and there don't seem to be any trigonomeric functions, so I'm really up a
creek for trying to calculate latitude/longitude distances using:

create function radians(float4)  returns float4 as
'select 3.1415927 * $1 / 180'
language 'sql';

create function gpsdistance(float4, float4, float4, float4) returns float4 as
'select (3590 * (2 * atan2( sqrt(pow((sin(radians(($1 - $3))/2)),2) +
cos($4) * cos($2) * pow((sin(radians(($2 - $4))/2)),2)),
sqrt(1-(pow((sin(radians(($1 - $3))/2)),2) + cos($4) * cos($2) *
pow((sin(radians(($2 - $4))/2)),2))))))'
language 'sql';

The online docs don't seem to have anything about trig nor longitude
latitude, but I could have sworn somebody said that kind of stuff was in
PostgreSQL...

Any ideas, keeping in mind that installing a new PostgreSQL or adding stuff
to it that requires being root or even postgres super-user are not an
option?...

I *can* compile c code, so if somebody could 'splain to a Lisp hacker how
to make a gpsdistance.so that would maybe work?

-- "TANSTAAFL" Rich lynch@cognitivearts.com   webmaster@  and www. all of:
R&B/jazz/blues/rock - jademaze.com      music industry org - chatmusic.com
acoustic/funk/world-beat - astrakelly.com   sculptures - olivierledoux.com
my own nascent company - l-i-e.com   cool coffeehouse - uncommonground.com



Re: [GENERAL] Trigonometry

От
Statistical Solutions
Дата:
On Fri, 23 Apr 1999, Richard Lynch wrote:

> I *can* compile c code, so if somebody could 'splain to a Lisp hacker how
> to make a gpsdistance.so that would maybe work?

Richard,
if you are using gcc use the -G or the -shared option.  (I believe -shared
is the preferred usage now but -G works also).

gcc -shared -fPIC -o myGPSfuncs.so myGPSfuncs.c -lm

(last is just to link in the math libraries).

Sometimes, its wise to add the -R flag, along with the appropriate paths
for where shared libraries reside, as in
gcc- shared -fPIC -R/usr/local/lib:/usr/lib:/home/me/mylibs -o
myGPSfuncs.so myGPSfuncs.c -lm

so that where when an app needs this library, it knows where to look for
others also.

steve