Re: How to rotate a 2-D plot and fit in the same view area ? [message #7130] |
Sat, 28 September 1996 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Whoa Gary...
I had just congratulated myself for solving a ticklish problem for
you before breakfast (and on a Saturday, no less) and I thought
I would reward myself with a nice cup of coffee and a bagel.
However, no sooner had I put the first swipe of cream chesse
on the bagel then the horrible thought hit me...
Yikes! My solution won't work!
What I wrote in my example program was:
> ; Transform the position coordinates to account for NO rotation
> ; in the display window
>
> temp = position(0)
> position(0) = 1.0 - position(2)
> position(2) = temp
What I *should* have written was:
; Transform the position coordinates to account for NO rotation
; in the display window
p = position
p = [p(1), p(0), p(3), p(2)]
offset = 1.0 - p(2)
p(2) = offset + (p(2) - p(0))
p(0) = offset
position = p
My first solution worked for your example program (at least
it *looked* like it worked), but wouldn't work for the general
case. I have tested this solution more thoroughly and I believe
it works generally.
Now, I am in deep trouble with my wife for not getting the
laundry started, I've got to coach a soccer game, and ....
Let's just same I'm turning the d*** computer OFF!
Yours,
David
--
David Fanning, Ph.D.
Phone: 970-221-0438
Fax: 970-221-4728
E-Mail: davidf@fortnet.org
|
|
|
Re: How to rotate a 2-D plot and fit in the same view area ? [message #7131 is a reply to message #7130] |
Sat, 28 September 1996 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
OK, Gary, *now* I see what you want to do. You were almost there. You write:
> The example given by David will not rotate the labels for x and y axises.
> I think to solve the problem need to use T3D. However I did some tests and
> cannot figure out how to set keywords ROT and TRANS to get the correct plot
> and position for the plot. Please use the following example as the base for
> testing on different conditions.
>
> x=[0,1]
> y=[0,2]
> T3D, /RESET, ROT=[0,0,-90], TRANS=[-1.0, 0.0, 0.0]
> PLOT, x, y, /T3D
>
> T3D, /RESET, ROT=[0,0,-90], TRANS=[-1.3, 0.0, 0.0]
> PLOT, x, y, /T3D, POSITION=[0.5,0.5,0.8,0.8]
>
The second PLOT command above will work. In fact it *does*
work. (Although I had to add a NOCLIP keyword to see the plot.
The result, I think, of round-off considerations on some machines.)
But what you are missing is that the POSITION keyword applies
to the position of the plot in the XY plane. So this plot goes
exactly where you tell it to go.
The problem, of course, is that you didn't want it at the right
position in the XY plane (which you just successfully rotated).
You wanted in the same position in your display window (which
you *didn't* rotate!).
To compensate for the fact that you rotated the XY plane but
not the display window, you have to perform a transformation
of the position coordinates as well. The example program
below does that successfully.
But just one question. *WHY* do you want to do this!? :-)
************************************************
PRO EXAMPLE
; Set up position in display window.
position = [0.5, 0.5, 0.8, 0.8]
; Normal plot.
WINDOW, 0, TITLE='NORMAL PLOT'
x=[0,1]
y=[0,2]
PLOT, x, y, POSITION=position
; Rotate the plot 90 degrees.
WINDOW, 1, TITLE='ROTATED PLOT'
T3D, /RESET, ROT=[0,0,-90], TRANS=[-1.0, 0.0, 0.0]
; Transform the position coordinates to account for NO rotation
; in the display window
temp = position(0)
position(0) = 1.0 - position(2)
position(2) = temp
; Draw the plot at same position in DISPLAY window.
PLOT, x, y, POSITION=position, /T3D, /NOCLIP
END
************************************************
Thanks for the challenging problem!
Yours,
David
--
David Fanning, Ph.D.
Phone: 970-221-0438
Fax: 970-221-4728
E-Mail: davidf@fortnet.org
|
|
|
Re: How to rotate a 2-D plot and fit in the same view area ? [message #7134 is a reply to message #7130] |
Fri, 27 September 1996 00:00  |
gfu
Messages: 10 Registered: October 1995
|
Junior Member |
|
|
In article <davidf-ya023080002609962158590001@news.fortnet.org>, davidf@fortnet.org (David Fanning) writes:
Hi,
The example given by David will not rotate the labels for x and y axises.
I think to solve the problem need to use T3D. However I did some tests and
cannot figure out how to set keywords ROT and TRANS to get the correct plot
and position for the plot. Please use the following example as the base for
testing on different conditions.
x=[0,1]
y=[0,2]
T3D, /RESET, ROT=[0,0,-90], TRANS=[-1.0, 0.0, 0.0]
PLOT, x, y, /T3D
T3D, /RESET, ROT=[0,0,-90], TRANS=[-0.9, 0.0, 0.0]
PLOT, x, y, /T3D, POSITION=[0.5,0.5,0.8,0.8]
T3D, /RESET, ROT=[0,0,-90], TRANS=[-1.2, 0.0, 0.0]
PLOT, x, y, /T3D, POSITION=[0.5,0.5,0.8,0.8]
T3D, /RESET, ROT=[0,0,-90], TRANS=[-1.3, 0.0, 0.0]
PLOT, x, y, /T3D, POSITION=[0.5,0.5,0.8,0.8]
Gary
|> Gary Fu (gfu@shark.gsfc.nasa.gov) is trying to trip us up with
|> a trick question when he writes:
|>
|> > Does any one know how to rotate a 2-D plot 90 degree (clockwise) so that
|> > the result still displays on the same viewing area defined by !p.position ?
|>
|> Uh, *any* plot you draw with the POSITION keyword set the same is going to go
|> into the same position into the window.
|>
|> > For example, how do I rotate the result of
|> > 'PLOT, [0,1], position=[0.5,0.5,0.9,0.9]' 90 degree and still displays in
|> > the [0.5,0.5,0.9,0.9] viewing area ?
|>
|> Well, this is a tricky example. Try this one (so you can see the rotation).
|>
|> a = FINDGEN(11)
|> b = a * 30
|>
|> ; Regular plot.'
|>
|> WINDOW, 0
|> PLOT, a, b, POSITION=[0.5,0.5,0.9,0.9]
|>
|> ; Plot rotated by 90 degrees.
|>
|> WINDOW, 1
|> PLOT, b, a, POSITION=[0.5,0.5,0.9,0.9]
|>
|> Same position in window. Axes rotated by 90 degrees (?!).
|>
|> Or (it just occurs to me!) to *really* rotate the first plot
|> by 90 degrees, do this:
|>
|> PLOT, b, a, POSITION=[0.5,0.5,0.9,0.9], YRANGE=[10,0]
|>
|> Alright, I give up! What's the answer? :-)
|>
|> David
|>
|> --
|> David Fanning, Ph.D.
|> Phone: 970-221-0438
|> Fax: 970-221-4728
|> E-Mail: davidf@fortnet.org
--
*****************************************
* Gary Fu, GSC (301) 286-7107 *
* email : "gfu@shark.gsfc.nasa.gov" *
* Laboratory for Hydrospheric Processes *
* NASA/Goddard Space Flight Center *
*****************************************
|
|
|