I'm faced with a relatively simple task here, but as I am just beginning to delve into object-oriented programming, it is proving to be quite perplexing for me. Currently, I am using the lon_lat_to_cartesian function from the following source:
function lonLatToVector3( lng, lat, out )
{
out = out || new THREE.Vector3();
//flips the Y axis
lat = PI / 2 - lat;
//distribute to sphere
out.set(
Math.sin( lat ) * Math.sin( lng ),
Math.cos( lat ),
Math.sin( lat ) * Math.cos( lng )
);
return out;
}
Within my glmain.js file, I invoke it using the following line:
position = lonLatToVector3(data.latitude, data.longitude);
Essentially, the latitude and longitude points are transformed into a vector through this process.
Now, I am looking to replace this library with latlon-vectors.js. I am particularly interested in using the lines 50-60 from the code:
LatLon.prototype.toVector = function() {
var φ = this.lat.toRadians();
var λ = this.lon.toRadians();
// right-handed vector: x -> 0°E,0°N; y -> 90°E,0°N, z -> 90°N
var x = Math.cos(φ) * Math.cos(λ);
var y = Math.cos(φ) * Math.sin(λ);
var z = Math.sin(φ);
return new Vector3d(x, y, z);
};
As per my limited understanding, this seems to be a method of the main object:
function LatLon(lat, lon) {
// allow instantiation without 'new'
if (!(this instanceof LatLon)) return new LatLon(lat, lon);
this.lat = Number(lat);
this.lon = Number(lon);
}
While I could easily call this function by doing:
position = LatLon(data.latitude, data.longitude);
This wouldn't achieve my goal of converting the Lat, Lon points to a vector. How can I proceed to invoke the aforementioned lines(50-60)?