【问题标题】:how to get degrees of a specific X Position in an object?如何获取对象中特定 X 位置的度数?
【发布时间】:2015-01-28 09:33:32
【问题描述】:

这是我像卫星在行星上一样绕圆移动正方形的方法:

-(CGPoint)circularMovement:(float)degrees radius:(CGFloat)radius{        
        float x = (planet.position.x + planet.radius) *cos(degrees);
        float y = (planet.position.y + planet.radius) *sin(degrees);

        CGPoint posicion = CGPointMake(x, y);
        return posicion;
}

如您所见,我得到了我的卫星的 x 和 y 位置,并用度数++调用此方法,我得到了围绕行星的圆周运动。

但我对这个运动系统的问题是我需要satelite.position.x+satelite.size.width/2 的度数来检测与另一个使用相同运动系统移动的物体的碰撞。

有人知道如何获取这个值吗??

【问题讨论】:

    标签: ios objective-c sprite-kit angle orbital-mechanics


    【解决方案1】:

    只做同样的计算,但是倒过来。

    在您的示例中,您知道:planet.position、planet.radius、degrees,您必须找到 x em> 和 y 表示 CGPoint。

    现在您知道了:planet.position、planet.radius 和 CGPoint,您需要找到度数。

    根据您的公式:

    float x = (planet.position.x + planet.radius) *cos(degrees);
    

    你可以找到你的学位:

    cos(degrees) = x / (planet.position.x + planet.radius);
    

    例如:

    cos(x) = 1 / 2;
    

    然后

    x = acos(1/2);
    x = 60 degrees or Pi/3 rads
    

    【讨论】:

    • 我试过这个:cos(degrees) = x / (planet.position.x + planet.radius);但没有成功。而且我不明白示例的其余部分-> 例如: cos(x) = 1 / 2;然后 x = acos(1/2); x = 60 度或 Pi/3 弧度
    • @user3033437 这是基础数学,不是代码。您可以编写代码自己查找度数
    • 请注意,sin、cos、cos 等和 SpriteKit 使用弧度而不是度数,因此您必须转换:rad=deg/180*M_PI
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    相关资源
    最近更新 更多