Difference between pages "Animal poems - Moose" and "JavaScript - Geometry"

From NoskeWiki
(Difference between pages)
Jump to navigation Jump to search
(Created page with "{{DaughterPage|mother=Animal poems}} == Moose == {{PoemSubtitle_start}}... strong, proud, sentimental{{PoemSubtitle_end}} From the cold mountain spires<br> of Alaskan...")
 
(Created page with "==About== {{DaughterPage|mother=JavaScript}} Here's some code for calculating latitude and longitude information in JavaScript. Al the code below has been taken from this...")
 
Line 1: Line 1:
{{DaughterPage|mother=[[Animal poems]]}}
+
==About==
 +
{{DaughterPage|mother=[[JavaScript]]}}
  
 +
Here's some code for calculating latitude and longitude information in JavaScript. Al the code below has been taken from this [http://www.movable-type.co.uk/scripts/latlong.html fabulous page by Movable Type Scripts], then turned into functions and use the [https://developers.google.com/maps/documentation/javascript/reference Google Maps Javascript API V3 Reference].
  
== Moose ==
 
{{PoemSubtitle_start}}... strong, proud, sentimental{{PoemSubtitle_end}}
 
  
 +
==Halfway between two points (longitude/latitude)==
  
From the cold mountain spires<br>
+
<syntaxhighlight lang="javascript">
of Alaskan wilderness forests,<br>
+
/**
in natures cathedral<br>
+
* Returns the exact longitude and latitudes halfway between two
where the scale is enormous,<br>
+
* latitude/longitude pairs on the globe. Note that this "closest"
and fish swim<br>
+
* point, to two other points may sometimes cross over the north or
in waters pure.<br>
+
* south pole.
 +
* @param {!number} latitude1 The latitude of the first point (in degress).
 +
* @param {!number} longitude1 The longitude of the first point.
 +
* @param {!number} latitude2 The latitude of the second point.
 +
* @param {!number} longitude2 The latitude of the second point.
 +
* @return {Object}  // google.maps.LatLng.
 +
*/
 +
var midPoint = function(latitude1, longitude1, latitude2, longitude2) {
 +
  var DEG_TO_RAD = Math.PI / 180;    // To convert degrees to radians.
  
 +
  // Convert latitude and longitudes to radians:
 +
  var lat1 = latitude1 * DEG_TO_RAD;
 +
  var lat2 = latitude2 * DEG_TO_RAD;
 +
  var lng1 = longitude1 * DEG_TO_RAD;
 +
  var dLng = (longitude2 - longitude1) * DEG_TO_RAD;  // Diff in longtitude.
  
 +
  // Calculate mid-point:
 +
  var bx = Math.cos(lat2) * Math.cos(dLng);
 +
  var by = Math.cos(lat2) * Math.sin(dLng);
 +
  var lat = Math.atan2(
 +
      Math.sin(lat1) + Math.sin(lat2),
 +
      Math.sqrt((Math.cos(lat1) + bx) * (Math.cos(lat1) + bx) + by * by));
 +
  var lng = lng1 + Math.atan2(by, Math.cos(lat1) + bx);
  
Down through lands<br>
+
  return new google.maps.LatLng(lat / DEG_TO_RAD, lng / DEG_TO_RAD);
know as big sky country,<br>
+
};
in regions<br>
+
</syntaxhighlight>
gently sunny,<br>
 
where clouds gravitate<br>
 
to the heavens.<br>
 
  
  
 +
==Distance between two points (longitude/latitude)==
  
Loom towering antlers<br>
+
<syntaxhighlight lang="javascript">
as high as a church,<br>
+
/**
Wading through marshes<br>
+
* Returns the distance in kilometers between two coordinates.
Or a high mountain perch,<br>
+
* @see: http://www.movable-type.co.uk/scripts/latlong.html
Overlooking the wilds<br>
+
* @param {!number} lat1 The latitude of the first point (in degrees).
A proud majestic moose.<br>
+
* @param {!number} lng1 The longitude of the first point.
 +
* @param {!number} lat2 The latitude of the second point.
 +
* @param {!number} lng2 The longitude of the second point.
 +
* @return {number} The distance in kilometers between the points.
 +
*/
 +
var distanceBetweenPoints = function(lat1, lng1, lat2, lng2) {
 +
  var RADIUS_EARTH = 6371;            // Radius of the earth in kilometers.
 +
  var DEG_TO_RAD = Math.PI / 180;    // To convert degrees to radians.
  
 +
  var dLat = (lat2 - lat1) * DEG_TO_RAD;
 +
  var dLng = (lng2 - lng1) * DEG_TO_RAD;
 +
  lat1 = lat1 * DEG_TO_RAD;
 +
  lat2 = lat2 * DEG_TO_RAD;
  
 +
  var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
 +
          Math.sin(dLng / 2) * Math.sin(dLng / 2) *
 +
          Math.cos(lat1) * Math.cos(lat2);
 +
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  
Larger than life<br>
+
  return RADIUS_EARTH * c;
Curious creatures,<br>
+
};
Largest of all deers<br>
+
</syntaxhighlight>
Striking sharp features,<br>
 
