1 / 9

Scalars, Points and Vectors (4.2)

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

zorion
Download Presentation

Scalars, Points and Vectors (4.2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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. 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. 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 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. 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. 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. 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. 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. A plane • Given three points • P = P1 + (P2-P1)t + (P3-P1)*s • Calculate the centroid of a polygon • P = (P1 + P2 + P3) / 3;

More Related