View Full Version : Linear Mapping issue

sajis997

11-25-2015, 06:16 PM

Hello forum,

I am not sure if the title is proper or not. I better explain the issue. I have to generate a fractal curve inside an arbitrary window of size pXq where the lower left corner of the window is (0,0). After the generating the fractal within the window, I have to map the coordinates of the fractal to another domain where the lower left corner of the window may not be at (0,0). It could be (-560,789)/(-23,-45).

I hope that the issue is explained. Some hint/references is appreciated.

Thanks

Raptor2277

11-25-2015, 09:25 PM

Hello forum,

I am not sure if the title is proper or not. I better explain the issue. I have to generate a fractal curve inside an arbitrary window of size pXq where the lower left corner of the window is (0,0). After the generating the fractal within the window, I have to map the coordinates of the fractal to another domain where the lower left corner of the window may not be at (0,0). It could be (-560,789)/(-23,-45).

I hope that the issue is explained. Some hint/references is appreciated.

Thanks

Lets say we have window1 and window2. Lets say the window is defined by x,y,w,h where x,y is the a corner and w,h is the width and height. The formula to go from window1.xy to window2.xy is:

P = point on window1;

xfactor = window2.width / window1.width;

yfactor = window2.height / window1.height;

xoffset = window2.x - window1.x;

yoffset = window2.y - window1.y;

P2 = new Point;

P2.x = xfactor ( p.x ) + xoffset;

p2.y = yfactor ( p.y ) + yoffset;

P2 is the point on window2;

Note the xy must be the same corner for both windows. So if the upper-left on window1 is 0,0. And the bottom-left on window2 is 0,0. Then we just invert the y.

Note if both windows have the same size then the y and x factors become 1. Then you can simplify the formula to P2.x = p.x + xoffset, P2.y = p.y + yoffset;

Raptor2277

11-25-2015, 09:40 PM

So lets work through a hypothetical example. w1( 0, 0, 1600, 900) upper-left, w2(10, 10, 90, 90) lower-left.

Lets pick a point on w1 to convert to w2. Lets use the middle of the screen. it would be (800, 450) on w1 and (55, 55) on w2.

P = (800,450);

xfactor = 90 / 1600 = 9 / 160;

yfactor = 90 / 900 = 9 / 90 = 1 / 10;

xoffset = 10 - 0 = 10;

yoffset = 10 - 0 = 10;

P2.x = 9 / 160 * ( 800) + 10 = 45 + 10 = 55;

P2.y = 1 / 10 * (450) + 10 = 45 + 10 = 55;

since w1 corner is uppler-left and w2 corner is lower-left, we need to invert y of the solution. P2.y = w2.h + w2.y - w2.y; so we get P2.y = 100 + 10 - 55 = 110 - 55 = 55;

sajis997

11-26-2015, 04:28 AM

Note the xy must be the same corner for both windows.

What is the point of mapping if the lower left corner coordinates of both windows (x,y) are same. Is not what you meant ?

Raptor2277

11-28-2015, 03:39 PM

What is the point of mapping if the lower left corner coordinates of both windows (x,y) are same. Is not what you meant ?

They might still have different widths and heights. And some windows use 0,0 as top left, while others use 0,0 as bottom left.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.