The mighty antlers<br>
 
A symbol of strength.<br>
 
  
  
 +
{{CodeLicence}}
  
A mighty rack<br>
 
of bone and vessels of blood,<br>
 
shed annually<br>
 
for another furry pair to bud,<br>
 
as if a gentleman<br>
 
with a sword wrapped in velvet.<br>
 
  
 +
==Links==
  
 +
* [http://www.movable-type.co.uk/scripts/latlong.html Movable Type Scripts - Calculate distance, bearing and more between Latitude/Longitude points] - where this code came from.
  
The more gentle female<br>
+
[[Category:Computers]]
rarely in large gathering,<br>
+
[[Category:Programming]]
with a bond between mother and calf<br>
 
independent and meandering.<br>
 
 
 
 
 
 
 
The moose to me<br>
 
represents more than strength,<br>
 
it's a creature with deep tradition,<br>
 
sentiment and self reflection<br>
 
a history of survival and resilience,<br>
 
standing proudly<br>
 
between tapestries of fresh water<br>
 
and expansive sky.<br>
 
 
 
 
 
 
 
 
 
 
 
{{PoemSignature}}
 
 
 
 
 
{{AnimalPoem
 
|datepoem=May 2018
 
|animal=[https://en.wikipedia.org/wiki/Moose Moose]
 
|description=Dedicated to Chris.
 
}}
 
 
 
 
 
[[Category:Personal]]
 
[[Category:Poems]]
 

Latest revision as of 14:13, 6 February 2019

About

NOTE: This page is a daughter page of: JavaScript


Here's some code for calculating latitude and longitude information in JavaScript. Al the code below has been taken from this fabulous page by Movable Type Scripts, then turned into functions and use the Google Maps Javascript API V3 Reference.


Halfway between two points (longitude/latitude)

/**
 * Returns the exact longitude and latitudes halfway between two
 * latitude/longitude pairs on the globe. Note that this "closest"
 * point, to two other points may sometimes cross over the north or
 * south pole.
 * @param {!number} latitude1 The latitude of the first point (in degress).
 * @param {!number} longitude1 The longitude of the first point.
 * @param {!number} latitude2 The latitude of the second point.
 * @param {!number} longitude2 The latitude of the second point.
 * @return {Object}  // google.maps.LatLng.
 */
var midPoint = function(latitude1, longitude1, latitude2, longitude2) {
  var DEG_TO_RAD = Math.PI / 180;     // To convert degrees to radians.

  // Convert latitude and longitudes to radians:
  var lat1 = latitude1 * DEG_TO_RAD;
  var lat2 = latitude2 * DEG_TO_RAD;
  var lng1 = longitude1 * DEG_TO_RAD;
  var dLng = (longitude2 - longitude1) * DEG_TO_RAD;  // Diff in longtitude.

  // Calculate mid-point:
  var bx = Math.cos(lat2) * Math.cos(dLng);
  var by = Math.cos(lat2) * Math.sin(dLng);
  var lat = Math.atan2(
      Math.sin(lat1) + Math.sin(lat2),
      Math.sqrt((Math.cos(lat1) + bx) * (Math.cos(lat1) + bx) + by * by));
  var lng = lng1 + Math.atan2(by, Math.cos(lat1) + bx);

  return new google.maps.LatLng(lat / DEG_TO_RAD, lng / DEG_TO_RAD);
};


Distance between two points (longitude/latitude)

/**
 * Returns the distance in kilometers between two coordinates.
 * @see: http://www.movable-type.co.uk/scripts/latlong.html
 * @param {!number} lat1 The latitude of the first point (in degrees).
 * @param {!number} lng1 The longitude of the first point.
 * @param {!number} lat2 The latitude of the second point.
 * @param {!number} lng2 The longitude of the second point.
 * @return {number} The distance in kilometers between the points.
 */
var distanceBetweenPoints = function(lat1, lng1, lat2, lng2) {
  var RADIUS_EARTH = 6371;            // Radius of the earth in kilometers.
  var DEG_TO_RAD = Math.PI / 180;     // To convert degrees to radians.

  var dLat = (lat2 - lat1) * DEG_TO_RAD;
  var dLng = (lng2 - lng1) * DEG_TO_RAD;
  lat1 = lat1 * DEG_TO_RAD;
  lat2 = lat2 * DEG_TO_RAD;

  var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
          Math.sin(dLng / 2) * Math.sin(dLng / 2) *
          Math.cos(lat1) * Math.cos(lat2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

  return RADIUS_EARTH * c;
};


Code license
For all of the code on my site... if there are specific instruction or licence comments please leave them in. If you copy my code with minimum modifications to another webpage, or into any code other people will see I would love an acknowledgment to my site.... otherwise, the license for this code is more-or-less WTFPL (do what you want)! If only copying <20 lines, then don't bother. That said - if you'd like to add a web-link to my site www.andrewnoske.com or (better yet) the specific page with code, that's a really sweet gestures! Links to the page may be useful to yourself or your users and helps increase traffic to my site. Hope my code is useful! :)



Links