围绕中心点旋转一个点,出了点问题

时间:2014-01-13 20:21:40

标签: rotation point

在当前的赋值中,我们需要创建一个方法,围绕给定点旋转 以给定角度给出的中心点,以CLOCK WISED偏移量给出。 在这里搜索帖子后,我以为我想出来了,但根据我的说法 老师,这有点不对劲,我无法理解。

我希望也许有人可以帮助指出问题所在。

这是我的方法

    /**
 * rotate this Point around a given enter point, with the given angle, in clock wised offset.
 * @param center - the center Point for rotation
 * @param angle - the size angle in degrees - to be rotate clock wised
 */
public void rotate(Point center, double angle){

    // convert the angle to radiant (to use with Math class methods). The negative sign is because, in trigonometry, default rotation is COUNTER-clock wised.
    double rad_angle = -Math.toRadians(angle); 

    // in order to rotate properly, we need to know the difference between the coordinates, to get a base for the rotation.
    double diff_x = this.x - center.X(); 
    double diff_y = this.y - center.Y(); 

    // calculate the rotation difference
    this.x = diff_x * Math.cos(rad_angle) - diff_y* Math.sin(rad_angle);  
    this.y = diff_x * Math.sin(rad_angle) + diff_y * Math.cos(rad_angle);

    // translate the differences back to this point
    this.x = this.x + center.X(); 
    this.y = this.y + center.Y();

    return;
}//rotate

提前感谢。

1 个答案:

答案 0 :(得分:0)

    angle += 0.2f * delta;
    position.x = target.x + (float) Math.sin(angle) * distanceFromCenter;
    position.y = target.y + (float) Math.cos(angle) * distanceFromCenter;

真的没有什么了。