Sunday, February 26, 2012

Bézier Curves - Programs for TI nSpire, HP 50g

Introduction

A short definition: a Bézier Curve is a set of parametric equations involving n points:

x(t)=Σ( nCr(n,k) * (1-t)^(n-k) * t^k * x_k) from k=0 to n

y(t)=Σ( nCr(n,k) * (1-t)^(n-k) * t^k * y_k) from k=0 to n

For 0 ≤ t ≤ 1

The curve fits points (x_0, y_0) (when t=0) and (x_n, y_n) (when t=1). The curve approximates the other points.

The degree of the polynomial is n-1.

Bézier curves are used heavily in computer graphics, animation, and font making.

Mike "Pomax" Kamermans provides an awesome primer on Bézier curves.


Béizer Curve Generator - TI nSpire CX
(I am sure this would work with the TI-89 too)

Define LibPub bezier(list)=
Func
© coordinates; Define x (or y)#(t)=bezier(...)
Local n,k
dim(list) - 1 → n
Return Σ( nCr(n,k) * (1-t)^(n-k) * t^k * list[k+1]) from k=0 to n
EndFunc


Save the file, the file name can only be one word. The file must belong to the MyLib folder under the My Documents folder. Please do not forget to refresh the libraries after saving. To refresh, press the doc button, select option 6.

One way to graph a Bézier Curve:

1. Go to, or create a graph screen, or in Scratchpad Graph screen
2. Set to Parametric Mode:

x#(t)=filename\bezier({x coordinates})

y#(t)=filename\bezier({y coordinates})

Set 0 ≤ t ≤ 1

Where # is 1 to 99 and filename is the file that contains the Bezier function.

Bézier Curve for the HP 50g (should work on the 48G and 49G families)

There are two programs in this section. Both are programmed using User RPL.

BEZIER: a curve generator
BEZGRPH: graphs a single Bézier Curve given a list of y coordinates and a list of corresponding x coordinates. BEZIER is required.

Bézier Curve Generator

Level 1: list of coordinates

Program Name: BEZIER
'L' STO
0 'F' STO
'T' PURGE
0 N FOR K
N K COMB
1 'T' - N K - ^ *
'T' K ^ *
L K 1 + GET *
'F' STO+
NEXT F SIMPLIFY FDISTRIB
{N L} PURGE >>


Graphing a Single Bézier Curve:

Level 2: list of y coordinates
Level 1: list of x coordinates

Program Name: BEZGRPH
BEZIER SWAP BEZIER
+ STEQ
PARAMETRIC
{T 0 1} INDEP
AUTO ERASE
DRAW LABEL DRAX PICTURE >>


Notes:
1. The program BEZIER is required.
2. Standard mode (STD) set is used to make labels less obtrusive
3. {T 0 1} INDEP sets T to be the independent variable with the range (0, 1)
Parametric Equations on the HP 50g: XY#(T)=X(T)+i*Y(T)

Example:
Draw a Bézier curve about the points (0,3), (1,2), (0,0), (-1,-1), and (4,-4)
List of y coordinates: {3, 2, 0, -1, -4}
List of x coordinates: {0, 1, 0, -1, 4}

Equations:
x(t) = 4t^4 + 8t^3 - 12t^2 + 4t
y(t) = -5t^4 + 8t^3 - 6t^2 - 4t + 3

TI nSpire CAS CX:

HP 50g:

Hope you enjoyed this blog. Take care as always, Eddie





This tutorial is property of Edward Shore. © 2012

Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode

Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode The Probability Simulation add-in has six type...