Node: Ellipse Intersections, Next: , Previous: Returning Elements and Information for Ellipses, Up: Ellipse Reference



Intersections

bool_point_pair intersection_points (const Point& p0, const Point& p1) const virtual function
bool_point_pair intersection_points (const Path& p) const virtual function
These functions return the intersection points of a line with an Ellipse. In the first version, the line is specified by the two Point arguments. In the second version, p.is_linear() must return true, otherwise, intersection_points() issues an error message and returns INVALID_BOOL_POINT_PAIR.

If the line and the Ellipse are coplanar, there can be at most two intersection points. Otherwise, there can be at most one.

          Ellipse e(origin, 5, 7, 30, 30, 30);
          e.shift(3, 0, 3);
          Point p0 = e.get_center().mediate(e.get_point(3));
          Point normal = e.get_normal();
          Point A = normal;
          A *= 2.5;
          A.shift(p0);
          Point B = normal;
          B *= -2.5;
          B.shift(p0);
          bool_point_pair bpp = e.intersection_points(A, B);
          bpp.first.pt.dotlabel("$i_0$", "rt");
          Point C = e.get_point(15).mediate(e.get_point(11), 1.25);
          Point D = e.get_point(11).mediate(e.get_point(15), 1.5);
          Path q = C.draw(D);
          bpp = e.intersection_points(q);
          bpp.first.pt.dotlabel("$i_1$", "llft");
          bpp.second.pt.dotlabel("$i_2$", "ulft");
          


[Figure 167. Not displayed.]

Fig. 167.

bool_point_quadruple intersection_points (Ellipse e, [const real step = 3, [bool verbose = false]]) const virtual function
Returns the intersection points of two Ellipses. Two Ellipses can intersect at at most four points.

Let bpq be the bool_point_quadruple returned by intersection_points(). If one or more intersection points are found, the corresponding Points are stored in the pt elements of the four bool_points belonging to bpq, otherwise INVALID_POINT. If a Point is found, the b element of the bool_point will be true, otherwise false.

The step argument is used when the Ellipses are coplanar and either have different centers or the vertical axis of one Ellipse is colinear with the horizontal axis of the other (and vice versa). In these cases, the intersection points must be found by an iterative routine. A Point p travels around the perimeter of *this, and its location with respect to e is tested. step is the angle of rotation used for stepping around the perimeter of *this. The default value, 3, should be adequate, unless the Ellipses differ greatly in size.

If the verbose argument is true, intersection_points() will print information about the intersection points to standard output.

In [next figure] , the Ellipses e and f both lie in the x-z plane, are centered at the origin, and intersect at four points.

          Ellipse e(origin, 5, 2);
          Ellipse f(origin, 2, 5);
          bool_point_quadruple bpq = e.intersection_points(f);
          bpq.first.pt.dotlabel(1, "llft");
          bpq.second.pt.dotlabel(2, "urt");
          bpq.third.pt.dotlabel(3, "ulft");
          bpq.fourth.pt.dotlabel(4, "lrt");
          


[Figure 168. Not displayed.]

Fig. 168.

In [next figure] , e and f are coplanar, but don't lie in a major plane, have different centers, and only intersect at two points.

          Ellipse e(origin, 4, 2);
          Ellipse f(origin, 2, 5);
          f.shift(0, 0, 1);
          f.rotate(0, 15);
          f.shift(1, 0, 1);
          e *= f.shift(-.25, 1, -1);
          e *= f.rotate(10, -12.5, 3);
          bool_point_quadruple bpq = e.intersection_points(f, true);
          bpq.first.pt.dotlabel(1, "urt");
          bpq.second.pt.dotlabel(2, "ulft");
          


[Figure 169. Not displayed.]

Fig. 169.

If the planes of the Ellipses are parallel, there are, of course, no intersection points. If the Ellipses are non-coplanar, and their planes are not parallel to each other, intersection_points() first finds the line of intersection of the planes of the Ellipses. It then returns the Points of intersection of this line with the Ellipses, if they exist. If the verbose argument is true, information about the Points is printed to standard output.

In [next figure] , the two Ellipses lie in skew planes. The plane of f intersects with e at the Points labelled "1" and "2", while the plane of e intersects with f at the Points labelled "3" and "4".

          Ellipse e(origin, 5, 3);
          Ellipse f(origin, 2, 5);
          f.rotate(0, 0, 30);
          f.rotate(0, 10);
          f.rotate(45);
          f.shift(1.5, 1);
          bool_point_quadruple bpq = e.intersection_points(f, true);
          bpq.first.pt.dotlabel(1);
          bpq.second.pt.dotlabel(2);
          bpq.third.pt.dotlabel(3, "rt");
          bpq.fourth.pt.dotlabel(4, "urt");
          -| First point lies on the perimeter of *this.
             First point lies inside e.
             Second point lies on the perimeter of *this.
             Second point lies outside e.
             Third point lies outside *this.
             Third point lies on the perimeter of e.
             Fourth point lies inside *this.
             Fourth point lies on the perimeter of e.
          


[Figure 170. Not displayed.]

Fig. 170.

In [next figure] , the two Ellipses lie in skew planes. The plane of f intersects with e at the Points labelled "1" and "2". The plane of e does not intersect with f, so bpq.third.pt and bpq.fourth.pt are INVALID_POINT.

          Ellipse e(origin, 5, 3);
          Ellipse f(origin, 2, 5, 45);
          f.shift(0, 2.5, 3);
          bool_point_quadruple bpq = e.intersection_points(f, true);
          bpq.first.pt.dotlabel(1);
          bpq.second.pt.dotlabel(2);
          -| First point lies on the perimeter of *this.
             First point lies outside e.
             Second point lies on the perimeter of *this.
             Second point lies outside e.
             Third intersection point is INVALID_POINT.
             Fourth intersection point is INVALID_POINT.
          


[Figure 171. Not displayed.]

Fig. 171.