【发布时间】:2017-02-03 15:21:00
【问题描述】:
我无法理解函数 labelBox 中使用的这行代码this.position = convertlatlonToVec3(cardinal.lat, cardinal.lon).multiplyScalar(radius);。 multiplyScalar(radius) 是如何工作的。
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);
}
【问题讨论】:
-
convertlatlonToVec3返回new THREE.Vector3(x, y, z)...这可能有一个名为multiplyScalar的方法 - 随后会执行 -
@Jaromanda X 我需要知道 multiplyScalar(radius) 是如何工作的。
-
那么现在您已经改变了问题 - 您查看过three.js 文档吗?
-
@Jaromanda X ya 我查看了 three.js 文档,但找不到有关 multiplyScalar(radius) 的信息。
-
我通过搜索
three.js Vector3 multiplyScalar找到了它 - google 中的第一个结果
标签: javascript math three.js