Vectors, Dot Product, Cross Product, Basic Collision Detection George Georgiev Technical Trainer GeorgeAtanasov George Atanasov.

Slides:



Advertisements
Similar presentations
Creating Vector Graphics in the Web Learning & Development Telerik Software Academy.
Advertisements

Redundant Array of Independent Disks Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Writing HTML made easier Telerik School Academy HTML, CSS and JavaScript.
Inside Windows Boot Process Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Nikolay Kostov Telerik Software Academy academy.telerik.com Technical Trainer About the Course.
Guidelines to Preparing and Delivering an Elevator Pitch Presentation Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training.
Two basic algorithms for path searching in a graph Telerik Algo Academy Graph Algorithms.
Computational Geometry & Collision detection
About the Course Telerik Software Academy CSS Styling.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Eclipse + Android SDK, VS + Windows Phone SDK Telerik Software Academy Hybrid Mobile Applications.
Welcome to the JSON-stores world Learning & Development Telerik Software Academy.
Course Content, Evaluation, Exams Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Eclipse + Android SDK, VS + Windows Phone SDK Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Twitter Bootstrap Telerik Software Academy
Things you need to know George Georgiev Technical Trainer GeorgeAtanasov George Atanasov Front-End Developer.
Hamiltonian Cycle Penka Borukova Student at Telerik Academy.
Group Policy Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation “Baba Tonka” High School of Mathematics.
April, Sofia, Telerik Software Academy Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy ASP.NET MVC.
Sales Processes, Sales Cycle and the Sales Force Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik.
Design Patterns that ease the design by identifying a simple way to realize relationships between entities. Antony Jekov Telerik Software Academy academy.telerik.com.
Using KendoUI for SPA Applications Learning & Development Telerik School Academy.
The way to create cross-platform apps Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
PEST Analysis, Porter’s 5 Forces and Sustainability Strategies Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System.
Searching for a Job, Writing CV and Cover Letter, Passing a Job Interview Telerik Academy for Software Engineers October 6 th 2012 – Sofia academy.telerik.com.
Drive Partitioning Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Telerik Software Academy Mobile apps for iPhone & iPad.
Google APIs and Facebook API Ivaylo Kenov Penka Borukova Telerik Corporation Telerik Academy Students.
The magic of virtual machines Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Basics. OpenGL. “Hello world” George Georgiev Technical Trainer GeorgeAtanasov George Atanasov Front-End Developer.
Device APIs with Xamarin
Telerik Software Academy Mobile apps for iPhone & iPad.
Academy.telerik.com Class of , Fall 2013.
Telerik Software Academy Databases.
Google APIs and Facebook API Ivaylo Kenov Penka Borukova Telerik Corporation Telerik Academy Students.
Telerik Software Academy ASP.NET Web Forms.
What are WinJS and WinRT, Using the APIs in JavaScript George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
JavaScript Modules and Patterns Telerik Software Academy
The True power of dynamic web pages Learning & Development Team Telerik Software Academy.
PEST Analysis, Porter’s 5 Forces and Sustainability Strategies Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System.
Approximate string matching Evlogi Hristov Telerik Corporation Student at Telerik Academy.
Xamarin with SQLite Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
Ivaylo Kenov Telerik Software Academy Technical Assistant.
Developing "evil" JavaScript applications Learning & Development Telerik School Academy.
The PhoneGap History Doncho Minkov Telerik Software Academy Technical Trainer
Building Rock-Solid Software Svetlin Nakov Telerik Software Academy Manager Technical Training
Adobe® Photoshop® CS6 Essentials
Cultivating Professionals for Your Company The Success Story of Telerik Svetlin Nakov, PhD Manager Technical Training Telerik Corp.
Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
AJAX with ASP.NET MVC Telerik Software Academy
Nencho Nenchev Doroteya Agayna Telerik Software Academy Telerik Support Leads.
Installation, Sample Usage, Strings and OOP Telerik Software Academy Software Quality Assurance.
In JavaScript Learning & Development Telerik Software Academy.
Services in AngularJS Telerik Software Academy
Svetlin Nakov Telerik Software Academy Manager Technical Training
What is Roslyn and how can we use it? Telerik Academy Plus C# 6.0 and Roslyn Seminar.
Splitting JavaScript into Dependent Modules Learning & Development Telerik Software Academy.
Changing the default visualization of views in Xamarin.Forms Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
Telerik Software Academy HTML5.
What to expect from the new IDE Telerik Academy Plus Visual Studio 2015 and ASP.NET 5.
Hristian Hristov Telerik Corporation
I have to use math? I am out of here… Telerik School Academy Unity 2D Game Development.
Automating Windows Deployment Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Store Apps, Development Tools, App key features George Georgiev Telerik Corporation Technical Trainer itgeorge.net.
Server Roles and Features Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Binary, Decimal and Hexadecimal Numbers Telerik Software Academy C# Fundamentals – Part 2.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Adding UI and Audio element Telerik Academy Plus Unity 2D Game Development.
Presentation transcript:

