0% found this document useful (0 votes)
24 views34 pages

8 Curve and Line

Uploaded by

squallf15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views34 pages

8 Curve and Line

Uploaded by

squallf15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

14012501-3

Computer Graphics

Lecture 8
Line Drawing Algorithm
Curve and Spline

1
Line
• A straight-line segment
is defined by the
coordinate positions for
the end points of the
segment.

2
Equation of line
• The Cartesian slope-
intercept equation for a
straight line is:
 y=mx+b
 m = (yend – y0)/(xend – x0)
 m = Δy / Δx
 b = y0 – m x0
Where
 m: slope of the line
 b: y-intercept
3
Solving by equation of line
 (x0, y0) = (20, 10)
 (xend, yend) = (30, 18)
 m = (yend – y0) / (xend – x0)
 m = (18 – 10) / (30 – 20) = 8/10 = 0.8
 b = y0 – m x0 = 10 – (0.8)(20) = 10 – 16 = – 6
 y=mx+b

k x y k x y
0 21 10.8 5 26 14.8
1 22 11.6 6 27 15.6
2 23 12.4 7 28 16.4
3 24 13.2 8 29 17.2
4 25 14 9 30 18

4
Examples

5
Cases of Positive Slope
• m = Δy / Δx
• Δx > Δy
 0<m<1
• Example (blue line)
 (5, 10) & (35, 20)
 m = 0.33
• Δx < Δy
 m >1
• Example (green line)
 (10, 5) & (20, 35)
 m=3

6
Slope

Blue is positive slope


Orange is negative slope
Green has a slope of zero
Light blue is undefined slope
7
Display line on a raster
monitor
• The graphics system project the endpoints
to integer screen coordinates and
determine the nearest pixel positions
along the line path between the two end
points.
• Video controller plots the screen pixels in
the specified color.

8
Stair-step effect (jaggies)
• Rounding of coordinate values to integers
causes horizontal and vertical lines to be
displayed with a stair-step appearance
("the jaggies").

9
Display line on a raster
monitor
• Algorithms for displaying straight lines are
based on the line equation.
• For any given x interval Δx along a line,
we can compute the corresponding y
interval Δy as
 Δy = m. Δx

10
Display line on a raster
monitor
• On raster systems, lines are plotted with
pixels, and step sizes in the horizontal and
vertical directions are constrained by pixel
separations.
• That is, we must "sample" a line at
discrete positions and determine the
nearest pixel to the line at each sampled
position.

11
Sampling
• Straight-line segment
with five sampling
positions along the x
axis between x0 and
xend.

12
Introduction
• Intuitively, think of a curve as something
you can draw with a pen
• The curve is the set of points that the pen
traces over an interval of time
• While we usually think of a pen writing on
paper (e.g., a curve that is in a 2D space),
the pen could move in 3D to generate a
space curve

13
Parametric Curve
• A parametric curve is controlled by a
single parameter that can be considered a
sort of index that moves continuously
along the curve
P0

P2
P1 degree = 2;
P(t) = (1 – t)2 P0 + 2t (1 - t)P1 + t2 P2 ; 0≤t≤1

14
Spline
• Spline is a piecewise polynomial function.
• Local properties of curves are attributed to
only a single location on the curve are:
 Continuity
 Position at a specific place on the curve
 Direction at a specific place on the curve
 Curvature (and other derivatives)

15
Continuity
• We call the condition that the curve pieces
fit together continuity conditions because if
they hold, the curve can be drawn as a
continuous piece.
• A breakpoint is where two curve segments
joint within a piecewise curve.
• The continuity of a curve at a breakpoint
describes how those curves joint at the
breakpoint
16
Continuity

C0 C1 C2 continuity
continuity continuity

17
Curve Fitting
• interpolating curve
 We want a curve that
passes through control
points.

• approximating curve
 Or a curve that passes
near control points.

18
Bézier Curve
• A Bézier curve is a parametric curve
frequently used in computer graphics.
• Linear Bézier curve is straight line.
• Quadratic and cubic Bézier curves are
most common.
• Higher degree curves are more
computationally expensive to evaluate.

19
Low Order Bézier Curves

P0 degree = 1; (Linear Bezier curve)


P(t) = (1 - t) P0 + t P1 ; 0≤t≤1
P1

P0

P2
P1 degree = 2; (Quadratic Bezier curve)
P(t) = (1 – t)2 P0 + 2t (1 - t)P1 + t2 P2 ; 0≤t≤1

20
Cubic Bézier Curve
degree = 3; (Cubic Bezier curve)
P(t) = (1 – t)3 P0 + 3t (1 – t)2 P1 + 3t2 (1 – t)P2 +t3P3; 0≤t≤1

P2 P1
P1

P0
P3

P0
P3

P2
21
Computation of Parameters

• If a Bézier curve consist of (n+1) points


between the first and last points inclusive
• Then interval between two consecutive
points is ∆ = 1/n
• The value of parameter t varies between 0
and 1 inclusive
• The (n+1) values of t are computed as
 i = 0, 1, 2,…n
 ti = i * ∆
22
Computation of Parameters
• n+1 = 5
• n=5–1=4
• ∆ = 1/n = 1/4 = 0.25
• i = 0, 1, 2,…4
 ti = i * ∆
 t0 = 0 * 0.25 = 0
 t1 = 1 * 0.25 = 0.25
 t2 = 2 * 0.25 = 0.5
 t3 = 3 * 0.25 = 0.75
 t4 = 4 * 0.25 = 1.0
23
Computation of Bézier Curve

• The Bézier curve is evaluated at each


