1 / 32

Computational Geometry

Computational Geometry. Vectors, Dot Product, Cross Product, Basic Collision Detection. George Georgiev. Telerik Corporation. www.telerik.com. Table of Contents. Vectors Extended revision The vector dot product The vector cross product Collision detection In Game programming

darena
Download Presentation

Computational Geometry

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. Computational Geometry Vectors, Dot Product, Cross Product, Basic Collision Detection George Georgiev Telerik Corporation www.telerik.com

  2. Table of Contents • Vectors • Extended revision • The vector dot product • The vector cross product • Collision detection • In Game programming • Sphere collision • Bounding volumes • Axis sweep

  3. Vectors Revision, Normals, Projections

  4. Vectors – revision • Ordered sequences of numbers • OA (6, 10, 18) – 3-dimensional • OA (6, 10) – 2-dimensional • OA (6, 10, 18, -5) – 4-dimensional • Have magnitude and direction A

  5. Vectors – revision • No location • Wherever you need them • Can represent points in space • Points are vectors with a beginning at the coordinate system center • Example: • Point A(5, 10) describes the location (5, 10) • Vector U(5, 10), beginning at (0, 0), describes ‘the path’ to the location (5, 10)

  6. Vectors – revision • All vectors on the same line are called collinear • Can be derived by scaling any vector on the line • E.g.: A(2, 1), B(3, 1.5), C(-1, -0.5) are collinear • Two vectors, which are not collinear, lie on a plane and are called coplanar • => Two non-collinear vectors define a plane • Three vectors, which are not coplanar, define a space

  7. Vectors – revision • Collinear vectors: • Coplanar vectors:

  8. Vectors – revision • Vectors defining a 3D vector space

  9. Vectors – revision • Perpendicular vectors • Constitute a right angle • Deriving a vector, perpendicular to a given one: • Swap two of the coordinates of the given vector (one of the swapped coordinates can’t be zero) • Multiply ONE of the swapped coordinates by -1 • Example: • A (5, 10) given => A’(-10, 5) is perpendicular to A • V (3, 4, -1) given => V’(3, 1, 4) is perpendicular to V

  10. Vectors – revision • Normal vectors to a surface • Constitute a right angle with flat surfaces • Perpendicular to at least two non-collinear vectors on the plane • Constitute a right angle with the tangent to curved surfaces

  11. Vectors – revision • Projection of a vector on another vector

  12. Vector Dot Product Definition, Application, Importance

  13. Vector dot product • Dot Product (a.k.a. scalar product) • Take two equal-length sequences • e.g. sequence A (5, 6) and sequence B (-3, 2) • Multiply each element of A with each element of B • A [i] * B [i] • Add the products • Dot Product(A, B) = A[0] * B[0] + A[1] * B[1] + … + A[i] * B[i] + … + A[n-1] * B[n-1]

  14. Vector dot product • Dot Product (2) • Example: • A (5, 6) B (-3, 2) = 5 * (-3) + 6 * 2 = -15 + 12 = -3 • Result • A scalar number

  15. Vector dot product • Dot product of coordinate vectors • Take two vectors of equal dimensions • Apply the dot product to their coordinates • 2D Example: • A(1, 2) . B(-1, 1) = 1*(-1) + 2*1 = 1 • 3D Example: • A(1, 2, -1) . B(-1, 1, 5) = 1*(-1) + 2*1 + (-1) * 5 = -4 • Simple as that

  16. Vector dot product • Meaning in Euclidean geometry • If A(x1, y1, …), B(x2, y2, …) are vectors • theta is the angle, in radians, between A and B • Dot Product (A, B) = A . B = = |A|*|B|*cos(theta) • |A| and |B| denote the length of A and B • Applies to all dimensions (1D, 2D, 3D, 4D, … nD)

  17. Vector dot product • Meaning in Euclidean geometry (2) • If U and V are unit vectors, then U . V = • cosine of the angle between U and V • the oriented length of the projection of UonV • If U and V are non-unit vectors, then • ( U . V ) divided by |U|*|V| = cosine of the angle between U and V • ( U . V ) divided by |V| = the oriented length of the projection of U on V

  18. Vector dot product • Consequences • If A . B > 0, A and B are in the same half-space • If A . B = 0, A and B are perpendicular • If A . B < 0, A and B are in different half-spaces • Applications • Calculating angles • Calculating projections • Calculating lights • Etc…

  19. Dot Product Computation Live Demo

  20. Vector Cross Product Definition, Features, Application

  21. Vector cross product • Cross product • Operates on vectors with up to 3 dimensions • Forms a determinant of a matrix of the vectors • Result – depends on the dimension • In 2D – a scalar number (1D) • In 3D – a vector (3D) • Not defined for 1D and dimensions higher than 3

  22. 2D Vector cross product • 2D Cross product • Take the vectors U(x1, y1) and V(x2, y2) • Multiply their coordinates across and subtract: • U(x1, y1) x V(x2, y2)= (x1 * y2) – (x2 * y1) • Result • A scalar number

  23. 2D Vector cross product • Scalar meaning in Euclidean geometry • If U(x1, y1) and V(x2, y2) are 2D vectors • theta is the angle between U and V • Cross Product (U, V) = U x V = = |U| * |V| * sin(theta) • |U| and |V| denote the length of U and V • Applies to 2D and 3D

  24. 2D Vector cross product • Scalar meaning in Euclidean geometry (2) • For every two 2D vectors U and V • U x V = the oriented face of the parallelogram, defined by U and V • For every three 2D points A, B and C • If U x V = 0, then A, B and C are collinear • If U x V > 0, then A, B and C constitute a ‘left turn’ • If U x V < 0, then A, B and C constitute a ‘right turn’

  25. 2D Vector cross product • Applications • Graham scan (2D convex hull) • Easy polygon area computation • Cross product divided by two equals oriented (signed) triangle area • 2D orientation • ‘left’ and ‘right’ turns

  26. 2D Cross Product Computation Live Demo

  27. 3D Vector cross product • 3D Cross product • Take two 3D vectors U(x1, y1, z1) and V(x2, y2, z2) • Calculate the following 3 coordinates • x3 = y1*z2 – y2*z1 • y3 = z1*x2 – z2*x1 • z3 = x1*y2 – x2*y1 • Result • A 3D vector with coordinates (x3, y3, z3)

  28. 3D Vector cross product • Meaning in Euclidean geometry • The magnitude • Always positive (length of the vector) • Has the unsigned properties of the 2D dot product • The vector • Perpendicular to the initial vectors U and V • Normal to the plane defined by U and V • Direction determined by the right-hand rule

  29. 3D Vector cross product • The right-hand rule • Index finger points in direction of first vector (a) • Middle finger points in direction of second vector (b) • Thumb points up in direction of the result of a x b

  30. 3D Vector cross product • Unpredictable results occur with • Cross product of two collinear vectors • Cross product with a zero-vector • Applications • Calculating normals to surfaces • Calculating torque (physics)

  31. 3D Cross Product Computation Live Demo

  32. Collision detection Basics,

More Related