7. Computational Geometry - 3D Graphics and Game Development Course

21
Computational Geometry Vectors, Translation, Rotation George Georgiev http://academy.telerik.com Technical Trainer academy.telerik.com /.../3d-game-developm ent-opengl George Atanasov Front-End Developer

description

In this presentation, part of the 3D graphics and game develpment course, we discuss the vector math, the analytic geometry and the programming geometry at all. Main topics: http://academy.telerik.com/.../3d-game-development-opengl Telerik Software Academy: http://www.academy.telerik.com The website and all video materials are in Bulgarian

Transcript of 7. Computational Geometry - 3D Graphics and Game Development Course

Page 1: 7. Computational Geometry - 3D Graphics and Game Development Course

Computational Geometry

Vectors, Translation, Rotation

George Georgiev

http://academy.telerik.com

Technical Trainer

academy.telerik.com

/.../3d-game-developm

ent-opengl

George AtanasovFront-End Developer

Page 2: 7. Computational Geometry - 3D Graphics and Game Development Course

Table of Contents Analytic geometry

Vectors and Points

Vector math Addition / Translation

Subtraction

Multiplication / Scaling

2D Rotation

Vector length

Programming it2

Page 3: 7. Computational Geometry - 3D Graphics and Game Development Course

Analytic geometryThe math

Page 4: 7. Computational Geometry - 3D Graphics and Game Development Course

Analytic geometry

Also called Cartesian geometry Coordinate system

Applies algebraic principles to geometry Algebra

Analysis

4

Page 5: 7. Computational Geometry - 3D Graphics and Game Development Course

Analytic geometry Points (vertices)

Represented by coordinates 2D – (X, Y);

3D – (X, Y, Z);

Etc..

Points are locations inspace

5

Page 6: 7. Computational Geometry - 3D Graphics and Game Development Course

Analytic geometry Points

Example – A (3, 2); H (-1.5, 3);

6

Page 7: 7. Computational Geometry - 3D Graphics and Game Development Course

Analytic geometry Vectors

Represented exactly the same way

Different only by concept Have

Direction

Magnitude (length)

Computers understand vectors Points – vectors added to the

beginning of the coordinate system (0, 0)

7

Page 8: 7. Computational Geometry - 3D Graphics and Game Development Course

Analytic geometry

8

A Point A vector to the point

Page 9: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector mathIt's easy

Page 10: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector math Addition

Vectors can be added just like numbers

Called translation when applied to a point

Example A(5, 10) + B(-3, 7) = C(2, 17)

Subtraction Subtracting two points gives the

vector from the second to the first

Example: A(5, 10) - B(-3, 7) = V(8, 3)

10

Page 11: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector math Multiplication

By a number Multiple each coordinate by the

number

V(5, 7) * 3 = V’(15, 21)

Called uniform scaling

Division works the same way You can always multiply by 1/3

(that’s 0.33)

V(15, 21) / 3 = V’(5, 7)

V(15, 21) * 0.33 = V’(5, 7)11

Page 12: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector math 2D Rotation

A little more complicated

Multiply two of the vector’s coordinates according to a formula

The formula The vector V(x, y) rotated by the

angle ALPHA

x’ = x*cos(ALPHA) - y*sin(ALPHA)

y’ = x*sin(ALPHA) + y*cos(ALPHA)

The resulting vector is V’(x’, y’)12

Page 13: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector math 2D Rotation

Positive angle, counter-clockwise rotation

Negative angle, clockwise rotation

13

Page 14: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector math Vector length

Calculated with the Pythagorean theorem The vector’s x and y

components are perpendicular

The vector’s length is:length = sqrt (x*x + y*y) Where sqrt is the square root

14

Page 15: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector math Unit vector

A unit vector is a vector with a length of 1

A unit vector multiplied by a number has length equal to the number

‘Converting’ a vector to a unit vector Called Normalization

Get the length of the vector

Divide the vector by it’s length15

Page 16: 7. Computational Geometry - 3D Graphics and Game Development Course

Vector mathLive Demo

Page 17: 7. Computational Geometry - 3D Graphics and Game Development Course

Programming geometry

Point classes, functions, operators

Page 18: 7. Computational Geometry - 3D Graphics and Game Development Course

Programming geometry We need

A class describing a point/vector

Operators for vector addition, multiplication

A rotation method

A normalization method

A length calculation method

18

Page 19: 7. Computational Geometry - 3D Graphics and Game Development Course

Programming geometryLive Demo

Page 20: 7. Computational Geometry - 3D Graphics and Game Development Course

форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно

програмиране за деца – безплатни курсове и уроцибезплатен 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#Дончо Минков - сайт за програмиранеНиколай Костов - блог за програмиранеC# курс, програмиране, безплатно

?

? ? ??

?? ?

?

?

?

??

?

?

? ?

Questions?

?

Computational geometry

http://academy.telerik.com/