# Forum: Ruby Math lib (even in C or C++... nobody is perfect !)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
on 2007-05-18 14:56
```I am looking for a function to calculate the barycentre of a point list
(GPS coordinates lat/lng) ..

anybody aware of such lib or utility I could rewrite in Ruby ? bet it
doesn't exist yet

thanks for any hint
joss```
on 2007-05-18 15:39
```Hi!

Whenever I need to use a math lib in C, I use the GNU Scientific Library
(GSL): http://www.gnu.org/software/gsl/
However, no idea if it contains what you need...

cheers, Severin

Josselin schrieb:```
on 2007-05-18 17:41
```On 2007-05-18 15:38:27 +0200, Severin Schoepke
<severin.schoepke@gmail.com> said:

> Josselin schrieb:
>> I am looking for a function to calculate the barycentre of a point list
>> (GPS coordinates lat/lng) ..
>>
>> anybody aware of such lib or utility I could rewrite in Ruby ? bet it
>> doesn't exist yet
>>
>> thanks for any hint
>> joss

got it from a PHP script..  translated into Ruby...

(d/180.0)*Math::PI
end
(r/Math::PI)*180
end

def self.gravity_center(placemarks)
sumx = 0.0
sumy = 0.0
sumz = 0.0

for  placemark in placemarks do
# convert spherical coordinate into cartesian
x = Math::cos(lat) * Math::sin(lon)
y = Math::cos(lat) * Math::cos(lon)
z = Math::sin(lat)
# sum the vectors
sumx += x
sumy += y
sumz += z
end

# convert cartesian coordinate back to spherical
meanz = sumz / placemarks.nitems