Alignment of coordinate systems

Say I have 2 coordinate systems as shown in the attached image enter image description here

How can I align these coordinate systems? I know that I need to translate the second coordinate system around X with 180 degrees, and then translate it to (0, 0) of the first coordinate system, but I have some problems with the fact that this leads to incorrect results. We will be very grateful for the detailed answer.

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

+3
source share
3 answers

An important piece of information is where the second origin of the coordinate system is, namely (a,b) .

Once you know this, all you need is:

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

You should find the 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 of the point in one system, and X, Y in another.

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

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

0
source

There is a problem with rotation of 180 degrees, this not only affects the direction of your Y coordinate, but also on X.

  YX <- +
 ^ => |
 |  v
 + -> XY

What you probably wanted to do was translate the point to Y and then invert the Y coordinate. You can do it like this:

  • Convert Y to a new origin
  • Scale (1, -1)
  Y + -> X
 ^ => |
 |  v
 + -> XY


Thinking again, I have to wonder why you are doing this conversion in the first place? Is it due to differences in the OpenGL coordinates and the Qt coordinates for its window?

If so, you can change the projection matrix ... If you use a spelling matrix, for example:

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

If you decide to do this, you probably need to change the winding direction of your polygon faces. OpenGL defaults to CCW, change it to glFrontFace (GL_CW) , and this should prevent strange lighting / rejection behavior.

0
source

Source: https://habr.com/ru/post/1499953/


All Articles