Re: Positioning text within a circle

  • From: "Ian D. Nichols" <inich@xxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 8 Feb 2009 00:28:12 -0500

Hi Ken,

Thanks very much for your reply.

Unfortunately I didn't make it clear that I do not want to centre the text in 
the circle.  I want to place text anywhere in the circle and make sure that no 
part of the text accidentally lands outside the circle.  What I need to obtain, 
or calculate for myself, are the coordinates of a sufficient number of points 
on the dircumference so that I can check to see that the corners of the 
rectangle containing the text are all within the circle.  I have that logic 
worked out already.  What I am lacking are the numbers to compare the 
coordinates of the text with.

I recognize that it is a rather complicated procedure.  Windows must know how 
to do it because the ellipse function with equal x and y axes draws a perfect 
circle.

I've calculated the coordinates of the 4 points where the diagonals intersect 
the circumference, and I did it using the theorem of Pythagarus, as you did in 
your reply.  But only the diagonals of the circle's bounding square coincide 
with the hypotenuses of right-angled triangles, so that method is very limited 
in what it can do.

Thanks again.  I live in hope!

All the best,

Ian

Ian D. Nichols,
Toronto, Canada

  ----- Original Message ----- 
  From: Ken Perry 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Saturday, February 07, 2009 9:07 PM
  Subject: 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: