在 2D 中将一个点旋转另一个点 [英] Rotate a point by another point in 2D

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

问题描述

我想知道如何计算一个点相对于另一个点旋转一个角度时的新坐标.

我有一个方块箭头,想将它旋转一个相对于箭头底部中间点的角度 theta.

这是允许我在 2 个屏幕控件之间绘制多边形所必需的.我无法使用和旋转图像.

从我目前所考虑的情况来看,使问题进一步复杂化的是屏幕的原点位于左上角.

解决方案

如果将点 (px, py) 围绕点 (ox, oy) 旋转角度 theta 你会得到:

<前>p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + oxp'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy

I want to know how to work out the new co-ordinates for a point when rotated by an angle relative to another point.

I have a block arrow and want to rotate it by an angle theta relative to a point in the middle of the base of the arrow.

This is required to allow me to draw a polygon between 2 onscreen controls. I can't use and rotate an image.

From what I have considered so far what complicates the matter further is that the origin of a screen is in the top left hand corner.

解决方案

If you rotate point (px, py) around point (ox, oy) by angle theta you'll get:

p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy

这篇关于在 2D 中将一个点旋转另一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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