Home :: Tutorials :: Geometry

1. Introduction
2. Reference
1. Class Methods
2. Methods
3. Properties

## Introduction

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.

## Reference

### Class Methods

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;

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

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

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

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

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

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

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:

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

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

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:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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:

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

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

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:

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

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

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

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

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

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

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

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

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

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

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

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

• 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

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

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:

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

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

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

• 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

intersectCirclePolygon(c, r, points) : Intersection;

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

• 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

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

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

• 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

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

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:

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

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

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

• 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

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

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

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

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

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

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

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

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

• 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

intersectLinePolygon(a1, a2, points) : Intersection;

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

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

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

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

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

intersectPolygonPolygon(points1, points2) : Intersection;

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

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

intersectPolygonRectangle(points, r1, r2) : Intersection;

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

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

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

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

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

bezout(e1, e2) : Polynomial;

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.

### Methods

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(status);

init() initialized all properties for this object.

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

appendPoint(point);

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

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

appendPoints(points);

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

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

### Properties

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.