Linear Interpolation Applying “weighted averages” to some graphics problems: animations and curve-drawing.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

Scan conversion of Line , circle & ellipse
CMPE 466 COMPUTER GRAPHICS
Lecture Notes #11 Curves and Surfaces II
Vector Calculus Mengxia Zhu Fall Objective Review vector arithmetic Distinguish points and vectors Relate geometric concepts to their algebraic.
BEZIER CURVES Part II. Assume we are given two endpoints labelled E1 and E2 and two control points labelled C1 and C2. create a smooth curve whose endpoints.
© University of Wisconsin, CS559 Spring 2004
Informationsteknologi Monday, December 10, 2007Computer Graphics - Class 161 Today’s class Curve fitting Evaluators Surfaces.
Surfaces Chiew-Lan Tai. Surfaces 2 Reading Required Hills Section Hearn & Baker, sections 8.11, 8.13 Recommended Sections 2.1.4, , 3D Computer.
Modelling. Outline  Modelling methods  Editing models – adding detail  Polygonal models  Representing curves  Patched surfaces.
A code-walkthrough Commentary on our ‘model3d.cpp’ demo-program – an initial ‘prototype’ for 3D wire-frame animations.
Modelling: Curves Week 11, Wed Mar 23
Computer Graphics (Fall 2005) COMS 4160, Lecture 7: Curves 2
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Curves Week 13, Mon 24 Nov 2003.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
Chapter 5 Linear Inequalities and Linear Programming Section 2 Systems of Linear Inequalities in Two Variables.
Econ 482 Lecture 1 I. Administration: Introduction Syllabus Thursday, Jan 16 th, “Lab” class is from 5-6pm in Savery 117 II. Material: Start of Statistical.
Chapter 5.1 Systems of linear inequalities in two variables.
Splines III – Bézier Curves
© Pearson Education Canada, 2003 GRAPHS IN ECONOMICS 1 APPENDIX.
Curve Modeling Bézier Curves
0.1 Functions and Their Graphs. Real Numbers A set is a collection of objects. The real numbers represent the set of numbers that can be represented as.
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 2 Graphs and Functions Copyright © 2013, 2009, 2005 Pearson Education, Inc.
19/13/ :20 UML Graphics II Parametric Curves and Surfaces Session 3.
Subdivision/Refinement Dr. S.M. Malaek Assistant: M. Younesi.
A D V A N C E D C O M P U T E R G R A P H I C S CMSC 635 January 15, 2013 Spline curves 1/23 Curves and Surfaces.
CS 376 Introduction to Computer Graphics 04 / 23 / 2007 Instructor: Michael Eckmann.
Midpoint and Distance Formulas Goal 1 Find the Midpoint of a Segment Goal 2 Find the Distance Between Two Points on a Coordinate Plane 12.6.
V. Space Curves Types of curves Explicit Implicit Parametric.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
FUNCTIONS AND GRAPHS.
1 Dr. Scott Schaefer Smooth Curves. 2/109 Smooth Curves Interpolation  Interpolation through Linear Algebra  Lagrange interpolation Bezier curves B-spline.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Quadratic Surfaces. SPLINE REPRESENTATIONS a spline is a flexible strip used to produce a smooth curve through a designated set of points. We.
Curves. First of all… You may ask yourselves “What did those papers have to do with computer graphics?” –Valid question Answer: I thought they were cool,
Linear Inequalities and Linear Programming Chapter 5 Dr.Hayk Melikyan Department of Mathematics and CS
1 CS 430/536 Computer Graphics I Curve Drawing Algorithms Week 4, Lecture 8 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Vectors Part II Application of Linear Combination.
Splines IV – B-spline Curves based on: Michael Gleicher: Curves, chapter 15 in Fundamentals of Computer Graphics, 3 rd ed. (Shirley & Marschner) Slides.
Fall 2004CS-321 Dr. Mark L. Hornick 1 Final Exam Monday Nov 13, 2-4pm CC-43 Bring Calculator – no laptops Note sheet Complete FAST entries before exam.
CE 221 Data Structures and Algorithms Chapter 4: Trees (Binary) Text: Read Weiss, §4.1 – 4.2 1Izmir University of Economics.
Coordinate Systems and Coordinate Frames  vector v = (3, 2, 7)  point P = (5, 3, 1)  coordinate frame consists of a specific point, V, called the origin,
1Barnett/Ziegler/Byleen Finite Mathematics 12e Learning Objectives for Section 5.2  The student will be able to solve systems of linear inequalities graphically.
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS Representation of Curves and Surfaces Graphics.
In the name of God Computer Graphics Bastanfard. Curve Function(2) Other method is approximate it using a poly-line. Just locate a set of points along.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
CSCE 441: Keyframe Animation/Smooth Curves (Cont.) Jinxiang Chai.
CS 318 Intro to Computer Graphics John C. Hart
Basic Theory (for curve 01). 1.1 Points and Vectors  Real life methods for constructing curves and surfaces often start with points and vectors, which.
Curves University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner.
Piecewise Polynomial Parametric Curves Sun-Jeong Kim.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Vector 2.
Computer Graphics Lecture 38
Parametric Curves cgvr.korea.ac.kr.
Chapter 5 Linear Inequalities and Linear Programming
Solving Compound Inequalities
Copyright © Cengage Learning. All rights reserved.
CSE 167 [Win 17], Lecture 9: Curves 1 Ravi Ramamoorthi
Basic Graphing Techniques
Chapter 4-5 Systems of linear inequalities in two variables.
Inequalities in Two Variables
Diffusion Curves Dr. Scott Schaefer.
Primitive Drawing Algorithm
Computer Aided Geometric Design
Primitive Drawing Algorithm
Direction Fields and Euler's Method
Section 3.1 TOVS and Midpoints
Presentation transcript:

