RE: Positioning text within a circle

 

 

Ok you can use the formula s1^2+s2^2=h^2 to make sure your rectangles cross
hypotenuse fits as the diameter of the circle.  From there you just need to
place the center point of the rectangle in the middle of the circle.  So
just Using small numbers I will say that your long side is 4, your short
side is 3 and your circle is 5 diameter.  We can find if the rectangle has
the same diameter by doing:

 

3^2 +4^2 =5^2 Which it does.  Most of the circle drawing functions I have
used draw the circle from a midpoint so you 

 

drawCircle(10+l/2,10+s/2)) 

When you print the text starting at upper left hand corner of the box 10,10
you should get it in the center 

 

So if I am being confusing the thing I am doing is splitting your rectangle
into two right triangles.  Finding the hypotenuse which will criss cross the
rectangle right in the middle.  That becomes both the center point of the
rectangle and the circle.  It also will be the diameter of the circle and
the rectangle.  So if your hypotenuse fits as the diameter then it fits.
Then its just simply finding the center and calculating where to place the
first part so the centers of the rectangle and the circle corresponds.  If
you need help and I am being too confusing just send me your circle drawing
function and text writing function and I will try and help you out.

 

Ken

 

  

 

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ian D. Nichols
Sent: Saturday, February 07, 2009 6:57 PM
To: program-l@xxxxxxxxxxxxx; programmingblind@xxxxxxxxxxxxx
Subject: Positioning text within a circle

 

Hi Listers,

 

I have a circle drawn on the monitor screen.  I know its diameter and its
centre point in screen pixels.

 

I want to make sure that text I draw on the screen is completely within this
circle.  I use the TextOut function, which uses a POINT sructure for
positioning the text.  I can use GetTextExtentPoint32 to calculate the size
and location of the enclosing rectangle of the text.  I need to make sure
that all four of the corners of that rectangle are going to fall within the
circle.

 

Can some one please tell me how I can determine the location of the
circumference of the circle, so that I can check that my text rectangle will
fall completely within it?  I'm more than 50 years out of high school, and
didn't study mathematics or geometry, or whatever it is that I need, at
university.

 

Thanks in advance.

 

Ian

 

Ian D. Nichols,

Toronto, Canada

 

Other related posts: