Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topics in Applied Mathematics Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.

Similar presentations


Presentation on theme: "Topics in Applied Mathematics Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada."— Presentation transcript:

1 Topics in Applied Mathematics Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2009 by Douglas Wilhelm Harder. All rights reserved. Best-Fitting Bezier Curves for Graphs of Functions

2 Best Fitting Bezier Curves 2 Outline This presentation looks at finding optimal Bezier curves –Background and definitions –Eight unknowns: Six constraints based on the functions and derivatives Two constraints based on minimizing the mean squared error –Ten examples of various functions

3 Best Fitting Bezier Curves 3 Background Bezier curves are used to model smooth space curves Often necessary to plot specific functions, including: –Circles –Exponential –Trigonometric functions We will define a technique for finding such curves and look at some examples

4 Best Fitting Bezier Curves 4 Mathematical Notation We will use standard mathematical notation to represent various values: –Variables are italicized lower-case characters t, x, y, a, b –Vectors are bold lower-case characters v k –Functions are roman lower-case characters f(t), x(t), y(t) –Derivatives are represented as superscripts f (1) (t)

5 Best Fitting Bezier Curves 5 Theory Given a vector space, a cubic Bezier curve is defined by four vectors v 1, v 2, v 3, v 4 and uses these to define a space curve parametrically v 1 (1 – t) 3 + v 2 t (1 – t) 2 + v 3 t 2 (1 – t) + v 4 t 3 with t varying from 0 to 1 We will use v k = (x k, y k )

6 Best Fitting Bezier Curves 6 Theory To find the best fitting Bezier curve for the graph of a function (x, f(x)) for x on an interval [a, b], introduce three constraints: v 1 = (a, f(a)) v 4 = (b, f(b)) We will also require that the derivatives match: f (1) (a) = (y 2 – y 1 )/(x 2 – x 1 ) f (1) (b) = (y 4 – y 3 )/(x 4 – x 3 ) where v k = (x k, y k ) T

7 Best Fitting Bezier Curves 7 Theory To deal with functions which have asymptotes in the derivative, to constrain the size, we will make one of two substitutions: –If |f (1) (a)| < 1, substitute y 2 = f(a) + f (1) (a) (x 2 – a), else substitute x 2 = (y 2 – f(a))/f (1) (a) + a –Similarly, if |f (1) (b)| < 1, substitute y 3 = f(b) + f (1) (b) (x 3 – b), else substitute x 3 = (y 3 – f(b))/f (1) (b) + b

8 Best Fitting Bezier Curves 8 Theory With these substitutions, we now have two Bezier curves with two unknown variables –These define the Bezier curve parametrically There are four cases for the substitutions: –If both derivatives are small, the two curves are x(t) = a(1 – t) 3 + x 2 t (1 – t) 2 + x 3 t 2 (1 – t) + bt 3 y(t) = f(a)(1 – t) 3 + [f(a) + f (1) (a) (x 2 – a) ]t (1 – t) 2 + [f(b) + f (1) (b) (x 3 – b)]t 2 (1 – t) + f(b)t 3 –If the derivative is large (or infinity) at the left point, use: x(t) = a(1 – t) 3 + [(y 2 – f(a))/f (1) (a) + a]t (1 – t) 2 + x 3 t 2 (1 – t) + bt 3 y(t) = f(a)(1 – t) 3 + y 2 t (1 – t) 2 + [f(b) + f (1) (b) (x 3 – b)]t 2 (1 – t) + f(b)t 3

9 Best Fitting Bezier Curves 9 Theory We must now define a function which must be minimized We will minimize the root mean-squared error: This is a real-valued bivariate function in the two unknown parameters Use techniques such as gradient descent to find the minimum Reasonable initial approximations are the midpoints: x k = (a + b)/2 y k = (f(a) + f(b))/2

10 Best Fitting Bezier Curves 10 Theory Why minimize the root mean squared error? –The error is a continuous and differentiable function in the parameters –Squaring emphasizes larger errors relative to smaller errors One could also minimize the infinity norm: Continuous, but not differentiable

11 Best Fitting Bezier Curves 11 Examples The following ten slides gives the best fitting Bezier curves for a number of functions on specific intervals –The function is plotted in red –The best fitting Bezier curve is plotted in blue behind the graph of the function The code was written in the Maple programming language The source code is available at http://ece.uwaterloo.ca/~dwharder/Maplesque/Bezier/

12 Best Fitting Bezier Curves 12 Examples The best fitting Bezier curve for the quarter circle is defined by the points (0, 1), (0.5520, 1), (1, 0.5520), (1, 0) with a root mean squared error of 0.000175

13 Best Fitting Bezier Curves 13 Examples The best fitting Bezier curve for the sin function on [0,  /2] is defined by the points (0, 0), (0.5251, 0.5251), (1.005, 1), (1.571, 1) with a root mean squared error of 0.000474

14 Best Fitting Bezier Curves 14 Examples The best fitting Bezier curve for the exponential function on [0, 1] is defined by the points (0, 1), (0.3765, 1.3765), (0.7057, 1.9184), (1, 2.7183) with a root mean squared error of 0.00000102

15 Best Fitting Bezier Curves 15 Examples The best fitting Bezier curve for the natural logarithm function on [1, 2] is defined by the points (0.5, -0.6931), (0.8043, -0.08448), (1.3010, 0.3437), (2, 0.6931) with a root mean squared error of 0.000238

16 Best Fitting Bezier Curves 16 Examples The best fitting Bezier curve for the quadratic function on [0, 1] is defined by the points (0, 0), (0.4174, 0), (0.7629, 0.5257), (1, 1) with a root mean squared error of 0.000118

17 Best Fitting Bezier Curves 17 Examples The best fitting Bezier curve for the square root function (quadratic inverse) on [0, 1] is defined by the points (0, 0), (0, 0.4182), (0.5274, 0.7637), (1, 1) with a root mean squared error of 0.000124

18 Best Fitting Bezier Curves 18 Examples The best fitting Bezier curve for the function f(x) = x 3/2 on [0, 1] is defined by the points (0, 0), (0.1804, 0), (0.5792, 0.3689), (1,1) with a root mean squared error of 0.00251

19 Best Fitting Bezier Curves 19 Examples The best fitting Bezier curve for the function f(x) = x ln(x) on [1, 10] is defined by the points (1, 0), (3.0993, 2.0993), (6.5721, 11.7052), (10., 23.0259) with a root mean squared error of 0.0202

20 Best Fitting Bezier Curves 20 Examples The best fitting Bezier curve for the standard normal curve on [0, 3] is defined by the points (0,1), (0.9235, 1), (0.1722, 0.002217), (3, 0.0001234) with a root mean squared error of 0.0490

21 Best Fitting Bezier Curves 21 Examples It is better to use two Bezier curves on [0, 1] and [1, 3] : (0, 0.5642), (0.3452, 0.5642), (0.6314, 0.3605), (1, 0.2076) (1, 0.2076), (1.5128, -0.005325), (1.8960, 0.0005308), (3, 0.00006963) with a root mean squared errors of 0.0000147 and 0.000227

22 Best Fitting Bezier Curves 22 Examples The best fitting Bezier curve for the sinc function ( sin(x)/x or the cardinal sine) on [0,  ] is defined by the points (0,1), (1.1339, 1), (2.0493, 0.3477), (3.1416, 0) with a root mean squared error of 0.000154

23 Best Fitting Bezier Curves 23 Summary This presentation looked at finding optimal Bezier curves for function graphs: –Six constraints are defined by the properties of the graph –Two are found by minimizing the root mean squared error The results are usually very good –The function x 1.5 resulted in the worst case –The smooth exponential function was best fit

24 Best Fitting Bezier Curves 24 Usage Notes These slides are made publicly available on the web for anyone to use If you choose to use them, or a part thereof, for a course at another institution, I ask only three things: –that you inform me that you are using the slides, –that you acknowledge my work, and –that you alert me of any mistakes which I made or changes which you make, and allow me the option of incorporating such changes (with an acknowledgment) in my set of slides Sincerely, Douglas Wilhelm Harder, MMath dwharder@alumni.uwaterloo.ca


Download ppt "Topics in Applied Mathematics Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada."

Similar presentations


Ads by Google