Matrix / coordinate transformation in C#

試著忘記壹切 提交于 2019-12-01 23:19:14

I'm assuming you want to transform the image to the unit square ( (0, 0) - (1.0, 1.0)) You need three points, one is the origin, the other will be transformed to the x-axis (1.0, 0) and the other to the y-axis (0, 1.0).

In the original coordinate system:

  • The origin is (Ox, Oy)
  • The X-axis is (X1, Y2)
  • The Y-Axis is (X2, Y2)
  • X-Axis relative to the origin (X1-Ox, Y1-Oy) will be shortened to (RX1, RY1)
  • Y-Axis relative to the origin (X2-ox, Y2-Oy) will be shortened to (RX2, RY2)

First we will shift the origin to (0,0) in homogeneous coordinates the transform matrix will be

(1   0   -Ox)
(0   1   -Oy)
(0   0    1) 

The transform from the new space to the old one is represented by the following matrix:

(RX1   RX2   0)
(RY1   RY2   0)
( 0    0     1)

Because you want the inverse transformation, from old space to the new one, we need the invert this matrix: Let's shorten (RX1*RY2-RX2*RY1) as D

(RY2/D   -RX2/D   0)
(-RY1/D   RX1/D   0)
(  0       0      1)

Now you can multiply both matrices first you do the translation and then use the second matrix to transform the basis.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!