- Introduction
- Reference
- Class Methods
- intersectShapes
- intersectPathShape
- intersectBezier2Bezier2
- intersectBezier2Bezier3
- intersectBezier2Circle
- intersectBezier2Ellipse
- intersectBezier2Line
- intersectBezier2Polygon
- intersectBezier2Rectangle
- intersectBezier3Bezier3
- intersectBezier3Circle
- intersectBezier3Ellipse
- intersectBezier3Line
- intersectBezier3Polygon
- intersectBezier3Rectangle
- intersectCircleCircle
- intersectCircleEllipse
- intersectCircleLine
- intersectCirclePolygon
- intersectCircleRectangle
- intersectEllipseEllipse
- intersectEllipseLine
- intersectEllipsePolygon
- intersectEllipseRectangle
- intersectLineLine
- intersectLinePolygon
- intersectLineRectangle
- intersectPolygonPolygon
- intersectPolygonRectangle
- intersectRectangleRectangle
- bezout
- Methods
- Properties
- Download

Intersection is a JavaScript object used to capture the results of the intersection of two Shape objects. Class methods perform the actual intersections and use only Point2D objects as parameters. This makes this class useful stand-alone uses where you don't want to use the 2D Geometry library.

The Ellipse-Ellipse intersection code is based on code written by David Eberly. That code and many more excellent examples are available at his site. If you are at all interested in 3D gaming algorithms, then I highly recommend his "3D Game Engine Design" book (ISBN 1-55860-593-2).

This code is used in the 2D Geometry section of this site.

intersectShapes(*shape1, shape2*) : Intersection;

This method determines which of the following intersection methods to call based on the types of the two shape parameters. One special case is tested for paths since these shapes need to be handled differently than all other shapes.

The Intersection object is returned from the resulting intersection method that is called by this method.

intersectPathShape(*path, shape*) : Intersection;

This method calls the specified path's intersectShape method to find all intersections between the specified path and shape.

intersectBezier2Bezier2(*a1, a2, a3, b1, b2, b3*) : Intersection;

- No Intersection, no points: the quadratic Beziers do not intersect
- Intersection, 1-4 intersection points: the shapes intersect

Find the intersection of two quadratic Beziers. An Intersection object is returned with the following values:

intersectBezier2Bezier3(*a1, a2, a3, b1, b2, b3, b4*) : Intersection;

- No Intersection, no points: the quadratic Bezier and the cubic Bezier do not intersect
- Intersection, 1-6 intersection points: the shapes intersect

Find the intersection of a quadratic Bezier and a cubic Bezier. An Intersection object is returned with the following values:

intersectBezier2Circle(*p1, p2, p3, c, r*) : Intersection;

- No Intersection, no points: the quadratic Bezier and the circle do not intersect
- Intersection, 1-4 intersection points: the shapes intersect

Find the intersection of a quadratic Bezier and a circle. Note that this routine uses the intersectBezier2Ellipse() method to find all intersections. An Intersection object is returned with the following values:

intersectBezier2Ellipse(*p1, p2, p3, ec, rx, ry*) : Intersection;

- No Intersection, no points: the quadratic Bezier and the ellipse do not intersect
- Intersection, 1-4 intersection points: the shapes intersect

Find the intersection of a quadratic Bezier and an ellipse. Note that this routine is also used to find the intersection of a quadratic Bezier and an circle (although a separate intersectBezier2Circle may be created in the future). An Intersection object is returned with the following values:

intersectBezier2Line(*p1, p2, p3, a1, a2*) : Intersection;

- No Intersection, no points: the quadratic Bezier and the line do not intersect
- Intersection, 1-2 intersection points: the shapes intersect

Find the intersection of a quadratic Bezier and a line. An Intersection object is returned with the following values:

intersectBezier2Polygon(*p1, p2, p3, points*) : Intersection;

- No Intersection, no points: the quadratic Bezier and the polygon do not intersect
- Intersection, n intersection points: the shapes intersect

Find the intersection of a quadratic Bezier and a polygon. An Intersection object is returned with the following values:

