将四边形变换为矩形? [英] Transform quadrilateral into a rectangle?

查看:600
本文介绍了将四边形变换为矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景由一个任意的四边形组成。我需要能够把这个四边形转换成一个矩形。每个四边形是在2d坐标,因此他们有4个顶点(x_i,y_i)



有一个反转,因为想法是在操纵矩形后回到原始的四边形。



执行此操作最简单的方法是什么?我听说它被称为透视变换,但我发现一些小的线索,使我认为这可以很容易做。

解决方案

你知道所需矩形的大小是多少?如果是这种情况,您可以将任何凸四边形映射到具有透视变换的可逆变换的矩形。所有你要做的是得到4个对应点(在四边形和矩形之间),例如,(X 1 1,Y 1),(X 2, (X 4,Y 3),(X 3,Y 3),(X 4,Y 4)对于四边形和相应地(x <1>, 1 ),(x <2>,< 2),(x 3子,y 3子),(x 4子,y 4子)为矩形。然后将其插入 Borealid's 链接中的最后一个公式,即可设置为:



上述方程(其中n = 4)的解将给出可逆的元素(a,b,c,d,e,...,h)透视变换矩阵,





这将允许您将矩形上的点变换为四边形上的点。对于逆变换,只是反转变换矩阵。



另请注意,一旦获得了变换坐标的向量[XW YW W] T ,您需要对其进行归一化,使得W = 1 。你的最终答案是[XW / W YW / WW / W] T ,它等于[XY 1] T

I have scene composed of one arbitrary quadrilateral. I need to be able to transform that quadrilateral into a rect. Each quad is in 2d coordinates, so they have 4 vertex (x_i, y_i).

The transformation need to have an inverse because the idea is to go back to the original quad after manipulating the rectangle.

What would be the easiest way to perform this operation ? I've heard it's called a perspective transformation, but I've found some small clues that lead me to think this could be quite easy to do.

解决方案

Do you know what the size of the desired rectangle is? You can map any convex quadrilateral to a rectangle with an invertible transformation with a perspective transformation if this is the case. All you have to do is get 4 corresponding points (between the quadrilateral and the rectangle), say, (X1,Y1), (X2,Y2), (X3,Y3), (X4,Y4) for the quadrilateral and correspondingly (x1,y1), (x2,y2), (x3,y3), (x4,y4) for the rectangle. Then plug it into the final equation in Borealid's link and you're set:

The solution of the above equation (where n = 4) will give you the elements (a,b,c,d,e,...,h) of the invertible perspective transformation matrix,

This will allow you to transform the points on the rectangle to the points on the quadrilateral. For the reverse transformation, just invert the transformation matrix.

Also note that once you obtain the vector [XW YW W]T of transformed coordinates, you need to normalize it such that W = 1. I.e., your final answer is [XW/W YW/W W/W]T which is equal to [X Y 1]T, the desired answer.

这篇关于将四边形变换为矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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