Exploring Analyic Geometry with Mathematica® |
|||||
| Home | Contents | Commands | Packages | Explorations | Reference |
| Tour | Lines | Circles | Conics | Analysis | Tangents |
Biarcs
Biarc Carrier Circles
Knot Point
Knot Circles
Biarc Programming Examples
Explorations
In this chapter we will demonstrate some techniques for adding new functions to Descarta2D. To make the demonstration realistic, we will introduce the mathematics for a new type of tangent circle construction called a biarc. Biarcs are used in some graphical computer systems to connect a set of data points with smoothly joined arcs. The mathematics of biarcs is by itself interesting and will serve as a good example of extending the capabilities of Descarta2D.
Initialize
To initialize Descarta2D, select the input cell bracket and press SHIFT-Enter.
This initialization assumes that the Descarta2D software has been copied into one of the standard directories for AddOns which are on the Mathematica search path, $Path.
<<Descarta2D`
Biarc Carrier Circles [Top]
A biarc is a composite curve consisting of two circular arcs, placed end to end with continuity of slope at the join point. The two circles underlying the arc are called the biarc carrier circles. The carrier circles may be internally or externally tangent to each other, and the point of tangency that joins the two arcs is called the knot point of the biarc. Referring to Figure [biarc:fig01], suppose we wish to construct a smooth curve between points
and
such that the tangents to the curve at
and
are the unit vectors
and
.
,
,
and
are called the biarc configuration parameters.
Biarc configuration parameters.
The geometric condition that two circles are tangent can always be expressed as
sum or difference of radii=distance between the centers
according to the kind of contact, external (sum of radii) or internal (difference of radii).
We take positive values of
and
to indicate that the center points of the carrier circles,
and
, are offset in the direction of
and
, respectively.
and
are unit vectors constructed by rotating tangent vectors
and
counter-clockwise. Suppose we now wish to form an expression for the left-hand side of Equation ([biarc:eqn01]). It can be shown that the expressions
and
represent all cases for the sum (squared) and difference (squared) of the biarc radii for all combinations of positive or negative
and
for both internally and externally tangent carrier circles.
We introduce a radius sign constant,
, which may take on the values ±1, in order to accommodate internally or externally tangent carrier circles in the same equation,
Note that it makes no difference whether we associate
with
or
, since after squaring and applying
, the relationship is symmetric,
The carrier circle center points,
and
, may be written as
Combining Equations ([biarc:eqn02]) and ([biarc:eqn03]) as suggested by Equation ([biarc:eqn01]), the sum or difference of the radii (squared) equals the distance (squared) between
and
, yields
When simplifying Equation ([biarc:eqn04]), note that the relationships
and
can be used, since
and
are defined as unit vectors. Rearranging Equation ([biarc:eqn04]) and using the following substitutions
![]()
=
![]()
![]()
=
![]()
![]()
=
![]()
![]()
=
![]()
produces the equation
which establishes the general relationship between the radii,
and
, of the carrier circles. Constants
,
,
and d are referred to as the biarc defining constants. Geometrically,
is the cosine of the angle between the tangent vectors,
is the (signed) distance from
to the line defined by
and
,
is the (signed) distance from
to the line defined by
and
and
is the distance (squared) between points
and
. Note that these defining constants depend only on the relative position of the defining geometry and are independent of the choice of coordinate axes.
Radii Ratio
If a relationship between the carrier circle radii,
and
, is specified, then Equation ([biarc:eqn05]) can be solved for the radii. We choose to specify the biarc radii ratio,
, as the defining relationship. Substituting
into Equation ([biarc:eqn05]) produces the equation
Solving Equation ([biarc:eqn06]) by using the quadratic formula yields
In the special case where the tangent vectors are in the same direction, the denominator
will equal zero, and the quadratic equation degenerates and the solution of the resulting linear equation is
Thus, by specifying a biarc radii ratio, κ, and applying Equation ([biarc:eqn07]) or ([biarc:eqn08]) we may calculate values for
and
. Equation ([biarc:eqn03]) allows us to calculate the corresponding coordinates of the carrier circle centers,
and
. In certain configurations only one arc is needed to satisfy the position and tangent constraints. In this case, the equations will produce centers and radii for two identical circles.
Number of Solutions
Given a specific pair of points,
and
and tangent vectors,
and
, we now consider how many different carrier circle pairs exist for a given radii ratio, κ. The solutions may be enumerated as follows:
• Equations ([biarc:eqn07]) or ([biarc:eqn08]) may produce negative values for
or
. The sign indicates the directions the center points
and
should be offset from
and
, respectively. As a result, both κ and -κ may produce valid biarcs with a specified radii ratio.
• The radius sign constant,
, may take on two different values, ±1.
• The quadratic formula yields two different solutions due to the sign preceding the radical sign as shown in Equation ([biarc:eqn07]).
Therefore, as many as 2×2×2=8 unique carrier circle pairs may exist for a given biarc configuration and radii ratio.
Knot Point [Top]
Suppose we wish to compute the coordinates of the knot point,
, which is the point of tangency between the two carrier circles. The coordinates of the knot point can be found by intersecting the two circles and taking advantage of the fact that they intersect in a single point yielding
where
![]()
=
![]()
R
=
![]()
While it is a simple matter to compute the knot point once we have the two carrier circles, we might instead want to specify the position of the knot point. We will show in this section that the knot point cannot be selected arbitrarily, but must lie on one of two specific circles, called the knot circles. The following theorem and corollary from elementary geometry (which are stated without proof) will be central to exploring the nature of the knot circles.
Theorem. Angles at the circumference of a circle subtended by the same arc are equal.
Corollary. Given two fixed points
and
and a variable point Q, the locus of Q is a circle if
is a constant.
Knot point angles.
Consider two internally tangent carrier circles centered at
and
and with radii
and
, respectively, as shown in Figure [biarc:fig10]. By construction the two circles are internally tangent at the origin. Pick two arbitrary points
and
on the circles with coordinates
We will show that the angle
is a constant angle for all such points
and
when the angle ω is constant, and, having established this fact, we will apply the corollary stated above to establish that the knot point must be on one of two circles.
The slopes of lines
and
,
and
, are given by
![]()
=
![]()
![]()
=
![]()
and the angle, α, between
and
is
tanα
=
![]()
.
=

.
=
![]()
.
=

The angle ω between the two tangent lines
and
is given by
![]()
=
ω (or π-ω)
![]()
=
ω (or π-ω)
![]()
=
ω (or π-ω).
Notice that since ω is a constant, by definition, for any given biarc configuration,
is also a constant. Since α is a function of
it must also be a constant. Now applying the corollary, the knot point must be on one of two circles corresponding to the two constant values of α. Similar proofs hold for other geometric configurations and also for externally tangent circles.
Knot Circles [Top]
Knot circles.
In the previous section it was established that all the valid knot points for a given biarc configuration must lie on either of two circles. These two circles can be constructed geometrically by considering the limiting cases of the carrier circle radii,
and
, as shown in Figure [biarc:fig11]. First, notice that the tangency points
and
must be on the knot circles because they correspond to the knot point in the trivial cases when
and
. Now imagine a circle anchored at
, tangent to line
, and increasing in radius from zero. At some value of
, the circle will become tangent to line
at the point labeled
(or
, if the circle is on the opposite side of
). At this value of
,
will be infinite and the second biarc circle will become a line. The three points
,
and
determine the first knot circle, and
,
, and
determine the second knot circle.
Since the construction is symmetrical, we could have increased the radius of the second carrier circle,
, from zero and found points
and
which are on the same two knot circles as those defined by
and
.
The center points of the knot circles can be constructed by intersecting the perpendicular bisector of
with the angle bisectors of lines
and
. Using simple trigonometric relationships it can be shown that the radii of the two knot circles, r' and r'', are given by
where d is the distance between
and
and ω is the angle between
and
.
Biarc Programming Examples [Top]
Descarta2D does not provide built-in functions for computing biarcs directly, so we will use the facilities available in Descarta2D along with the programming capabilities provided by Mathematica to demonstrate how new functions can be added to Descarta2D. In order to keep the examples simple, we will ignore special cases and possible error conditions. Better implementations would check for special cases and report errors in the input arguments when such errors are detected.
Knot Circles
The first example illustrates a Mathematica function that will return a list of two knot circles given a biarc configuration (tangent points and tangent lines). For simplicity we will use a triangle to define the biarc configuration with the implicit understanding that the first and third vertices of the triangle,
and
, are the tangent points,
and
, and sides
and
of the triangle are the tangent lines,
and
. Using a triangle as an input parameter has the added advantage that many invalid cases are avoided because they would involve invalid triangles.
(*1*) KnotCircles2D[t1:Triangle2D[p1:{x1_,y1_},
(*2*) pA:{xA_,yA_},
(*3*) p2:{x2_,y2_}]] :=
(*4*) Module[{pt1,pt2},
(*5*) pt1=Point2D[t1,Inscribed2D];
(*6*) pt2=Point2D[Point2D[pA],Point2D[p1],
(*7*) -Distance2D[p2,pA]];
(*8*) Map[Circle2D[Point2D[p1],Point2D[p2],#]&,
(*9*) {pt1,pt2}] ];
Lines 1, 2 and 3 define a Mathematica function called KnotCircles2D that takes one parameter that is required to pattern match a Descarta2D triangle object. Line 4 opens a Module statement that defines two local variables pt1 and pt2. Line 5 constructs a point at the center of a circle inscribed in the triangle. Line 6 constructs a point offset from the apex point, pA, to the tangency point, p1, a negative distance defined by p2 and pA. Lines 8 and 9 construct two circles from the two tangency points and a third point, pt1 or pt2.
Example: Construct the two knot circles associated with the triangle whose vertices are (0,0), (2,1) and (3,0). Plot the geometric objects.
Solution: The function KnotCircles2D[triangle], defined above, returns a list of two knot circles associated with a triangle.
t1=Triangle2D[p1=Point2D[{0,0}],
p2=Point2D[{2,1}],
p3=Point2D[{3,0}]];
kc=KnotCircles2D[t1] //N
Sketch2D[{p1,p2,p3,t1,kc,Point2D[t1,Inscribed2D]}]
■
Descarta2D Hint: In the KnotCircles2D function whose implementation is shown above, the third point on the second knot circle is constructed following the technique described earlier in the chapter. However, the third point of the first knot circle is constructed as the center of the circle inscribed in the triangle. The exploration knotin.html at the end of the chapter shows that this point is actually on the first knot circle. Using this point has the added advantage that it avoids an error condition that would otherwise occur when
and
are equidistant from the third point of the triangle (an isosceles biarc configuration).
Arc Construction
In this section we will implement functions for constructing bulge factor arcs given defining points and tangent vectors. These will be used later to construct biarcs. First, we define a utility function, Cross2D, that computes a vector cross-product in two dimensions.
Cross2D[{u1_,v1_},{u2_,v2_}]:=u1*v2-u2*v1;
Now we define an arc construction function that takes the arc's start and end points,
and
, as input, plus a point associated with the start point indicating the direction of the tangent to the arc at the start point. The justification for this function is provided in the exploration arcentry.html.
Arc2D[{Point2D[p0:{x0_,y0_}],Point2D[p:{x_,y_}]},
Point2D[p1:{x1_,y1_}]]:=
Module[{v0=p-p0,chd=p1-p0,s,c},
s=Cross2D[v0,chd];
c=Dot[v0,chd];
Arc2D[p0,p1,s/(c+Sqrt[c^2+s^2])] ];
The next arc construction function is similar to the previous one, except the point indicating the tangent direction is associated with the end point of the arc. The justification for this function is provided in the exploration arcexit.html.
Arc2D[Point2D[p0:{x0_,y0_}],
{Point2D[p1:{x1_,y1_}],Point2D[p:{x_,y_}]}]:=
Module[{v1=p-p1,chd=p1-p0,s,c},
s=Cross2D[chd,v1];
c=Dot[chd,v1];
Arc2D[p0,p1,s/(c+Sqrt[c^2+s^2])] ];
Knot Points
Now that we have functions for computing knot circles and constructing arcs involving tangent vectors, it is fairly easy to construct biarcs. Consider the following Mathematica function:
(*1*) Biarc2D[t1:Triangle2D[p0:{x0_,y0_},
(*2*) pA:{xA_,yA_},
(*3*) p1:{x1_,y1_}],
(*4*) ptK:Point2D[{xk_,yk_}]] :=
(*5*) {Arc2D[{Point2D[p0],Point2D[pA]},ptK],
(*6*) Arc2D[{Point2D[p1],Point2D[pA]},ptK]};
The function Biarc2D takes two arguments, a Descarta2D triangle object defining the biarc configuration (lines 1-3), and a Descarta2D point object defining the knot point (line 4). The function Arc2D[{point,point},point], defined in the previous section, is used twice to actually construct the biarc which is returned as a list of two arcs (lines 5-6).
Example: Construct the biarc associated with the triangle whose vertices are (0,0), (2,1) and (3,0) and a knot point on the first knot circle at parameter value π/2. Plot the geometric objects.
Solution: The function Biarc2D[triangle,point] described above returns a list of two arcs (a biarc) given a triangle that defines the biarc configuration and the knot point.
t1=Triangle2D[p1=Point2D[{0,0}],
p2=Point2D[{2,1}],
p3=Point2D[{3,0}]];
kc=KnotCircles2D[t1] //N;
bi1=Biarc2D[t1,pk=Point2D[kc[[1]][Pi/2]]] //N
Sketch2D[{p1,p2,p3,t1,pk,bi1}]
■
Descarta2D Hint: The Biarc2D function does not check to insure that the knot point provided is a valid knot point. It will erroneously return two arcs that are not tangent to each other if it is called with a point not on one of the knot circles. Other errors will occur if the knot point coincides with one of the triangle vertices.
It would be convenient if the biarc construction function computed the knot point internally as shown in the following Mathematica function:
(*1*) Biarc2D[t1:Triangle2D[p0:{x0_,y0_},
(*2*) pA:{xA_,yA_},
(*3*) p1:{x1_,y1_}],
(*4*) knotCircleNumber_Integer,
(*5*) knotPointParameter_?IsScalar2D] :=
(*6*) Module[{kc,ptK},
(*7*) kc=KnotCircles2D[t1][[knotCircleNumber]];
(*8*) ptK=Point2D[kc[knotPointParameter]] //N;
(*9*) Biarc2D[t1,ptK] ];
This Biarc2D function takes three arguments, the first being a triangle defining the biarc configuration, the second an integer equal to 1 or 2 specifying which biarc circle the knot point should be on, and the third an angle (in radians) specifying the parameter location on the knot circle for the desired knot point. Lines 1-5 define the function arguments, line 7 computes the knot circle, line 8 computes the knot point, and line 9 computes the biarc.
Example: Construct the biarc associated with the triangle whose vertices are (0,0), (2,1) and (3,0) and a knot point on the first knot circle at parameter value π/2.
Solution: The function
Biarc2D[triangle,knotCircleNumber,knotCircleParameter]
as implemented above returns the required biarc.
t1=Triangle2D[p1=Point2D[{0,0}],
p2=Point2D[{2,1}],
p3=Point2D[{3,0}]];
bi1=Biarc2D[t1,1,Pi/2] //N
■
The Biarc2D functions implemented above are restrictive in the sense that the tangent vectors always point toward the apex point of the triangle and no provision is available to allow either (or both) of the tangent vectors to point away from the apex. In order to overcome this restriction we will implement a function that takes two line segments to define the biarc configuration. The line segments will define a position (the start point of the line segment) and a direction (from the start point towards the end point).
(*1*) Biarc2D[Segment2D[p0:{x0_,y0_},d0:{u0_,v0_}],
(*2*) Segment2D[p1:{x1_,y1_},d1:{u1_,v1_}],
(*3*) ptK:Point2D[{xk_,yk_}]] :=
(*4*) {Arc2D[{Point2D[p0],Point2D[d0]},ptK],
(*5*) Arc2D[ptK,{Point2D[p1],Point2D[d1]}]};
(*1*) Biarc2D[L0:Segment2D[p0:{x0_,y0_},d0:{u0_,v0_}],
(*2*) L1:Segment2D[p1:{x1_,y1_},d1:{u1_,v1_}],
(*3*) knotCircleNumber_Integer,
(*4*) knotCircleParameter_?IsScalar2D] :=
(*5*) Module[{ptA,t1,kc,ptK},
(*6*) ptA=Point2D[Line2D[L0],Line2D[L1]];
(*7*) t1=Triangle2D[p0,Coordinates2D[ptA],p1];
(*8*) kc=KnotCircles2D[t1][[knotCircleNumber]];
(*9*) ptK=Point2D[kc[knotCircleParameter]];
(*10*) Biarc2D[L0,L1,ptK] ];
These Biarc2D functions are parallel implementations of the previous two, except two line segments are used to define the biarc configuration instead of a triangle.
Example: Given a biarc configuration defined by the line segments from (0,0) to (-3,2) and from (3,0) to (4,-2) construct a set of biarcs whose knot points are on knot circle 1 at parameter values π/3, π/2 and 2π/3.
Solution: Use the function Biarc2D whose implementation is provided above.
ls0=Segment2D[{0,0},{-3,2}] //N;
ls1=Segment2D[{3,0},{4,-2}] //N;
bi1=Map[(Biarc2D[ls0,ls1,1,#] //N)&,{Pi/6,Pi/2,5Pi/6}];
Map[(Print[Sketch2D[{ls0,ls1,#}]])&,bi1];
■
Building on these basic Mathematica programs for computing biarcs, more elaborate construction functions could be provided. For example, we might write a function that attempts to automatically select the knot point based on some minimization criteria; or we might attempt to construct biarcs that have no reversal of curvature at the knot point (i.e. the carrier circles are internally tangent to each other). Another interesting exercise is to devise a strategy for connecting a predefined set of points with a smooth, piecewise curve consisting of biarcs.
Explorations [Top]
Incenter on Knot Circle. [knotin.html]
Show that the incenter of a triangle (the center point of the circle inscribed in the triangle) is on one of the knot circles for the biarc configuration defined by the triangle.