Re: rotations in threed plots

From: Dave Kennison (kennison AT unknown)
Date: Wed Oct 15 2003 - 13:43:12 MDT

  • Next message: Antoine Rousseau: "f90"

    Joel,

    I am appending below, following copies of previous emails, two different
    programs, one that uses THREED to draw some axes and another that uses
    TDPACK to draw the same axes.

    If you run one of these without change, you will get a 99-frame NCGM that
    you can animate using "idt gmeta". (Click on "animate", wait while it
    creates 99 bit-map representations of the 99 frames, then click on "loop",
    and then click on ">>" or "<<". You might also need to make the idt display
    window a bit smaller in order to keep down the size of the bit maps.)

    Playing with these programs should give you some feel for how THREED and
    TDPACK work; I think the logic of the programs is pretty simple.

    THREED always uses the center of the box as the point looked at and sets
    up the projection so that a vector pointing in the positive W direction
    from the box center point projects into a vector that points in the positive
    Y direction in the projection plane; but, if you put the eye almost directly
    above the center of the box, it will use a vector pointing in a different
    direction as the one that projects into the positive-Y vector; this can
    lead to strange glitches in a movie. TDPACK doesn't have this problem,
    because it makes you you specify a point defining the vector that projects
    into a positive-Y vector in the projection.

    Joel: I just had an "oh-my-God" moment: what I just said above may explain
    what's happening to you: you may be seeing the discontinuity in the behavior
    of THREED when using a viewpoint that is almost exactly above the center
    point of the box as opposed to one that is not so positioned.

    I also just realized that it is the *V* axis, rather than the *W* axis,
    that you want to be the one pointing upward in the projection plane; this
    invalidates some of what I said in my previous message. If you always want
    the V axis to point upward in the projection plane, you'll either have to
    use TDPACK or get into the code of THREED and modify it, because THREED
    really isn't equipped to let you do it (part of the reason I wrote TDPACK).

    For documentation of "TDPACK", see the following URL:

      http://ngwww.ucar.edu/ngdoc/ng4.3/supplements/tdpack/

    Note that I have used an unadvertised "relative size feature" of THREED
    in order to turn off automatic scaling of the image and enable the making
    of an animation. I have also used an unadvertised internal routine to
    compute the X and Y coordinates of the projection of a 3D point. In both
    cases, the analogous features of TDPACK are just part of the interface.

    I hope these programs are helpful ...

    Dave Kennison

    Original email:
    -------- ------

    > From ncarg-talk-admin AT unknown Wed Oct 8 10:31:20 2003
    > To: ncarg-talk AT unknown
    > Subject: rotations in threed plots
    >
    > I want to draw a plot of points in 3-d along with their x,y,z coordinate
    > axes, as seen from an oblique viewpoint, but with two of the three axes
    > lined up along the plot page like so:
    > v
    > |__________
    > | |
    > .|. . . . .|
    > .|. . . . .|
    > .|_________|__ u
    > / . . . . .
    > /
    > /w
    > using threed routines, if I choose the viewpoint approximately along one
    > of the axes, say by making the viewpoint array eye = (0,0,1000), I do get
    > roughly this form:
    > v
    > |
    > |. . . . .
    > |. . . . .
    > |. . . . .
    > |__________ u
    > (w)
    > But, if the the viewpoint is off-axis, say (1000,1000,1000), the plot
    > comes out rotated about the line joining eye and the origin by an amount
    > I don't know how to control, like
    > u
    > /|..
    > /.|..
    > / .|..
    > / .|..
    > / .|..
    > | .|..
    > | .|..
    > | .|..
    > | / \
    > | / \
    > / \
    > v w
    > The usual threed routines (set3, curve3, perim3, point3) have no further
    > variables to adjust. Is there a way then to rotae this back, i.e., specify
    > both of the orientation angles? (A previous suggesttion was to call set3
    > once for the points with the oblique value for eye, and then for the axis
    > with the "on-axis" value, but this breaks the connection between the points
    > and their coordinate values.)

    Another email:
    ------- ------

    > From koplik AT unknown Wed Oct 15 09:03:20 2003
    > To: kennison AT unknown
    > Subject: Re: rotations in threed plots
    >
    > Dave,
    >
    > Thanks for the response. I'll follow your suggestion and try out
    > TDPACK, but the issue is the following. Your idea of puting the viewed
    > point away from the origin (default in THREED) does seem to correspond to
    > my first figure. In thinking about it further, however, the feature I
    > really want is to have is the v-axis vertical: in a perspective view the
    > other two should rotate around v so as to correspond to the value of eye.
    > The problem with THREED is somehow the whole figure is being rotatedi and I
    > can't fix the one axis.
    >
    > Joel

    THREED test program:
    ------ ---- --------

          PROGRAM TESTIT
    C
    C This program uses THREED to draw pictures of three intersecting axes,
    C each of which runs from -1 to +1. The output is best viewed using
    C the "animate" feature of "idt". Some unadvertised features of THREED
    C are used.
    C
    C Define NVWS, the number of views to be generated. Each of the views
    C is from a different point along a horizontal circle centered on the
    C point (0,0,2) and having a radius of 5.
    C
            PARAMETER (NVWS=99)
    C
    C Define the error file, the Fortran unit number, the workstation type,
    C and the workstation ID to be used in calls to GKS routines.
    C
            PARAMETER (IERF=6,LUNI=2,IWTY=1 ,IWID=1) ! NCGM
    C PARAMETER (IERF=6,LUNI=2,IWTY=8 ,IWID=1) ! X Windows
    C PARAMETER (IERF=6,LUNI=2,IWTY=20,IWID=1) ! PostScript
    C PARAMETER (IERF=6,LUNI=2,IWTY=11,IWID=1) ! PDF, Portrait
    C PARAMETER (IERF=6,LUNI=2,IWTY=12,IWID=1) ! PDF, Landscape
    C
    C Declare a THREED common block so as to have access to a variable
    C RZERO. Here's how RZERO is described in the documentation of THREED:
    C
    C RELATIVE SIZE FEATURE IN USE. THIS SECTION OF CODE IS NEVER
    C EXECUTED UNLESS RZERO IS SET POSITIVE IN THE CALLING PROGRAM
    C VIA COMMON BLOCK TEMPRT. "RZERO" IS THE DISTANCE BETWEEN THE
    C OBSERVER AND THE POINT LOOKED AT (CENTER OF THE BOX BY DEFAULT)
    C WHEN THE INPUT BOX IS TO FILL THE SCREEN WHEN VIEWED FROM THE
    C DIRECTION WHICH MAKES THE BOX BIGGEST. "RZERO" IS THUS TO
    C BE USED TO DETERMINE THE SHAPE OF THE OBJECT. THIS SECTION
    C OF CODE IS TO BE USED WHEN IT IS DESIRED TO KEEP THE VIEWED
    C OBJECT IN RELATIVE PERSPECTIVE ACROSS FRAMES--E.G. IN MAKING
    C MOVIES.
    C
            COMMON /TEMPRT/ RZERO
    C
    C Declare an array to hold the eye position.
    C
            DIMENSION EYE(3)
    C
    C Open GKS.
    C
            CALL GOPKS (IERF,0)
            CALL GOPWK (IWID,LUNI,IWTY)
            CALL GACWK (IWID)
    C
    C Turn off the clipping indicator.
    C
            CALL GSCLIP (0)
    C
    C Turn off the automatic scaling of the image box to fit the viewport.
    C
            RZERO=8.
    C
    C Run through a set of different eye positions.
    C
            DO 101 I=1,NVWS
    C
    C Calculate the position of the eye.
    C
              EYE(1)=5.*COS(.017453292519943*(REAL(I-1)/REAL(NVWS))*360.)
              EYE(2)=5.*SIN(.017453292519943*(REAL(I-1)/REAL(NVWS))*360.)
              EYE(3)=2.
    C
    C Initialize THREED. Uncomment the first of these to get a fixed Z
    C axis, the second to get a Z axis that moves in a little circle.
    C Playing with this call is the best way to get a feel for the
    C projection.
    C
              CALL SET3 (.1,.9,.1,.9,-1.0,+1.0,-1.0,+1.0,-1.0,+1.0,EYE)
    C CALL SET3 (.1,.9,.1,.9,-1.0,+1.1,-1.0,+1.1,-1.0,+1.1,EYE)
    C
    C See what SET call was done by THREED.
    C
              CALL GETSET (XVPL,XVPR,YVPB,YVPT,XWDL,XWDR,YWDB,YWDT,LNLG)
    C
    C Draw the axes.
    C
              CALL LINE3 (-1., 0., 0., 1., 0., 0.)
              CALL LINE3 ( 0.,-1., 0., 0.,+1., 0.)
              CALL LINE3 ( 0., 0.,-1., 0., 0.,+1.)
    C
    C Label the ends of the axes.
    C
              CALL TRN32T (-1.07,0.,0.,XPOS,YPOS,DUMI,2)
              CALL PLCHHQ (CPUX(INT(XPOS)),CPUY(INT(YPOS)),'-X',.02,0.,0.)
    C
              CALL TRN32T (+1.07,0.,0.,XPOS,YPOS,DUMI,2)
              CALL PLCHHQ (CPUX(INT(XPOS)),CPUY(INT(YPOS)),'+X',.02,0.,0.)
    C
              CALL TRN32T (0.,-1.07,0.,XPOS,YPOS,DUMI,2)
              CALL PLCHHQ (CPUX(INT(XPOS)),CPUY(INT(YPOS)),'-Y',.02,0.,0.)
    C
              CALL TRN32T (0.,+1.07,0.,XPOS,YPOS,DUMI,2)
              CALL PLCHHQ (CPUX(INT(XPOS)),CPUY(INT(YPOS)),'+Y',.02,0.,0.)
    C
              CALL TRN32T (0.,0.,-1.07,XPOS,YPOS,DUMI,2)
              CALL PLCHHQ (CPUX(INT(XPOS)),CPUY(INT(YPOS)),'-Z',.02,0.,0.)
    C
              CALL TRN32T (0.,0.,+1.07,XPOS,YPOS,DUMI,2)
              CALL PLCHHQ (CPUX(INT(XPOS)),CPUY(INT(YPOS)),'+Z',.02,0.,0.)
    C
    C Advance the frame.
    C
              CALL FRAME
    C
    C End of loop on eye position.
    C
      101 CONTINUE
    C
    C Close GKS.
    C
            CALL GDAWK (IWID)
            CALL GCLWK (IWID)
            CALL GCLKS
    C
    C Done.
    C
            STOP
    C
          END

    TDPACK test program:
    ------ ---- --------

          PROGRAM TESTIT
    C
    C This program uses TDPACK to draw pictures of three intersecting axes,
    C each of which runs from -1 to +1. The output is best viewed using
    C the "animate" feature of "idt".
    C
    C Define NVWS, the number of views to be generated. Each of the views
    C is from a different point along a horizontal circle centered on the
    C point (0,0,2) and having a radius of 5.
    C
            PARAMETER (NVWS=99)
    C
    C Define the error file, the Fortran unit number, the workstation type,
    C and the workstation ID to be used in calls to GKS routines.
    C
            PARAMETER (IERF=6,LUNI=2,IWTY=1 ,IWID=1) ! NCGM
    C PARAMETER (IERF=6,LUNI=2,IWTY=8 ,IWID=1) ! X Windows
    C PARAMETER (IERF=6,LUNI=2,IWTY=20,IWID=1) ! PostScript
    C PARAMETER (IERF=6,LUNI=2,IWTY=11,IWID=1) ! PDF, Portrait
    C PARAMETER (IERF=6,LUNI=2,IWTY=12,IWID=1) ! PDF, Landscape
    C
    C Open GKS.
    C
            CALL GOPKS (IERF,0)
            CALL GOPWK (IWID,LUNI,IWTY)
            CALL GACWK (IWID)
    C
    C Turn off the clipping indicator.
    C
            CALL GSCLIP (0)
    C
    C Use a 25-degree (instead of the default 20-degree) field of view.
    C
            CALL TDSETI ('FOV',25)
    C
    C Run through a set of different eye positions.
    C
            DO 101 I=1,NVWS
    C
    C Calculate the position of the eye.
    C
              UEYE=5.*COS(.017453292519943*(REAL(I-1)/REAL(NVWS))*360.)
              VEYE=5.*SIN(.017453292519943*(REAL(I-1)/REAL(NVWS))*360.)
              WEYE=2.
    C
    C Initialize TDPACK. Uncomment the first of these to get fixed Z axis,
    C the second to get a Z axis that moves in a little circle, the third
    C to get the effect of a little circular pendulum. Playing with this
    C call is the best way to get a feel for the projection.
    C
              CALL TDINIT (UEYE,VEYE,WEYE, 0., 0.,0., 0., 0.,1.,0.)
    C CALL TDINIT (UEYE,VEYE,WEYE,.05,.05,0.,.05,.05,1.,0.)
    C CALL TDINIT (UEYE,VEYE,WEYE,.05,.05,0., 0., 0.,1.,0.)
    C
    C Draw the axes.
    C
              CALL TDLINE (-1., 0., 0., 1., 0., 0.)
              CALL TDLINE ( 0.,-1., 0., 0.,+1., 0.)
              CALL TDLINE ( 0., 0.,-1., 0., 0.,+1.)
    C
    C Label the ends of the axes.
    C
              CALL TDPRPT (-1.07,0.,0.,XPOS,YPOS)
              CALL PLCHHQ (XPOS,YPOS,'-X',.02,0.,0.)
    C
              CALL TDPRPT (+1.07,0.,0.,XPOS,YPOS)
              CALL PLCHHQ (XPOS,YPOS,'+X',.02,0.,0.)
    C
              CALL TDPRPT (0.,-1.07,0.,XPOS,YPOS)
              CALL PLCHHQ (XPOS,YPOS,'-Y',.02,0.,0.)
    C
              CALL TDPRPT (0.,+1.07,0.,XPOS,YPOS)
              CALL PLCHHQ (XPOS,YPOS,'+Y',.02,0.,0.)
    C
              CALL TDPRPT (0.,0.,-1.07,XPOS,YPOS)
              CALL PLCHHQ (XPOS,YPOS,'-Z',.02,0.,0.)
    C
              CALL TDPRPT (0.,0.,+1.07,XPOS,YPOS)
              CALL PLCHHQ (XPOS,YPOS,'+Z',.02,0.,0.)
    C
    C Advance the frame.
    C
              CALL FRAME
    C
    C End of loop on eye position.
    C
      101 CONTINUE
    C
    C Close GKS.
    C
            CALL GDAWK (IWID)
            CALL GCLWK (IWID)
            CALL GCLKS
    C
    C Done.
    C
            STOP
    C
          END
    _______________________________________________
    ncarg-talk mailing list
    ncarg-talk AT unknown
    http://mailman.ucar.edu/mailman/listinfo/ncarg-talk



    This archive was generated by hypermail 2b29 : Mon Oct 20 2003 - 08:34:47 MDT