coordinate system mapping

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Hi All,

Assuming you have 2 coordinate systems:

A system (A) whereby [0,0,0] (X,Y,Z) specifies the center of the frame, [1,1,0] is the top right corner of the frame and [-1,-1,0] is bottom left corner of the frame. Another system (B) whereby [0,0] is the top left corner of the frame and [1,1] is the bottom right corner of the frame.

How would you convert a (x,y) coordinate from system A to system B? I need to convert this as I will have to pass this to a method to display stuffs in a frame that has a different coordinate.

I thought I'd share this with you guys... hey I am also working on this little arithmetics but anyway who is quicker is willing to post his/her solution.

Thanks
Eric
 

WBahn

Joined Mar 31, 2012
32,823
In the case of both x and y you simply need a linear equation to go from

Xb = 0 => Xa = 1
Xb = 1 => Xa = -1

Xb has a span of 1 while Xa has a span of 2, so the slope has a magnitude of 2.
As Xb increases, Xa decreases, so the slope is negative.
Xa has an offset of 1.

Xa = -2Xb + 1

Y has the same mapping.

Z is always zero.

Q.E.D.
 

WBahn

Joined Mar 31, 2012
32,823
I think it should rather be:

Xb = 0 => Xa = -1
Xb = 1 = > Xa = 1

I might be wrong though.
Could be. I didn't draw a sketch and so it's very possible that I messed it up mentally. Let's look:

System A: Top Right: [1,1,0]; Bottom Left: [-1,-1,0]
System B: Top Left [0,0]; Bottom Right: [1,1]

So let's map a consistent pair of points:

Top Left: System A: [-1,1,0]; System B: [0,0]
Bottom Right: System A: [1,-1,0]; System B: [1,1]

So you are correct. Can you come up with the equations you need, now?
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Could be. I didn't draw a sketch and so it's very possible that I messed it up mentally. Let's look:
...
So you are correct. Can you come up with the equations you need, now?
lol, yes!

From the above we get:
2 Xb = 1 and 2 Xa = 0. => Xa = 0 => 2 Xb + Xa = 1.
=> Xb = (1 - Xa) / 2.

which seems to be the same result as your equation. Is my equation correct?
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I feel like in primary school now.

Looks like Yb = (1 - Ya) / 2 as well. Anyway will have to test it in my program and check if the locations are correct.
 

WBahn

Joined Mar 31, 2012
32,823
lol, yes!

From the above we get:
2 Xb = 1 and 2 Xa = 0. => Xa = 0 => 2 Xb + Xa = 1.
=> Xb = (1 - Xa) / 2.

which seems to be the same result as your equation. Is my equation correct?
It shouldn't be, not if my earlier one was correct for the wrong mapping.

Let's check it out.

If Xa = -1 then you are at the left edge. Plug that into your equation and you get Xb = 1, which is the right edge.

So back to the drawing board.

We still have that A system has twice the span of the B system. But now both coordinates increase as you move from left to right, so the slope is positive. When Xb is zero, Xa is -1. Putting these altogether you have

Xa = 2·Xb - 1

Checking the results, when Xb = 0 (left edge), Xa = -1 (left edge). When Xb = 1 (right edge), Xa = 1 (right edge). So this checks.

If you want to go the other way, then you have

Xb = (Xa + 1) / 2 = (Xa/2) + 0.5
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Brilliant!

...

We still have that A system has twice the span of the B system.
Oh yes.

But now both coordinates increase as you move from left to right, so the slope is positive. When Xb is zero, Xa is -1. Putting these altogether you have

Xa = 2·Xb - 1

Checking the results, when Xb = 0 (left edge), Xa = -1 (left edge). When Xb = 1 (right edge), Xa = 1 (right edge). So this checks.
...
Correct!

Sometimes the simplest things can mess you up. lol

Thanks!
 
Top