绕一个点的矩形 [英] Rotate rectangle around a point

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

问题描述

如何将得到4分绕一个指针一定程度,以形成一个矩形?我可以绕一个点一个点,但我不能抵消它使未变形的矩形。

How would I get 4 points rotated a certain degrees around a pointer to form a rectangle? I can rotate a point around a point, but I can't offset it to make a rectangle that isn't distorted.

推荐答案

如果你可以绕一个点一个点,那么你就应该很容易旋转矩形 - 你只需旋转4个

If you can rotate a point around a point then you it should be easy to rotate a rectangle - you just rotate 4 points.

下面是一个js函数来绕原点的点:

Here is a js function to rotate a point around an origin:

function rotate_point(pointX, pointY, originX, originY, angle) {
    angle = angle * Math.PI / 180.0;
    return {
        x: Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX,
        y: Math.sin(angle) * (pointX-originX) + Math.cos(angle) * (pointY-originY) + originY
    };
}

然后你就可以做到这一点,以每个点。 这里有一个例子: http://jsfiddle.net/dahousecat/4TtvU/

And then you can do this to each point. Here is an example: http://jsfiddle.net/dahousecat/4TtvU/

变换角度和命中运行,看看结果......

Change the angle and hit run to see the result...

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

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