MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Rectangle and Circle

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105552] Re: [mg105540] Rectangle and Circle
  • From: "David Park" <djmpark at comcast.net>
  • Date: Tue, 8 Dec 2009 06:45:11 -0500 (EST)
  • References: <15926420.1260169669975.JavaMail.root@n11>

I'm certain there are ways to do this in plain Mathematica. For example
write the equations for each of the lines and the circle and use NSolve to
look for solutions.

The Presentations package contains a PlaneGeometry subpackage for writing
dynamic plane geometry diagrams. Specifically it has the routines:

lineCircleIntersection[{center,r},{a,b}] will return a list of the
intersection point(s) of the circle with the given center and radius r, and
the line defined by the points a and b.

parametrizedLine[(a,b}][s] will parametrize the line {a,b}.

inverseParametrizedLine[p,{a,b}] will return the parameter s for a point p
that is on the line defined by points a and b.

So I would make a dynamic presentation with locators for one corner of the
rectangle and the center of the circle and sliders for the width and height
of the rectangle and the radius of the circle. (Or alternatively one could
use two locators for the rectangle to define opposite corners.) Then I would
use lineCircleIntersection to look for intersections on each of the sides of
the rectangle, and inverseParametrizedLine to determine if any intersection
was in the segment of the line that defined the rectangle or on the extended
portion of the line. On the side of the diagram one could also display
numerically the current coordinates of any intersection points. 

I won't show all the code for this because it would take a little work to
set it up for all four sides, and maybe you don't really want a dynamic
diagram. However I will show a sample calculation of intersection points.
Let the rectangle and circle be defined by:

ptA = {0, 0};
ptB = {1, 0};
ptC = {1, 1};
ptD = {0, 1};
center = {3/2, 3/2};
radius = 1;

Then we can check for intersections of the circle with side AB. There are
none.

lineCircleIntersection[{center, radius}, {ptA, ptB}]
{}

For intersections with sides BC and CD we have:

{pt1, pt2} = lineCircleIntersection[{center, radius}, {ptB, ptC}]
{{1., 0.633975}, {1., 2.36603}}

{pt3, pt4} = lineCircleIntersection[{center, radius}, {ptC, ptD}]
{{0.633975, 1.}, {2.36603, 1.}}

There are two intersections with each of the sides because the lines are
considered to extend beyond the segment between the two points. However we
can determine if the intersections are on the side segment by calculating
the point parameter for a parametrized line between the points. The
parameter goes from 0 to 1 between the points. So to check if pt1 and pt2
are on the side segment we can use:

0 <= inverseParametrizedLine[pt1, {ptB, ptC}] <= 1
True

0 <= inverseParametrizedLine[pt2, {ptB, ptC}] <= 1
False

PlaneGeometry also has many other convenient routines for constructing
dynamic geometric diagrams. 


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  


From: zowtar [mailto:zowtar at gmail.com] 

I don't know if here is the right place to ask it, but I don't know
where to go... so...

I have...
a circle: center point and radius size.
a rectangle: 4 corner points.

I already know if the circle is inside of the rectangle, or if the
rectangle is inside the circle, or if the case 1 of my image
happens... I want to know if the circle has an intersection with the
rectangle like the case 2 of my image...  Any ideia?

http://img199.imageshack.us/img199/9347/cases.gif




  • Prev by Date: multiplication of large multivariate polynomials
  • Next by Date: Re: How to combine Dynamic graphics
  • Previous by thread: Re: Rectangle and Circle
  • Next by thread: multiplication of large multivariate polynomials