[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: units conversion (was: about contibuting to octave)
From: |
Michael Goffioul |
Subject: |
Re: units conversion (was: about contibuting to octave) |
Date: |
Fri, 5 Jun 2009 21:58:19 +0100 |
On Mon, Jun 1, 2009 at 4:54 AM, xianghang liu<address@hidden> wrote:
> Hi,
> I have a questiongs about units conversion from pixel to data. While doing
> the text rendering, I use transform method of the axes object to get the
> position of the text object in 'pixels' unit. The result is correct.
> While doing the bounding box calculation, I add a property extent and doing
> the calculation in the new function:
> text::properties::get_extent (void) const
> In this function, after get the bbox in 'pixels', I tried to use untransform
> method of the axes object to convert units to "data". I call that method
> like this:
> const base_properties& par_props = gh_manager::get_object (get_parent
> ()).get_properties ();
> const axes::properties& axes_props = dynamic_cast<const
> axes::properties&> (par_props);
> graphics_xform axes_xform = axes_props.get_transform ();
> ColumnVector bsize = axes_xform.untransform(cx,cy,0); //cx, cy is
> the sizeof bbox in 'pixels'
> The result is not correct. I also tried the axes::properties::pixel2coord
> method, and the result is not correct neither.
> So my question is what is the mistake in my code and what is the right way
> to do the units conversion from 'pixels' to 'data'?
The right to convert pixels to data (and the opposite) is to use
the transform/untransform methods. BUT these methods are intended
to be applied to single point coordinates, while you want to convert a
rectangle. I didn't test, but I think you have to transform the coordinates
of the 2 opposite corners of the rectangle and recompute the size of
your rectangle by substracting the coordinates of the transformed points.
That is, conceptually:
p0 = (0,0,0)
p1 = (cx,cy,0)
t0 = axes.transform(p0)
t1 = axes.transform(p1)
extent = [t1.x-t0.x, t1.y-t0.y, t1.z-t0.z]
Now, I just looked at Matlab doc about the Extent property and it
seems to have special meaning when Units is "data": while it's clear
how to obtain "left" and "bottom", I'm not sure about the meaning of
"width" and "height", especially in 3D mode. I guess some experimentation
under Matlab would help a little...
Michael.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: units conversion (was: about contibuting to octave),
Michael Goffioul <=