Chapter 4 Vector Tools for Graphics
Vectors – The Basics Lecture 11 Fri, Sep 19, 2003
Review of Vectors A point specifies a position. A vector specifies a direction and a magnitude. Generally, our vectors will be normalized to have a length of 1.
Operations on Points The difference between two points is a vector. v = P – Q The sum of two points is undefined. The product of a scalar and a point is undefined. We should avoid these operations in our programs.
Operations on Vectors The sum of two vectors is the vector that is defined by the parallogram rule. u v u + v
Operations on Vectors The difference between two vectors is a vector. u u – v v
Operations on Vectors The product of a vector and a scalar is a vector. v 4v4v
Operations on Points and Vectors The sum or difference of a point and a vector is a point. P v P + v Q – v v Q
Points vs. Vectors Points and vectors are not the same. OpenGL treats them differently. However, there is a certain equivalence: PP – O = v
Linear Combinations of Vectors A linear combination of vectors v 1, …, v n, is an expression a 1 v 1 + … + a n v n, where a 1, …, a n are real numbers. The linear combination is affine if a 1 + … + a n = 1.
Affine Linear Combinations For any set of vectors v 1, …, v n, the set of all affine linear combinations of v 1, …, v n defines a convex polygon. v1v1 v2v2 v3v3 v4v4
The Magnitude of a Vector The magnitude of a vector v = (a 1, …, a n ) is |v| = (a … + a n 2 ) 1/2 A vector of length 1 is a unit vector. A vector may be normalized by dividing it by its length: v/|v|.
The Vector Class We will use the Vector3 class whenever it is convenient. vector3.h vector3.cpp However, we must be aware that OpenGL knows nothing of our Vector3 class. To OpenGL, a “vector” is a 3- or 4- dimensional array of floats or doubles.