计算平移后的旋转中心
我需要能够围绕给定点旋转图像,以便图像的任何部分出现在容器的中心都是旋转中心。
为了计算中心点,我目前只是取应用于图像的平移的倒数:
Rotate.CenterX = Translate.X * -1;
Rotate.CenterY = Translate.Y * -1;
但是,我使用的当前计算还不够,因为如果图像之后被平移,则它不起作用强>正在旋转。
我确信这是一个相当简单的三角函数,我只是想不出它是什么!
干杯
I need to be able to rotate an image around a given point so that what ever part of the image appears in the center of my container is the center of rotation.
To calculate the center points, I am currently just taking the inverse of the translation applied to the image:
Rotate.CenterX = Translate.X * -1;
Rotate.CenterY = Translate.Y * -1;
However, the current calculation i'm using is not sufficient as it does not work if the image has been translated after being rotated.
I'm sure it's a reasonably straight forward trig function, I just can't think what it is!
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在使用 GDI+,请使用以下命令:
如果您正在使用 WPF 图形对象,请使用以下变换组:
X & Y 是要平移图像的百分比值(如果图像为 1000 像素且 X 为 0.1,则图像将平移 100 像素)。这就是我需要该功能工作的方式,但您可以轻松更改它。
If you are working with GDI+ then use the following:
If you are working with WPF graphic objects, use the following transform group:
X & Y are the percent values you want to translate the image in (if the image is 1000 pixels and X is 0.1 then the image will be translated 100 pixels). This is how I needed the function to work but you can easily change it otherwise.