Nodejs Degree to Radian Convert toRad()

Here you can find the source of toRad()

Method Source Code

Number.prototype.toRad = function() { 
   return this * Math.PI / 180; 
};

Number.prototype.toDeg = function() { 
   return this * 180 / Math.PI; 
};


global.getPointAtDistance = function(lat, lon, brng, dist) {
  dist = dist / 6371000;/*from   w w w  .j  ava2s. c om*/
  brng = brng.toRad();
  var lat1 = lat.toRad(), lon1 = lon.toRad();
  var lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist) + 
                       Math.cos(lat1) * Math.sin(dist) * Math.cos(brng));
  var lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(dist) *
                               Math.cos(lat1), 
                               Math.cos(dist) - Math.sin(lat1) *
                               Math.sin(lat2));
  if (isNaN(lat2) || isNaN(lon2)) return null;
  return [lat2.toDeg(), lon2.toDeg()];
};

Related

  1. radians(degrees)
    Math.radians = function(degrees){
      return degrees * Math.PI / 180;
    };
    
  2. degToRad(degrees)
    Math.degToRad = function(degrees){
      return degrees * Math.PI / 180;
    };
    
  3. toRad()
    Number.prototype.toRad = function() {
      return this * Math.PI / 180;
    
  4. toRad()
    Number.prototype.toRad = function() {
      return this * Math.PI / 180;
    Number.prototype.toDeg = function() {
      return this * 180 / Math.PI;
    
  5. toRad()
    Number.prototype.toRad = function() {
      return this * Math.PI / 180;
    };
    Number.prototype.toDegree = function() {
      return this / Math.PI * 180;
    };
    
  6. toRad()
    Number.prototype.toRad = function() {
        return this * Math.PI / 180;
    };
    
  7. toRad()
    Number.prototype.toRad = function() {
      return (this / 180) * Math.PI;
    };
    
  8. toRad() // convert degrees to radians
    Number.prototype.toRad = function() {  
      return this * Math.PI / 180;
    
  9. toRadians()
    Number.prototype.toRadians = function() {
        return (this / 360) * 2 * Math.PI;