> Hello,
>
> I need a tipp for drawing an oval around a dynamic textfield with
> variable line numbers and variable width? Perhaps, someone can point
> me to a good tutorial dealing with such geometry questions.
> The drawOval methods I am using have width and height as parameters,
> but of course I can't use width and height of the textfield without a
> padding. How can I calculate an i     appropriate padding?

Hi,

Assuming your bezier curve is at least an approximate ellipse (I haven't
done the maths to be sure), here's how you can find an ellipse that contains
a particular rectangle. Suppose the rectangle has half-width w and
half-height h. You want an ellipse of half-width a and half-height b such
that the point (w,h) lies on it (assume it's centred on (0,0): you can add
the x,y coordinates at the end). The locus of a point P on an ellipse
aligned with the axes is:

P = (a * cos(t), b * sin(t)), where t lies between 0 and 2*pi (we only need
to think about t between 0 and pi/2, though).

So we need to find a and b such that a*cos(t) = w and b*sin(t) = h, for some
t. Notice that since we've got three variables and two equations, there are
an infinite number of possible solutions. If you pick any value of t between
0 and pi/2, you can simply read off the values of a and b as a = w/cos(t), b
= h/sin(t). So the only tricky bit is choosing a value of t that makes your
ellipse fit the rectangle reasonably tightly. I think I'd do it ideally by
trying to minimise the value of (a-w)^2 + (b-h)^2, thus minimising the
distance of the extremes from the rectangle edges, but that's a bit ugly. In
practice, I think you could do it by choosing t based on the ratio w/h (try
w*(pi/4)/h if w<h, pi/4 + h*(pi/4)/w if w>h as a first thought, but I
haven't tried it)

HTH
Danny

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to