Presentation is loading. Please wait.

Presentation is loading. Please wait.

Vector Tools (Ch 4) page 1 CS 367 Scalars, Points and Vectors (4.2) We will only cover 4.1 - 4.4 The author has managed to make a simple topic be much.

Similar presentations


Presentation on theme: "Vector Tools (Ch 4) page 1 CS 367 Scalars, Points and Vectors (4.2) We will only cover 4.1 - 4.4 The author has managed to make a simple topic be much."— Presentation transcript:

1 Vector Tools (Ch 4) page 1 CS 367 Scalars, Points and Vectors (4.2) We will only cover 4.1 - 4.4 The author has managed to make a simple topic be much more complicated than necessary! Scalar - real value Point / Vertex - a location in space (3D) Vector - an entity with direction and magnitude does not have a fixed location often represented as directed line segments (a ray)

2 Vector Tools (Ch 4) page 2 CS 367 uisGL (3D object library) The book explains that OpenGL is not OO This API helps to hide an internal data structure and some mathematical operations Refer to Documentation for more information uisGL Data types float S; uisVertex P1, P2(x,y,z); uisVector V1, V2;

3 Vector Tools (Ch 4) page 3 CS 367 Point / Vertex Operations Point-Point Subtraction Vector = Point - Point uisVertex P1(10, 10, 5), P2(7, 7, 9); V = P1 - P2; cout << V; Point-Vector Addition P1.set(4, 4, 4); P2= V + P1; cout << P2; Calculating Points on a line Midpoint = (P1 + P2) / 2 What about? P3 = (P1 + P2) / 3 Parametric Form of a Line float t = 0.5 P3 = P1 + V * t P3 = P1 + (P2 - P1) * t

4 Vector Tools (Ch 4) page 4 CS 367 Vector Operations Magnitude the length of a vector is a scalar sqrt(V*V) len = V1.length(); Unit Vector Vector of length one v / |v| V1.normalize(); Vector-Vector Addition Vector = Vector + Vector V3 = V1 + V2

5 Vector Tools (Ch 4) page 5 CS 367 Dot product (4.3) S = V1 * V2 S = V1.x*V2.x + V1.y*V2.y + V1.z*V2.z Vectors are perpendicular if V1 * V2 = 0 dot product of unit vectors equals cosine of angle cos (theta) = u * v Remember cosine of 0 = 1 cosine of 90 = 0 cosine of 180 = -1

6 Vector Tools (Ch 4) page 6 CS 367 Cross product (4.4) cross product of two vectors results in a third vector perpendicular to both Calculation (AyBz - AzBy, AzBx - AxBz, AxBy - AyBx) Sample code uisVector V, V1, V2 V = V1 | V2 Right handed? Direction of the perpendicular vector is based on the right handed system V1 | V2 V2 | V1 Group Activity Given three points Find a vector perpendicular to the plane Make it a unit vector

7 Vector Tools (Ch 4) page 7 CS 367 Homogeneous Representations 4.5 3D points and vectors are represented in 4D this helps make some future calculations easier using matrix multiplication P = (x, y, z, 1) V = (x, y, z, 0) Note the calculations adding two vectors results in w = 0 adding a vector to a point results in w = 1

8 Vector Tools (Ch 4) page 8 CS 367 Parametric Representations 4.5 line segment t = time along the line P’ = P1 + (P2 - P1) * t P’ = P1(1-t) + P2(t) perpendicular bisector M = midpoint x(t) = Mx - (By - Ay)t y(t) = My + (Bx - Ax)t segment length sqrt ((Bx - Ax) 2 + (By-Ay) 2 )

9 Vector Tools (Ch 4) page 9 CS 367 A plane Given three points P = P1 + (P2-P1)t + (P3-P1)*s Calculate the centroid of a polygon P = (P1 + P2 + P3) / 3;


Download ppt "Vector Tools (Ch 4) page 1 CS 367 Scalars, Points and Vectors (4.2) We will only cover 4.1 - 4.4 The author has managed to make a simple topic be much."

Similar presentations


Ads by Google