Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!utah-cs!utah-gr!thomas From: thomas@utah-gr.UUCP (Spencer W. Thomas) Newsgroups: comp.graphics Subject: Re: Algorithm needed: 2-D arc to Bezier conversion Message-ID: <1879@utah-gr.UUCP> Date: Mon, 29-Dec-86 13:51:47 EST Article-I.D.: utah-gr.1879 Posted: Mon Dec 29 13:51:47 1986 Date-Received: Mon, 29-Dec-86 21:48:50 EST References: <252@acornrc.UUCP> Reply-To: thomas@utah-gr.UUCP (Spencer W. Thomas) Organization: University of Utah CS Dept Lines: 58 Keywords: arc, Bezier, conic section First, you can't reproduce a conic section exactly with a normal Bezier curve. If, however, you are willing to use a rational representation, you can. The rational representation gives each control point a weight; the easiest way to do this is to use homogeneous coordinates. E.g., if your (2-D homogeneous) control points are ( x_i, y_i, h_i ), then the x coordinate of the resulting curve would be x(t) = sum_i( x_i * B_i(t) ) / sum_i( h_i * B_i(t) ) Given this representation, it is easy to construct an arbitrary conic. A common conic construction method starts with three points, A, B, and C, and a parameter l. The curve starts at A, tangent to the line AB, and ends at C, tangent to the line BC. It passes through a point on the line segment connecting B to the midpoint of AC determined by the parameter l. Mathematically, define D = (A + C) / 2 E = l * B + (1 - l) * D The curve passes through the point E. The shape of the curve is determined by the parameter l as follows: 0.5 < l < 1 hyperbola 0.5 = l parabola 0 < l < 0.5 ellipse To construct a rational Bezier curve for this conic, set the weights for A and C to 1, and for B to w = l / (1 - l). Thus, if B has the Euclidean coordinates (b_x, b_y), it will be (b_x * w, b_y * w, w) as a homogeneous point. To make a circular arc, you want |AB| = |BC| and set w to the cosine of half the angle between AB and BC. (Take the dot product of the vector AB with (AB + BC) / 2 and divide by the lengths of these two vectors.) Note that you cannot get a uniform (or arclength) parametrization of the circle, since this would amount to writing sine and cosine as rational polynomials (clearly impossible). For a 90 degree arc, this Bezier curve differs from an arclength parametrization by at most about 5%. (However, the curve as a whole does exactly reproduce the circular arc.) Here is an example. To make a 30 degree circular arc of unit radius, centered at the origin, counterclockwise from the point (1,0): A = (1,0) C = (sqrt(3)/2, 1/2) B is at the intersection of the tangents at A and C B = (1, tan(15deg)) The half angle is 15 degrees, so w = cos(15deg) Thus, we have, finally P_0 = (1, 0, 1) P_1 = (cos(15), sin(15), cos(15)) P_2 = (sqrt(3)/2, 1/2, 1) and the curve is c(t) = P_0*B_0(t) + P_1*B_1(t) + P_2 * B_2(t) -- =Spencer ({ihnp4,decvax}!utah-cs!thomas, thomas@cs.utah.edu)