302 Chapter 8 Miscellaneous 2D Problems
// line than radius.
return 0;
}
if (tmp2 < epsilon) {
// One solution only
center[0].x = point.x-a*tmp1;
center[0].y = point.y-b*tmp1;
return 1;
}
// Otherwise, two solutions
tmp2 = Sqrt(tmp2);
Point2D tmpPt = { point.x-a*tmp1, point.y-b*tmp1 };
center[0] = { tmpPt+b*tmp2, tmpPt-a*tmp2 };
center[1] = { tmpPt-b*tmp2, tmpPt+a*tmp2 };
return 2;
}
8.8 Circles Tangent to Two Lines
with a Given Radius
Suppose we have two nonparallel lines L
0
and L
1
. A circle C with a given radius r can
be constructed so that it is tangent to both lines, as shown in Figure 8.14. Of course,
there are actually four such circles, as shown in Figure 8.15.
Given the two lines L
0
and L
1
, and the radius r, our problem is to find the circles’
centers C
0
, C
1
, C
2
, and C
3
. The insight here begins with the observation that each of
C
i
is at a distance r from both L
0
and L
1
.IfC
i
is to be at a distance r from L
0
, then
it must be somewhere on a line that is parallel to L
0
and is separated by a distance
r;ifC
i
is to be at a distance r from L
1
, then it must be somewhere on a line that is
parallel to L
1
and is separated by a distance r as well.
Thus, the circle center C
i
must be at the intersection of these two lines that are
parallel to, and at a distance r from, L
0
and L
1
, respectively, as shown in Figure 8.16
for one of the four circles. All four possible tangential circles are constructed by
considering all pairs of intersections between the two lines parallel to L
0
and the two
lines parallel to L
1
.
If the two lines are defined implicitly
L
0
: a
0
x +b
0
y +c
0
= 0
L
1
: a
1
x +b
1
y +c
1
= 0