缩放旋转的元素 [英] Scaling of a rotated element

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

问题描述

让我们假设我有一个要在视觉设计器中旋转和缩放的元素: 用户应该能够拖动边缘,并且图形应该适当缩放.
旋转以度为单位输入.

Let's suppose I have an element that I want to rotate and scale in a visual designer: A user should be able to drag the edges and the graphics should scale appropriately.
The rotation is entered in degree.



以下事实是旋转元素的问题:
拖动左上角的点时,不仅宽度和高度都会改变,左上角的位置也会改变. 拖动右上角时,大小会更改,Y位置也会更改

但是,如果旋转元素(WPF RenderTransform,绕其中心旋转),则行为必须相应地更改,而我不知道该怎么做.假设元素旋转了90°,则先前左上角的点就是右上角的点.
这意味着我必须进行一些更改,但是我完全感到沮丧,

我正在寻找一种在任何图形程序中实现的行为.
用户基本上会拖动边界框的点,并且图形应在该框内投影.



Following fact is an issue with rotated element:
When the top left point is dragged not only the width and height will change, but the top left position as well. When the top right point is dragged then the size changes, and the Y-Position as well

If the element is rotated however (WPF RenderTransform, rotated around it's center) then the behaviour must change accordingly, and I dont know how. Assuming the element is rotated 90° then the point that was top left previously is the top right one.
Which means that I have to transform something, but I'm totally stumped I'm afraid

I'm looking for a behaviour that is implemented in any graphical program.
The user basically drags points of the bounding box and the graphic should be projected inside the box.

如何在WPF中解决此问题?
绘制的元素派生自UIElement,因此我可以访问所需的所有变换属性.该解决方案应适用于输入的任何轮换.
如果您能为我提供帮助或为我指明正确的方向,我将不胜感激.

How can this problem be solved in WPF?
The elements that are drawn derive from UIElement, so I can access all the transform properties needed. The solution should work for any rotation entered.
I'd appreciate if you could help me, or point me in the right direction.

修改:
我知道如何缩放和旋转元素.理想的结果是该元素完全适合用户拖动的盒子.因此,与WPF相关的问题更多是与数学相关的问题.


I know how to scale and rotate the elements. The desired result is that the element perfectly fits in the box the user dragged. So this problem is more math related than WPF related.

修改:
感谢您的投票,但没有给我建议我可以改进的地方.
为了了解问题,请尝试以下操作:
创建一个新的WPF项目,添加ANY UIElement并将其旋转,例如旋转90°.
现在,请记住在拖动之前将边距拖到右下角的某个位置.如您所见,边距(=头寸)也发生了变化.我的问题是如何计算此补偿,以在拖动时为用户提供所需的结果.因为如果我不更改位置以补偿比例,则结果将很奇怪,并且不会达到预期的效果.
补偿取决于元素的比例.明显地.
请参考下图:
您在此处看到的是在拖动右下角点之前的Canvas.Top和Canvas.Left属性,以及在拖动右下角点之后的Canvas.Top和Canvas.Left属性.
http://imageshack.us/photo/my-images/268/beforeaftert.png/?sa = 0


Thanks for downvoting without providing me a suggestion on what I could improve.
In order to understand the problem try the following:
Create a new WPF Project, add ANY UIElement and rotate it, 90° for example.
Now remember the margin BEFORE you drag, and drag the bottom right point somewhere. As you can see the margin (= position) changes as well. My question would be how to calculate this compensation to give the user the desired result when dragging. Because if I do not change the position to compensate the scale, than the result is just weird and doesn't behave as expected.
The compensation depends on the scale of the element. Obviously.
Please refer to the following picture:
What you see here is the Canvas.Top and Canvas.Left property before I dragged the bottom right point, and below after I dragged the bottom right point.
http://imageshack.us/photo/my-images/268/beforeaftert.png/?sa=0

推荐答案

也许看看

Maybe have a look at http://www.codeproject.com/Articles/22952/WPF-Diagram-Designer-Part-1 The resize part covers these issues. The basic idea is to recognize the element where you click for resizing (left corner, right corner etc.) Then there is the 'math' stuff to set Left and Top of your Canvas.

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

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