Vectors, Dot Product, Cross Product, Basic Collision Detection George Georgiev Technical Trainer GeorgeAtanasov George Atanasov Front-End Developer

 Vectors  Extended revision  The vector dot product  The vector cross product  Collision detection  In Game programming  Sphere collision  Bounding volumes  AABBs 2

Revision, Normals, Projections

4  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  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  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

 Collinear vectors:  Coplanar vectors: 7

 Vectors defining a 3D vector space 8

 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 9

 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 10

 Projection of a vector on another vector 11

Definition, Application, Importance

 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] 13

 Dot Product (2)  Example:  A (5, 6) B (-3, 2) = 5 * (-3) + 6 * 2 = = -3  Result  A scalar number 14

 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 15

 Meaning in Euclidean geometry  If A(x 1, y 1, … ), B(x 2, y 2, … ) are vectors  theta is the angle, in radians, between A and B  Dot Product (A, B) = A. B = = |A|*|B|*cos(theta)  Applies to all dimensions (1D, 2D, 3D, 4D, … nD) 16

 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 U on V  If U and V are non-unit vectors  ( 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 17

 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… 18

Live Demo

Definition, Features, Application

 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 21

 2D Cross product  Take the vectors U(x 1, y 1 ) and V(x 2, y 2 )  Multiply their coordinates across and subtract:  U(x 1, y 1 ) x V(x 2, y 2 ) = (x 1 * y 2 ) – (x 2 * y 1 )  Result  A scalar number 22

 Scalar meaning in Euclidean geometry  If U(x 1, y 1 ) and V(x 2, y 2 ) 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 23

 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’ 24

 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 25

Live Demo

 3D Cross product  Take two 3D vectors U(x 1, y 1, z 1 ) and V(x 2, y 2, z 2 )  Calculate the following 3 coordinates  x 3 = y 1 *z 2 – y 2 *z 1  y 3 = z 1 *x 2 – z 2 *x 1  z 3 = x 1 *y 2 – x 2 *y 1  Result  A 3D vector with coordinates (x 3, y 3, z 3 ) 27

 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 28

 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 29

30  Unpredictable results occur with  Cross product of two collinear vectors  Cross product with a zero-vector  Applications  Calculating normals to surfaces  Calculating torque (physics)

Live Demo

форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране

Basics, Methods, Problems, Optimization

34  Collisions in Game programming  Any intersection of two objects’ geometry  Raise events in some form  Usually the main part in games  Collision response – deals with collision events

35  Collision objects  Can raise collision events  Types  Spheres  Cylinders  Boxes  Cones  Height fields  Triangle meshes

36  Sphere-sphere collision  Easiest to detect  Used in  particle systems  low-accuracy collision detection  Collision occurrence:  Center-center distance less than sum of radiuses  Optimization  Avoid computation of square root

Live Demo

38  Triangle meshes collision  Very accurate  Programmatically heavy  Computation heavy (n 2 )  Rarely needed

39  Collision detection in Game programming  Combines several collision models  Uses bounding volumes  Uses optimizations  Axis-sweep  Lower accuracy in favor of speed

 Bounding volumes  Easy to check for collisions  Spheres  Boxes  Cylinders, etc.  Contain high-triangle-count meshes  Tested for collision before the contained objects  If the bounding volume doesn’t collide, then the mesh doesn’t collide 40

 Bounding sphere  Orientation-independent  Center – mesh’s center  Radius  distance from mesh center to farthest vertex  Effective for  convex, oval bodies  mesh center equally distant from surface vertices  rotating bodies 41

Live Demo

 Minimum bounding sphere  Center – the center of the segment, connecting the two farthest mesh vertices  Radius – the half-length of the segment, connecting the two farthest mesh vertices  Efficient with  convex, oval bodies  rotating bodies  Sphere center rotated with the other mesh vertices 43

Live Demo

 Axis-aligned bounding box (AABB)  Very fast to check for collisions  Usually smaller volume than bounding spheres  Edges parallel to coordinate axes  Minimum corner  coordinates – lowest coordinate ends of mesh  Maximum corner  coordinates – highest coordinate ends of mesh 45

 Axis-aligned bounding box (2)  Efficient with  non-rotating bodies  convex bodies  oblong bodies  If the body rotates, the AABB needs to be recomputed 46

Live Demo

 Checking AABBs for collision  Treat the minimum and maximum corners’ coordinates as interval edges  3D case  If the x intervals overlap  And the y intervals overlap  And the z intervals overlap  Then the AABBs intersect / collide 48

Live Demo

 Oriented bounding box (OBB)  Generated as AABB  Rotates along with the object’s geometry  Advantage:  Rotating it is much faster than creating an new AABB  Usually less volume than AABB  Disadvantage:  Much slower collision check 50

Live Demo

форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране

 3D Graphics and Game Development  academy.telerik.com/.../3d-game- development-opengl academy.telerik.com/.../3d-game- development-opengl academy.telerik.com/.../3d-game- development-opengl  Telerik Software Academy  academy.telerik.com academy.telerik.com  Telerik Facebook  facebook.com/TelerikAcademy facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com forums.academy.telerik.com