用于查看 2D 绘图的变换矩阵
我正在重构一个显示绘图的图形程序。程序使用了自己的变换,代码相当复杂。我想用转换矩阵重构代码。
窗口和视图坐标为 X 向右,Y 向下。
窗口中的绘图使用左上角点作为基点(0,0)。该视图是一个屏幕矩形区域,其基点 (0,0) 也在左上角。
视图区域可以是屏幕上的任意矩形。它显示 80%x80% 区域内的绘图,周围留有一些边距。
绘图的尺寸为宽 x 高。程序应在两个方向上以相同的比例显示绘图。绘图的中心映射到视图区域的中心。绘图可旋转0~360度任意角度。
给定以下数据,一般的变换矩阵是什么:
- 绘图的宽度和高度
- 旋转角度
- 视图区域的宽度和高度
- 绘图周围的边距
I am refactoring a graphic program that shows a drawing. The program uses its own transformation and the code is quite complicated. I'd like to refact the code with a transformation matrix instead.
The window and view coordinates are X to the right and Y to downwards.
The drawing in window uses the top left point as base point (0,0). The view is a screen rectangle area with base point (0,0) at the top left point too.
The view area can by any rectangle on the screen. It shows the drawing inside 80%x80% area leaving some margins around.
The drawing has a size of width x height. The program should show the drawing with the same scale ratio at both directions. The center of the drawing is mapping to the center of the view area. the drawing can be rotated in any angle between 0 ~ 360 degrees.
What is the general transformation matrix for this, given the following data:
- width and height of the drawing
- Rotation angle
- width and height of the view area
- Margins around the drawings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要包含旋转图像的框的宽度/高度
,然后您需要计算两个维度中的哪一个将是缩放约束,
然后您可以计算 3x2 变换矩阵
First you need the width/height of the box containing the rotated image
then you need to compute which of the two dimensions will be the scaling constraint
then you can compute the 3x2 transformation matrix