Linear Interpolation Applying “weighted averages” to some graphics problems: animations and curve-drawing

What does ‘between’ mean? P G B1 B2 The green point G lies between the two blue points B1 and B2. The pink point P does NOT lie between the two blue points B1 and B2.

Using a “weighted average” Suppose (x1,y1) and (x2,y2) are points The point located half-way in-between is: midpoint = (½)(x1,y1) + (½)(x2,y2) It’s the “average” of (x1,y1) and (x2,y2) Here’s another point on the line-segment that lies between (x1,y1) and (x2,y2): (x’,y’) = (¼)(x1,y1) + (¾)(x2,y2) It’s a “weighted average” of the endpoints

The generalization Let B1 = (x1,y1) and B2 = (x2,y2) be the two endpoints of a line-segment. Suppose w1 and w2 are “weights” (i.e., neither is negative, and their sum equals 1). Then the point P = w1*B1 + w2*B2 is called a “weighted average” of B1 and B2, and P will be located “in-between” B1 and B2. Here P is obtained by “linear interpolation”

Describing a line-segment Mathematical description of line-segments Let B1 = (x1,y1) and B2 = (x2,y2) be the two end-points of a given line-segment Let t be a real number whose value can vary continuously, from 0.0 to 1.0 Then point P = (1-t)*B1 + t*B2 will vary continuously over the entire line-segment, starting at B1 (when t=0.0) and ending up at B2 (when t=1.0)

Animating a line-segment initial position final position in-between positions

The programming idea We only need to specify the segment’s two endpoints at the start and the finish As the segment moves all its intermediate endpoint locations are then calculated as linear interpolations (“weighted averages”) This idea can be simultaneously applied to lots of different line-segments (e.g., to all the sides of a polygon, or to all the “edges” in a wire-frame model)

The ‘polyline’ structure typedef struct { float x, y; } point_t; typedef struct { int numverts; point_t vert[ MAXVERT ]; } polyline_t; // declare two polylines (for start and finish) // and a variable polyline (for “in-betweens”) tween[i].x = (1-t)*B1[i].x + t*B2[i].x; tween[i].y = (1-t)*B1[i].y + t*B2[i].y;

The ‘tweening.cpp’ demo We illustrate this idea for animating simple polygons, using random-numbers for the coordinates of the starting vertices and the ending vertices We use linear interpolation to calculate the sequence of the “in-between” vertices We use Bresenham’s line-drawing method to “connect-the-dots” at each stage

Stick man

Drawing curves Another application of “linear interpolation” We can construct a so-called Bezier curve The curve is determined by specifying a small number of “control points” A recursive algorithm is then applied, to generate locations along a smooth curve This idea is ‘deCasteljau’s algorithm’ Kai Long has written an implementation

Here’s the idea P1 P2 P3 P4 Start with some “control points” (Here we use just four of them) Find their “weighted averages” Only the red point actually is drawn The same value of t is used for all of these interpolations

Kai’s Implementation typedef struct { double h, v; } Point; typedef struct { int numcpts; Point cpts[ MAXVERT ]; } BezierCruve; // helper function void middle( Point p, Point q, Point &mid ) { mid.x = (p.x + q.x)/2; mid.y = (p.y + q.y)/2; }

Labels used in recursion P1 p2 h1 h2 a c1 c2 b1 b2 d if ( very_near( p1, p2 ) // base case draw_line_segment( p1, p2 ); else { // recursion case recursive_bezier( p1, b1, c1, d ); recursive_bezier( d, c2, b2, p2 ); }

In-class exercise Can you combine these two applications? Create a bezier curve with 4 control-points Create another one with 4 control-points Construct some in-between Bezier curves by applying linear-interpolation to pairs of corresponding control-points So first curve will “morph” into second one