围绕中心点旋转点 [英] Rotating a point around a center point

查看:461
本文介绍了围绕中心点旋转点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里有一些关于点和旋转的问题,我觉得我快到了.我需要一点推动力.

I am aware that there are a few questions about points and rotation out here, and I feel like Im almost there. I youst need a little push.

我有一个像这样的6点形状.

I Have a shape with 6 points like this one.

我想围绕点 C

而且我需要手动执行此操作,所以我对使用AffineTransform不感兴趣

And I need to do this manually so I am not interested in using AffineTransform

预先感谢

Thread thread = new Thread() {

    public void run() {

        //THE RADIUS OF THE SHAPE IS 100

        //GET THE POINT P
        PointClass point_class = points.get(0);

        //GET THE CENTER POINT C
        Point center = new Point(point_class.point.x - 100, point_class.point.y);

        int deg = 0;

        while(deg < 360) {

            //GET THE ANGLE IN RADIANS
            double angle = Math.toRadians(deg);

            //FIRST TRANSLATE THE DIFFERENCE
            int x1 = point_class.point.x - center.x;
            int y1 = point_class.point.y - center.y;

            //APPLY ROTATION
            x1 = (int) ((double) x1 * Math.cos(angle) - y1 * Math.sin(angle));
            y1 = (int) ((double) x1 * Math.sin(angle) + y1 * Math.cos(angle));

            //TRANSLATE BACK
            point_class.point.x = x1 + center.x;
            point_class.point.y = y1 + center.y;

            //ROTATE + 1 DEEGRE NEXT TIME
            deg++;

            try {

                //SLEEP TO SEE THE DIFFERENCE
                sleep(100);

            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
};

thread.start();


此代码发生的事情是Point P像这样终止在中心


What happens with this code is that the Point P ends up in the center like this

推荐答案

所以我找出了问题所在.

So I figured out what was wrong.

这两点的翻译,

//FIRST TRANSLATE THE DIFFERENCE
double x1 = point_class.point.x - center.x;
double y1 = point_class.point.y - center.y;

必须走出循环,因为应用旋转矩阵时我需要在该位置取底.而且在循环中,我应该将deegre固定为1,这样它只能增量1,而不是81 + 82 + 83 ...不知道我为什么这样做.

has to go outside of the loop, because I need to take base at that location when applying the rotation matrix. And also in the loop, I should have the deegre fixed at 1, so that it is only incrementet by 1 and not 81+82+83...Dont know why i did that.

希望这对某人有帮助=)

Hope this helps someone =)

这篇关于围绕中心点旋转点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