Cs3241 Lab9
-
Upload
edison-tsui -
Category
Technology
-
view
395 -
download
3
Transcript of Cs3241 Lab9
Bézier curve
CS3241 Lab9
Bézier curve
Implementing Bézier curve using OpenGL
Recall L8, p34 Bézier Blending function
Bézier curve Trick: Generate n sample points
For n evenly distributed sample point in [0, 1] t = i/(n-1) (for i = 0….n-1)
Find B1[i], B2[i], B3[i], B4[i]
Sample point [x, y] = [ B1[i], B2[i], B3[i], B4[i] ] [P0, P1, P2, P3]T
Connect the dots!
Sample Point 0
t = 0
Bh1[0] = 1
Bh2[0] = 0
Bh3[0] = 0
Bh4[0] = 0
Sample Point n-1
t = 1
Bh1[n-1] = 0
Bh2[n-1] = 0
Bh3[n-1] = 0
Bh4[n-1] = 1
Sample Point i
t = i/(n-1)
Bh1[i] = (1-t)^3
Bh2[i] = 3(1-t)^2*t
Bh3[i] = 3(1-t)*t^2
Bh4[i] = t^3
x = Bh1[i]*p0.x + Bh2[i]*p1.x
+ Bh3[i]*p2.x + Bh4[i]*p3.x
y = ….
ti
Bézier curve
Task 1
Open bezierUI_todo.c
Implement Bézier curve after 4 control points
(constraint) are fixed
Please modify
computeBlendingBh – pre-compute Bh1..4 according to
func in Slide 2
drawCurve – find out the co-ordinate of sample point by
x = Bh1[i]*q.p[0].x + Bh2[i]*q.p[1].x + Bh3[i]*q.p[2].x + Bh4[i]*q.p[3].x;
y = Bh1[i]*q.p[0].y + Bh2[i]*q.p[1].y + Bh3[i]*q.p[2].y + Bh4[i]*q.p[3].y;
Bézier curve
Build-in in OpenGL
One-Dimensional Evaluators
Ch 12, Red book
Reference
http://www.glprogramming.com/red/chapter12.htm
l
http://en.wikipedia.org/wiki/B%C3%A9zier_curve