# RE: Positioning text within a circle

• From: "Sina Bahram" <sbahram@xxxxxxxxx>
• To: <programmingblind@xxxxxxxxxxxxx>
• Date: Sun, 8 Feb 2009 13:10:07 -0500

```Ken's approach is guaranteed to work for any arbitrary point P. glad I read
to the end, otherwise I was writing up the exact same email.

Just so I can add something to the so called body of knowledge of this
discussion. This formula is also amazingly useful, in an even more
simplified way, to calculate the value of pi, since one can continuously do
a monticarlo simulation of random points that land inside and outside of the
rectangle, but still inside the circle. That ratio is then a fraction of pi,
and you're good to go after multiplying, by four, if I remember correctly.

Take care,
Sina

________________________________

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of E.J. Zufelt
Sent: Sunday, February 08, 2009 12:30 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Positioning text within a circle

Good afternoon Ken,

You might be right.  Essentially the information that I provided will allow
you to provide any point, lets say any corner of the rectangle that bounds
the text, and then determine if that point is inside or outside of the
circle.

So, I'm pretty sure that it will work.  Regardless the radius and midpoint
of the circle, my method should be able to determin if any particular point
is inside or outside of the circle.  Using that and the bounds of the text I
think a pretty easy determination should be able to be made about if the
bounds of the text are inside of the circle.

But, it's been a long time since I needed to do this type of thing, and I am
quite possibly incorrect.

HTH,
Everett

On 8-Feb-09, at 1:04 PM, Ken Perry wrote:

I don't think that will work for what he
wants.  He I think is saying if he has rectangle not in the midpoint but
anywhere in the circle he wants to know if it goes outside the circle.  This
takes a bit different work then you have done here I think.
Ken
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of E.J. Zufelt
Sent: Sunday, February 08, 2009 1:06 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Positioning text within a circle
Good evening Ian,
It's been a while since I had to do anything like this.
If I understand correctly you need to determine if any particular
point (p) is outside of the circle.
1. You need to calculate for the right angle triangle formed between
the midpoint of the circle, the point that you are testing, and either the
intersect of that point on the x or y axis.
2. You know the hight of the triangle, and the width of the triangle
(calculated by the distance your point is vertically and horizontally from
the midpoint of the circle.
3. You know that the maximum hypotenus of the triangle is the radius
of the circle, if the hypotenus is greater than the radius then the point is
outside of the circle.
Example:
A circle with radius of 10 and midpoint (20, 20), testing for point
(10, 10).
height = 20 - 10 = 10
Width = 20 - 5 = 15
Hypotenus = sqr(10^2 + 15^2)
hypotenus = sqr(100 + 225)
Hypotenus = sqr (325)
Hypotenus = roughly 18
Since the hypotenus is greater than the radius of the circle then
the point is outside of the circle.
HTH,
Everett
On 8-Feb-09, at 1:28 AM, Ian D. Nichols wrote:

Hi Ken,
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,

----- Original Message -----
From: Ken Perry <mailto:whistler@xxxxxxxxxxxxx>
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
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.