intersectBezier2Rectangle(*p1, p2, p3, r1, r2*) : Intersection;

- No Intersection, no points: the quadratic Bezier and the rectangle do not intersect
- Intersection, n intersection points: the shapes intersect

Find the intersection of a quadratic Bezier and a rectangle. An Intersection object is returned with the following values:

intersectBezier3Bezier3(*a1, a2, a3, a4, b1, b2, b3, b4*) : Intersection;

- No Intersection, no points: the cubic Beziers do not intersect
- Intersection, 1-9 intersection points: the shapes intersect

Find the intersection of two cubic Beziers. An Intersection object is returned with the following values:

intersectBezier3Circle(*p1, p2, p3, p4, c, r*) : Intersection;

- No Intersection, no points: the cubic Bezier and the circle do not intersect
- Intersection, 1-4 intersection points: the shapes intersect

Find the intersection of a cubic Bezier and a circle. Note that this routine uses the intersectBezier3Ellipse() method to find all intersections. An Intersection object is returned with the following values:

intersectBezier3Ellipse(*p1, p2, p3, p4, ec, rx, ry*) : Intersection;

- No Intersection, no points: the cubic Bezier and the ellipse do not intersect
- Intersection, 1-4 intersection points: the shapes intersect

Find the intersection of a cubic Bezier and an ellipse. Note that this routine is also used to find the intersection of a cubic Bezier and an circle (although a separate intersectBezier3Circle may be created in the future). An Intersection object is returned with the following values:

intersectBezier3Line(*p1, p2, p3, p4, a1, a2*) : Intersection;

- No Intersection, no points: the cubic Bezier and the line do not intersect
- Intersection, 1-3 intersection points: the shapes intersect

Find the intersection of a cubic Bezier and a line. An Intersection object is returned with the following values:

intersectBezier3Polygon(*p1, p2, p3, p4, points*) : Intersection;

- No Intersection, no points: the cubic Bezier and the polygon do not intersect
- Intersection, n intersection points: the shapes intersect

Find the intersection of a cubic Bezier and a polygon. An Intersection object is returned with the following values:

intersectBezier3Rectangle(*p1, p2, p3, p4, r1, r2*) : Intersection;

- No Intersection, no points: the cubic Bezier and the rectangle do not intersect
- Intersection, n intersection points: the shapes intersect

Find the intersection of a cubic Bezier and a rectangle. An Intersection object is returned with the following values:

intersectCircleCircle(*c1, r1, c2, r2*) : Intersection;

- Outside, no points: the two circles a completely separate from one another
- Inside, no points: one circle is completely inside of the other circle
- Intersection, 1-2 intersection points: the shapes intersect

Find the intersection of two circles. An Intersection object is returned with the following values:

intersectCircleEllipse(*cc, r, ec, rx, ry*) : Intersection;

- No Intersection, no points: the circle and the ellipse do not intersect
- Intersection, 1-4 intersection points: the shapes intersect

Find the intersection of a circle and an ellipse. Note that this routine uses the intersectEllipseEllipse() method to find all intersections. An Intersection object is returned with the following values:

intersectCircleLine(*c, r, a1, a2*) : Intersection;

- Outside, no points: the line is completely outside of the circle
- Inside, no points: the line is completely contained by the circle
- Tangent, no points (NOTE: should return 1): the line touches the circle at a single point
- Intersection, 1-2 intersection points: the shapes intersect

Find the intersection of a circle and a line. An Intersection object is returned with the following values:

intersectCirclePolygon(*c, r, points*) : Intersection;

- Outside, no points: the polygon is completely outside of the circle
- Inside, no points: the polygon is completely contained by the circle
- Intersection, n points: the shapes intersect

Find the intersection of a circle and a polygon. An Intersection object is returned with the following values:

intersectCircleRectangle(*c, r, r1, r2*) : Intersection;

- Outside, no points: the rectangle is completely outside of the circle
- Inside, no points: the rectangle is completely inside of the circle
- Intersection, 1-8 points: the shapes intersect

