Reputation: 125
I am unable to understand this line of code this.position = convertlatlonToVec3(cardinal.lat, cardinal.lon).multiplyScalar(radius);
used in function labelBox. How does multiplyScalar(radius) works.
function convertlatlonToVec3(lat, lon)
{
var cosLat = Math.cos(circle.getCenter().lat() * degrees);
var sinLat = Math.sin(circle.getCenter().lat() * degrees);
var xSphere = radiusEquator * cosLat;
var ySphere = 0;
var zSphere = radiusPoles * sinLat;
var rSphere = Math.sqrt(xSphere*xSphere + ySphere*ySphere + zSphere*zSphere);
var tmp = rSphere * Math.cos(lat * degrees);
xSphere = tmp * Math.cos((lon - circle.getCenter().lng()) * degrees);
ySphere = tmp * Math.sin((lon - circle.getCenter().lng()) * degrees);
zSphere = rSphere * Math.sin(lat * degrees);
var x = -ySphere/circle.getRadius();
var y = (zSphere*cosLat - xSphere*sinLat)/circle.getRadius();
var z = 0;
return new THREE.Vector3(x, y, z);
}
function labelBox(cardinal, radius, root)
{
this.screenvector = new THREE.Vector3(0,0,0);
this.labelID = 'MovingLabel'+ cardinal.ID;
this.position = convertlatlonToVec3(cardinal.lat, cardinal.lon).multiplyScalar(radius);
}
Upvotes: 0
Views: 89
Reputation: 44356
Three.js documentation here
For THREE.Vector3
multiplyScalar
method look docs are here:
.multiplyScalar ( s ) this
Multiplies this vector by scalar s.
Contents of this method can be found in the THREE.Vector3
class and look like this:
multiplyScalar: function ( scalar ) {
if ( isFinite( scalar ) ) {
this.x *= scalar;
this.y *= scalar;
this.z *= scalar;
} else {
this.x = 0;
this.y = 0;
this.z = 0;
}
return this;
},
Upvotes: 1