value of parameter t
• Example for linear Bézier curve
 P0 = (292, 196), P1 = (356, 148)
 Then at t= 0.5
 P(t) = (1 - t) P0 + t P1
 P(t) = (1 – 0.5) (292, 196) + 0. 5 (356, 148)
 P(t) = (324, 172)

24
Example:
Linear Bézier Curve
P0 = (292,196), P1 = (356,148)
2D Linear Bezier Curve
t Px(t) Py(t) 200
0 292.00 196.00 Bezier Curve
Sample Points
0.10 298.40 191.20
190 Control Points
0.20 304.80 186.40
0.30 311.20 181.60
180
0.40 317.60 176.80
0.50 324.00 172.00
170
0.60 330.40 167.20
0.70 336.80 162.40
160
0.80 343.20 157.60
0.90 349.60 152.80
1.00 356.00 148.00 150

140
290 300 310 320 330 340 350 360

25
Example:
Quadratic Bézier Curve
P0 = (292,196), P1 = (280,153), P2 = (356,148)
2D Quadratic Bezier Curve
t Px(t) Py(t) 200
0 292.00 196.00 Bezier Curve
Sample Points
0.10 290.48 187.78 190 Control Points
0.20 290.72 180.32 Control Polygon

0.30 292.72 173.62


180
0.40 296.48 167.68
0.50 302.00 162.50
170
0.60 309.28 158.08
0.70 318.32 154.42
160
0.80 329.12 151.52
0.90 341.68 149.38
150
1.00 356.00 148.00

140
280 290 300 310 320 330 340 350 360

26
Example:
Cubic Bézier Curve
P0 = (292,196), P1 = (280,153), P2 = (321,140), P3 = (356,148)
2D Cubic Bezier Curve
t Px(t) Py(t) 200
Bezier Curve
0 292.00 196.00 Sample Points
0.10 289.93 183.99 190 Control Points
Control Polygon
0.20 290.69 173.73
0.30 293.92 165.16 180
0.40 299.26 158.22
0.50 306.38 152.88 170
0.60 314.90 149.06
0.70 324.47 146.71
160
0.80 334.75 145.79
0.90 345.38 146.24
150
1.00 356.00 148.00

140
280 290 300 310 320 330 340 350 360

27
Interpolated Data
linear, quadratic, cubic
Bézier Curves
P0 = (292,196), P1 = (280,153), P0 = (292,196), P1 = (280,153),
P0 = (292,196), P1 = (356,148)
P2 = (356,148) P2 = (321,140), P3 = (356,148)
t Px(t) Py(t) t Px(t) Py(t) t Px(t) Py(t)
0 292.00 196.00 0 292.00 196.00 0 292.00 196.00
0.10 298.40 191.20 0.10 290.48 187.78 0.10 289.93 183.99
0.20 304.80 186.40 0.20 290.72 180.32 0.20 290.69 173.73
0.30 311.20 181.60 0.30 292.72 173.62 0.30 293.92 165.16
0.40 317.60 176.80 0.40 296.48 167.68 0.40 299.26 158.22
0.50 324.00 172.00 0.50 302.00 162.50 0.50 306.38 152.88
0.60 330.40 167.20 0.60 309.28 158.08 0.60 314.90 149.06
0.70 336.80 162.40 0.70 318.32 154.42 0.70 324.47 146.71
0.80 343.20 157.60 0.80 329.12 151.52 0.80 334.75 145.79
0.90 349.60 152.80 0.90 341.68 149.38 0.90 345.38 146.24
1.00 356.00 148.00 1.00 356.00 148.00 1.00 356.00 148.00

28
Interpolated Curves
linear, quadratic, cubic
Bézier Curves

29
Example:
3D Cubic Bézier Curve
P0 = (292, 196, -56) P1 = (280, 153, 75)
P2 = (321, 140, 140) P3 = (356, 148, 248)

t Px(t) Py(t) Pz(t) 3D Cubic Bezier Curve Bezier Curve


Bezier Curve
0 292.00 196.00 -56.00 Control Points

0.10 289.93 183.99 -18.57 300


Control Polygon

0.20 290.69 173.73 15.55


200
0.30 293.92 165.16 47.02
0.40 299.26 158.22 76.50 100

0.50 306.38 152.88 104.63 0

0.60 314.90 149.06 132.06


-100
0.70 324.47 146.71 159.47 200
360
180
0.80 334.75 145.79 187.49 340
160 320
0.90 345.38 146.24 216.78 300
140 280
1.00 356.00 148.00 248.00

30
Connected Cubic Bézier Curves

• First Segment • Second Segment

• P0=[392 196 -56]; • P0=[356 200 148];


• P1=[280 153 -75]; • P1=[400 250 153];
• P2=[321 140 10]; • P2=[300 320 40];
• P3=[356 200 148]; • P3=[250 260 -148];

31
Connected Cubic Bézier Curves
3D Connected Cubic Bezier Curves

200 Bezier Curve


Bezier Curve
150
Control Points
100 Control Polygon

50

-50

-100

-150
400

350

300

150 100
250 250 200
350 300

32
References
• Fundamentals of Computer Graphics by
Peter Shirley
• Computer Graphics with OpenGL, Hearn
& Baker, Prentice Hall
• https://en.wikipedia.org/

33
Disclaimer & Fair Use Statement
• This work may contain copyrighted material, the use of which may
not have been specifically authorized by the copyright owner. This
material is available for education purpose under ‘fair use’.
• If you wish to use any copyrighted material from this work for
purposes of your own that go beyond ‘fair use’, you must obtain
expressed permission from the copyright owner.

34

You might also like