Find the intersection of a circle and a rectangle. An Intersection object is returned with the following values:

intersectEllipseEllipse(*c1, rx1, ry1, c2, rx2, ry2*) : Intersection;

- No Intersection, no points: the ellipses do not intersect
- Intersection, 1-4 points: the shapes intersect

Find the intersection of two ellipses. Note that this routine is also used to find the intersection of an ellipse and a circle. An Intersection object is returned with the following values:

intersectEllipseLine(*c, rx, ry, a1, a2*) : Intersection;

- Outside, no points: the line is completely outside of the ellipse
- Inside, no points: the line is completely inside of the ellipse
- Intersection, 1-2 points: the shapes intersect

Find the intersection of an ellipse and a line. An Intersection object is returned with the following values:

intersectEllipsePolygon(*c, rx, ry, points*) : Intersection;

- No Intersection, no points: the ellipse and the polygon do not intersect
- Intersection, n points: the shapes intersect

Find the intersection of an ellipse and a polygon. An Intersection object is returned with the following values:

intersectEllipseRectangle(*c, rx, ry, r1, r2*) : Intersection;

- No Intersection, no points: the ellipse and the rectangle do not intersect
- Intersection, 1-8 points: the shapes intersect

Find the intersection of an ellipse and a rectangle. An Intersection object is returned with the following values:

intersectLineLine(*a1, a2, b1, b2*) : Intersection;

- No Intersection, no points: the lines do not intersect
- Coincident, no points: the lines overlap
- Parallel, no points: the lines are parallel, but do not overlap
- Intersection, 1 intersection point: the shapes intersect

Find the intersection of two lines. An intersection object is returned with the following values:

intersectLinePolygon(*a1, a2, points*) : Intersection;

- No Intersection: the polygon and the line do not intersect
- Intersection, n points: the shapes intersect

Find the intersection of a line and a polygon. An Intersection object is returned with the following values:

intersectLineRectangle(*a1, a2, r1, r2*) : Intersection;

- Outside, no points: the rectangle and the line do not intersect
- Intersection, 1-2 points: the shapes intersect

Find the intersection of a line and a rectangle. An Intersection object is returned with the following values:

intersectPolygonPolygon(*points1, points2*) : Intersection;

- Outside, no points: the polygons do not intersect
- Intersection, n points: the shapes intersect

Find the intersection of two polygons. An Intersection object is returned with the following values:

intersectPolygonRectangle(*points, r1, r2*) : Intersection;

- Outside, no points: the polygon and the rectangle do not intersect
- Intersection, n points: the shapes intersect

Find the intersection of a polygon and a rectangle. An Intersection object is returned with the following values:

intersectRectangleRectangle(*a1, a2, b1, b2*) : Intersection;

- Outside, no points: the rectangles do not intersect
- Intersection, n points: the shapes intersect

Find the intersection of two rectangles. An Intersection object is returned with the following values:

bezout() calculates the Bezout determinate for the two specified ellipses. The resulting quadratic polynomial is returned. This method is used by intersectEllipseEllipse.

**e1** is an array of the coefficients of an ellipse in general quadratic form: ax^2 + bxy + cy^2 + dx + ey + f = 0. The coefficients are in a,b,c,d,e,f order.

**e2** is an array of the coefficients of an ellipse in general quadratic form: ax^2 + bxy + cy^2 + dx + ey + f = 0. The coefficients are in a,b,c,d,e,f order.

constructor - new Intersection(*status*);

This method creates a new Intersection object. All initialization is handled by the init() method. All parameters for this method are described below

init() initialized all properties for this object.

**status** is a string which returns a brief description of the results of an intersection.

appendPoint() adds a new point to the point array.

**point** is the new Point2D object that is to be added to the points array.

appendPoint() adds a new point to the point array.

**points** is an array of Point2D objects to be added to the points array.

**status** is a string used to categorize the results of an intersection.

**points** is an array of Point2D objects; one point for each intersection point.

Intersection.js - the Intersection object only

2D.js.gz - all objects needed to use this object and other 2D geometry objects