在 wpf 中平移变换后对象无法正确旋转?

发布于 2024-11-09 10:06:35 字数 128 浏览 0 评论 0原文

我的画布上有几个从面板类继承的自定义控件,在运行时使用 rendertransform=(.5,.5) 动态添加到其中。但是当应用平移变换(50,50)并将其旋转100度时,它并没有原地旋转,而是以50的半径旋转,为什么? 我做错了什么吗?

I have canvas with several cutom controls inherited from panel class, dynamically added to it at runtime with rendertransform=(.5,.5). But when apply translate transform (50,50) and rotate it by 100 degrees, it does not rotate on its place, it rotates in radius of 50, why?
Am I doing wrong something ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾其所爱 2024-11-16 10:06:35

变换不可交换,您应该在应用平移之前应用旋转。

通常,您有一个 TransformGroup,那么您可以更改其子级的顺序,如果这在某种程度上不是一个选项,因为某些变换是从父级“继承”的,您可以使用它们的逆来取消先前的变换(在翻译的情况下)应该将目标移回原点),然后您可以将其旋转到位,并再次应用原始变换。


该文档是您的朋友,以下是 的内容TransformGroups

在复合转换中,各个转换的顺序很重要。例如,如果您先旋转,然后缩放,然后平移,则与先平移,然后旋转,然后缩放会得到不同的结果。顺序很重要的原因之一是旋转和缩放等变换是相对于坐标系的原点进行的。缩放以原点为中心的对象与缩放远离原点的对象会产生不同的结果。同样,旋转以原点为中心的对象与旋转远离原点的对象会产生不同的结果。

Transformations are not commutative, you should apply the rotation before applying the translation.

Often you have a TransformGroup, then you can just change the order of its children, if this is somehow not an option because some transform is "inherited" from a parent you can nullify prior transforms using their inverse (in the case of a translation that should move the target back to the origin), then you can rotate it in place, and apply the original transform again.


The documentation is your friend, here is what can be found for TransformGroups:

In a composite transformation, the order of individual transformations is important. For example, if you first rotate, then scale, then translate, you get a different result than if you first translate, then rotate, then scale. One reason order is significant is that transformations like rotation and scaling are done with respect to the origin of the coordinate system. Scaling an object that is centered at the origin produces a different result than scaling an object that has been moved away from the origin. Similarly, rotating an object that is centered at the origin produces a different result than rotating an object that has been moved away from the origin.

一身软味 2024-11-16 10:06:35

如果它以50的半径旋转,那是因为你的原点是错误的。

您只需将 CenterXCenterY 属性均设置为 50 即可更改 RotateTransform 的原点。案件。

If it rotates with a radius of 50, it's because your origin is wrong.

You just need to change the origin of your RotateTransform by setting the CenterX and CenterY properties both to 50 in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文