R
Richard A. DeVenezia
0,0 1000,0
+-------------------------+
| |
| .75,.75 |
| +-----------+ |
| | 100,100| |
| | | |
| | | |
| | | |
| |20,20 | |
| +-----------+ |
| .25,.25 |
| |
+-------------------------+
0,1000 1000,1000
I am trying to handle Viewports and Windows using multiple AffineTranforms
w=1000 // width of image in pixels
h=1000 // height of image in pixels
// viewport is specified as fraction of image
vllx = .25 // viewport lower left
vlly = .25
yurx = .75 // viewport upper right
yury = .75
// window is specified in world coordinates
wllx = 20 // window lower left
wlly = 20
wury = 100 // window upper right
wury = 100
*** transforms here ***
// Draw three circles centered at world coordinate 60,60 with radii 10,20,30
g.drawOval(60-10,60-10,20,20);
g.drawOval(60-20,60-20,40,40);
g.drawOval(60-30,60-30,60,60);
I am having a terrible time trying to figure out what the transforms should be.
The mapping from world coords (Wx,Wy) to pixels coords (Px,Py) is:
// pixel X
Px = 0 + w * ( vllx + (Wx - wllx)/(wurx - wllx) * (vurx - vllx);
// pixel Y
Py = h - h * ( vlly + (Wy - wlly)/(wury - wlly) * (vury - vlly);
I tried
g.translate (-wllx, -wlly);
g.scale (vw/ww,vh/wh);
g.translate (vllx, vlly);
g.scale (w, -h);
g.translate (0, h);
but nothing showed
I tried
g.translate (-wllx, -wlly);
g.scale (vw/ww,vh/wh);
which drew something, but is obviously not correct.
A program with only this stuff can be found at
www.devenezia.com/java/affine/Sample.java
Any help is greatly appreciated.
Richard A. DeVenezia
+-------------------------+
| |
| .75,.75 |
| +-----------+ |
| | 100,100| |
| | | |
| | | |
| | | |
| |20,20 | |
| +-----------+ |
| .25,.25 |
| |
+-------------------------+
0,1000 1000,1000
I am trying to handle Viewports and Windows using multiple AffineTranforms
w=1000 // width of image in pixels
h=1000 // height of image in pixels
// viewport is specified as fraction of image
vllx = .25 // viewport lower left
vlly = .25
yurx = .75 // viewport upper right
yury = .75
// window is specified in world coordinates
wllx = 20 // window lower left
wlly = 20
wury = 100 // window upper right
wury = 100
*** transforms here ***
// Draw three circles centered at world coordinate 60,60 with radii 10,20,30
g.drawOval(60-10,60-10,20,20);
g.drawOval(60-20,60-20,40,40);
g.drawOval(60-30,60-30,60,60);
I am having a terrible time trying to figure out what the transforms should be.
The mapping from world coords (Wx,Wy) to pixels coords (Px,Py) is:
// pixel X
Px = 0 + w * ( vllx + (Wx - wllx)/(wurx - wllx) * (vurx - vllx);
// pixel Y
Py = h - h * ( vlly + (Wy - wlly)/(wury - wlly) * (vury - vlly);
I tried
g.translate (-wllx, -wlly);
g.scale (vw/ww,vh/wh);
g.translate (vllx, vlly);
g.scale (w, -h);
g.translate (0, h);
but nothing showed
I tried
g.translate (-wllx, -wlly);
g.scale (vw/ww,vh/wh);
which drew something, but is obviously not correct.
A program with only this stuff can be found at
www.devenezia.com/java/affine/Sample.java
Any help is greatly appreciated.
Richard A. DeVenezia