Aligning coordinate systems

空扰寡人 提交于 2019-12-04 09:46:28

问题


Let's say I have 2 coordinate systems as it is shown in image attached

How can I align this coordinate systems? I know that I need to translate second coordinate system around X with 180 grads, and then translate it to (0, 0) of the first coordinate system, but I have some troubles with doing it getting wrong results. Will really appreciate any detailed answer.

EDIT: Actually (0, 0) of second coordinate system is in the same point like Y of the first coordinate system.


回答1:


The important piece of information is where is the second coordinate system's origin - namely (a,b).

Once you know that, all you need is:

QPointF pos1; // original position
QTransform t;
t.scale(1, -1);
t.translate(a, -b+1);
QPointF pos2 = pos1 * t;



回答2:


You have to find correct values of a,b,c,d,Ox,Oy in:

X = a * x + b * y + Ox

Y = c * x + d * y + Oy

where x,y are the coordinates on the point in one system and X,Y in the other one.

In your case, a = 1, b = 0, c = 0, d = -1. Ox,Oy is the offset between the Origins.

see https://en.wikipedia.org/wiki/Change_of_basis




回答3:


Here's the problem with rotating 180 degrees, it not only affects the direction of your Y coordinate but also X.

Y             X <--+
^        =>        |
|                  v
+--> X             Y

What you probably meant to do was translate the point at Y and then invert your Y-coordinate. You can do this like so:

  1. Translate Y to new origin
  2. Scale (1, -1)
Y             +--> X
^        =>   |
|             v
+--> X        Y


After more thought, I have to wonder, why are you doing this transformation in the first place? Is it because of differences in OpenGL coordinates and the coordinates Qt uses for its window?

If this is the case, you can actually alter your projection matrix... If you're using an orthographic matrix, for instance:

Try glOrtho (0, X, 0, Y, -1, 1); instead of the traditional glOrtho (0, X, Y, 0, -1, 1);

If you opt to do this, you will probably need to change the winding direction of your polygon "front faces". OpenGL defaults to CCW, change it to glFrontFace (GL_CW) and this should prevent weird lighting / culling behavior.



来源:https://stackoverflow.com/questions/18551162/aligning-coordinate-systems

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