circle-circle.cpp revision 981b809bc6ed10a21e89444d9447e5475801874f
/* circle_circle_intersection() *
* Determine the points where 2 circles in a common plane intersect.
*
* int circle_circle_intersection(
* // center and radius of 1st circle
* double x0, double y0, double r0,
* // center and radius of 2nd circle
* double x1, double y1, double r1,
* // 1st intersection point
* double *xi, double *yi,
* // 2nd intersection point
* double *xi_prime, double *yi_prime)
*
* This is a public domain work. 3/26/2005 Tim Voght
* Ported to lib2geom, 2006 Nathan Hurst
*
* Copyright 2006 Nathan Hurst <njh@mail.csse.monash.edu.au>
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
*/
#include <stdio.h>
#include <math.h>
#include "point.h"
namespace Geom{
{
/* dx and dy are the vertical and horizontal distances between
* the circle centers.
*/
/* Determine the straight-line distance between the centers. */
double d = L2(D);
/* Check for solvability. */
{
/* no solution. circles do not intersect. */
return 0;
}
{
/* no solution. one circle is contained in the other */
return 1;
}
/* 'point 2' is the point where the line through the circle
* intersection points crosses the line between the circle
* centers.
*/
/* Determine the distance from point 0 to point 2. */
/* Determine the coordinates of point 2. */
/* Determine the distance from point 2 to either of the
* intersection points.
*/
/* Now determine the offsets of the intersection points from
* point 2.
*/
/* Determine the absolute intersection points. */
return 2;
}
};
#ifdef TEST
{
printf("x0=%F, y0=%F, r0=%F, x1=%F, y1=%F, r1=%F :\n",
printf(" x3=%F, y3=%F, x3_prime=%F, y3_prime=%F\n",
}
int main(void)
{
/* Add more! */
exit(0);
}
#endif