Re: native device coordinates

From: <brownrig_at_nyahnyahspammersnyahnyah>
Date: Wed Apr 20 2011 - 13:46:46 MDT

Hi Jimmy,

I had sort of stated things confusingly in my earlier reply; NCL fits
the largest square NDC-space into the available image space, such that
the square completely spans the image's shortest axis, and is centered
about its longest axis. You can see that in the NDC grid in the plot
you'd sent.

The image you sent was 520x416 pixels. That means that the 0-th pixel
in Y has NDC coord = 1.0, while the 415-th pixel has NDC coord = 0.0
 (pixels are numbered starting from the top-left corner). Thus, the
extreme pixels in X are:

   0-th pixel in X: 0.0 - (imageWidth - imageHeight)/2.0
519-th pixel in X: 1.0 + (imageWidth - imageHeight)/2.0

In general, to find the pixel values of a known point in NDC space,
you do something like:

   if (imageWidth .ge. imageHeight) then
       pixelPerNDC = imageHeight
       xOriginOffset = (imageWidth - imageHeight) / 2.0
       yOriginOffset = 0.
   else
       pixelPerNDC = imageWidth
       xOriginOffset = 0.
       yOriginOffset = (imageHeight - imageWidth) / 2.0
   end if

   pntInPixelsX = ndcX * pixelPerNDC + xOriginOffset
   pntInPixelsY = imageHeight - (ndcY * pixelPerNDC) + yOriginOffset

Does that make sense?

BTW: to programmatically get the image dimensions (assuming a PNG
workstation-type), you can do:

   getvalues wks
         "wkWidth" : imageWidth
         "wkHeight" : imageHeight
   end getvalues

Hope that helps...
Rick

On Wed, 20 Apr 2011 13:19:36 -0500
  James Correia <jimmyc42@gmail.com> wrote:
> Hi Rick-
>
> http://hwt.nssl.noaa.gov/Spring_2011/pdfgen.000001.png
>
> That is the image with the NDC grid drawn over it. I realized that
>the
> points close to 0.5 in x are actually better than the ones towards
>the
> edges. So I applied a scaling factor in x to sort of account for
>this. It
> isn't perfect but it is close enough for what I am trying to
>accomplish.
>
> How can I see what the ndc range is?
> Thanks for your help.
> jimmyc
>
>
> On Wed, Apr 20, 2011 at 12:56 PM, Rick Brownrigg <brownrig@ucar.edu>
>wrote:
>
>> Hi James,
>>
>> I don't know if this is the issue, but it may be important to note
>>that if
>> your plot is rectangular in shape, then NDC space runs from [0..1]
>>along the
>> shortest axis. Thus along the longest axis, NDC has a range greater
>>than
>> 1.0, and it is *centered* about [0..1] such that the min is some
>>smallish
>> negative value and the max is some value marginally greater than 1.
>> Does
>> that make sense? In your case, is your plot taller than it is wide?
>>
>> Hope that helps...
>> Rick
>>
>> On Apr 20, 2011, at 10:52 AM, James Correia wrote:
>>
>> > All-
>> > Can anyone provide insight as to how datatondc works?
>> >
>> > I make a map that has some points on it, and I have the lat-lon
>>locations
>> of those points which I then try to get the ndc coordinates of. The
>>purpose
>> of the map is to put on a web page where on mouseover some text pops
>>up. It
>> appears my ndc points do not line up (points on the left side of the
>>image
>> are further left, and points to the right of the image are slightly
>>to the
>> right).
>> >
>> > I know the pixel count so I did my conversion from ndc to pixel
>>space. I
>> thought the ndc space is the whole page, is that correct?
>> >
>> > Thanks for any help.
>> >
>> > --
>> >
>> ------------------------------------------------------------------------------------------
>> > The views expressed in this email do not necessarily reflect those
>>of
>> NOAA, the National Weather Service, or the University of Oklahoma.
>> >
>> ------------------------------------------------------------------------------------------
>> > James Correia Jr.
>> > OU CIMMS Research Associate
>> > SPC HWT Liaison
>> >
>> > _______________________________________________
>> > ncl-talk mailing list
>> > List instructions, subscriber options, unsubscribe:
>> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
>
> --
> ------------------------------------------------------------------------------------------
> The views expressed in this email do not necessarily reflect those
>of NOAA,
> the National Weather Service, or the University of Oklahoma.
> ------------------------------------------------------------------------------------------
> James Correia Jr.
> OU CIMMS Research Associate
> SPC HWT Liaison

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Apr 20 13:46:55 2011

This archive was generated by hypermail 2.1.8 : Tue May 03 2011 - 14:47:35 MDT