【问题标题】:Three.js: The rotation around the object?Three.js:围绕对象的旋转?
【发布时间】:2017-07-14 16:12:33
【问题描述】:

我尝试制作太阳系。我的行星在圆周运动:

this.obj.position.x = (this.positionX*20) * Math.cos( this.ange );
this.obj.position.z = (this.positionX*20) * Math.sin( this.ange );
this.ange = this.ange + this.rotationAhisSpeed;

月球如何绕地球旋转?我知道地球的位置,但是余弦和正弦如何计算?

【问题讨论】:

    标签: javascript animation math three.js geometry


    【解决方案1】:

    让一个对象环绕另一个对象非常简单。

    let earth = {
        x,
        y,
        z,
        orbitDistance,
        angle,
        angleSpeed
    }
    
    let moon = {
        x,
        y,
        z,
        orbitDistance,
        angle,
        angleSpeed
    }
    
    // Assume the object properties are filled out
    
    earth.x = earth.orbitDistance * Math.sin( earth.angle );
    earth.z = earth.orbitDistance * Math.cos( earth.angle );
    
    // Starting from the Eath's position will make it the origin of the Moon's orbit
    moon.x = earth.x + moon.orbitDistance * Math.sin( moon.angle );
    moon.z = earth.z + moon.orbitDistance * Math.cos( moon.angle );
    
    earth.angle += earth.angleSpeed;
    moon.angle += moon.angleSpeed;
    

    【讨论】:

    • 请看这里。第 108 行和第 144 行。我试图解释你的代码,但我的月亮落入了太阳。 (((stekolschikov.info/demo/SS
    • 我查看了您的代码,第 147-149 行。看起来您正在计算正确的位置,但可能没有正确更新月球网格的位置。
    • 可能没看懂,我在149,150,151行换了位置
    • 应该是this.obj.position.x = earthX + 100 * Math.cos( this.ange );
    猜你喜欢
    • 2015-01-06
    • 1970-01-01
    • 2013-08-30
    • 2021-09-13
    • 2016-02-29
    • 2015-06-15
    • 2023-03-13
    • 2014-12-28
    • 2017-02-10
    相关资源
    最近更新 更多