Maths Fundamentals Games Fundamentals © by Jarek Francik Kingston University, London 2008-2013.

Slides:



Advertisements
Similar presentations
ADA: 15. Basic Math1 Objective o a reminder about dot product and cross product, and their use for analyzing line segments (e.g. do two segments.
Advertisements

Vector Calculus Mengxia Zhu Fall Objective Review vector arithmetic Distinguish points and vectors Relate geometric concepts to their algebraic.
Physics 1D03 - Lecture 31 Vectors Scalars and Vectors Vector Components and Arithmetic Vectors in 3 Dimensions Unit vectors i, j, k Serway and Jewett Chapter.
Chapter 4.1 Mathematical Concepts
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Basic Math Vectors and Scalars Addition/Subtraction of Vectors Unit Vectors Dot Product.
Motion Vectors. Displacement Vector  The position vector is often designated by.  A change in position is a displacement.  The displacement vector.
Physics 106: Mechanics Lecture 05 Wenda Cao NJIT Physics Department.
Linear Algebra, Principal Component Analysis and their Chemometrics Applications.
Chapter 3: VECTORS 3-2 Vectors and Scalars 3-2 Vectors and Scalars
Scalar and Vector Fields
Chapter 14 Section 14.3 Curves. x y z To get the equation of the line we need to know two things, a direction vector d and a point on the line P. To find.
2IV60 Computer Graphics Basic Math for CG
1 Physics 111/121 Mini-Review Notes on Vectors. 2 Right hand rule: - curl fingers from x to y - thumb points along +z.
Vectors Vector: a quantity that has both magnitude (size) and direction Examples: displacement, velocity, acceleration Scalar: a quantity that has no.
Vector. Scaler versus Vector Scaler ( 向量 ): : described by magnitude  E.g. length, mass, time, speed, etc Vector( 矢量 ): described by both magnitude and.
Halliday/Resnick/Walker Fundamentals of Physics 8th edition
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Vectors Vector: a quantity that has both magnitude (size) and direction Examples: displacement, velocity, acceleration Scalar: a quantity that has no.
Vectors in 2-Space and 3-Space II
1.1 – 1.2 The Geometry and Algebra of Vectors.  Quantities that have magnitude but not direction are called scalars. Ex: Area, volume, temperature, time,
Section 13.4 The Cross Product. Torque Torque is a measure of how much a force acting on an object causes that object to rotate –The object rotates around.
Roll and Fall Playing with the Laws of Motion Games Fundamentals © by Jarek Francik Kingston University, London
Physics and Physical Measurement Topic 1.3 Scalars and Vectors.
L 2 – Vectors and Scalars Outline Physical quantities - vectors and scalars Addition and subtraction of vector Resultant vector Change in a vector quantity,
Forces in Two Dimensions
2008 Physics 2111 Fundamentals of Physics Chapter 10 1 Fundamentals of Physics Chapter 10 Rotation 1.Translation & Rotation 2.Rotational Variables Angular.
Vector Space o Vector has a direction and a magnitude, not location o Vectors can be defined by their I, j, k components o Point (position vector) is a.
Equations of Lines and Planes
CGDD 4003 THE MATH LECTURE (BOILED DOWN, YET LIGHTLY SALTED)
1. Determine vectors and scalars from these following quantities: weight, specific heat, density, volume, speed, calories, momentum, energy, distance.
Let’s Bounce! or Physics of Collisions Part 1 Games Fundamentals © by Jarek Francik Kingston University, London
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
PHYSICS 111 SI 2D MOTION; PROJECTILE MOTION. You are adding vectors of length of 20 and 40 units. What is the only possible resultant magnitude?  A)18.
Physics and Physical Measurement Topic 1.3 Scalars and Vectors.
Physics 141Mechanics Lecture 3 Vectors Motion in 2-dimensions or 3-dimensions has to be described by vectors. In mechanics we need to distinguish two types.
Introduction to Vectors What is a vector? Algebra of vectors The scalar product.
12 A VECTORS AND SCALARS 12 B GEOMETRIC OPERATIONS HOMEWORK: VIEW POWER POINT BEFORE NEXT CLASS.
Game Engine Architecture
Vectors AP Physics C.
Physics 1: Mechanics Đào Ngọc Hạnh Tâm
General Physics 101 PHYS Dr. Zyad Ahmed Tawfik
Starter  .
(Constant acceleration)
Angular Vectors.
Vectors Vector: a quantity that has both magnitude (size) and direction Examples: displacement, velocity, acceleration Scalar: a quantity that has no.
Review: Transformations
Lecture 3 0f 8 Topic 5: VECTORS 5.3 Scalar Product.
Introduction to Vectors
Pointing the Way Vectors.
Vectors and Scalars Chapter 2.
Vectors and Two Dimensional motion
Lecture 4 Interconvert between Cartesian and Polar coordinates
REVIEW PROBLEMS FOR TEST 1 PART 3
Physics VECTORS AND PROJECTILE MOTION
Kinematics in Two Dimensions; Vectors
Kinematics in Two Dimensions
Find the velocity of a particle with the given position function
Projectile Motion A projectile is an object moving in two or three dimensions only under the influence of gravity.
Pointing the Way Vectors.
2 Vectors in 2-space and 3-space
Physics VECTORS AND PROJECTILE MOTION
Vectors.
CHAPTER 3 VECTORS NHAA/IMK/UNIMAP.
Mathematics Vectors a b c LabRat Scientific © 2019.
Journal Entry 7 Vector Analysis
Introduction to Vectors
Serway and Jewett Chapter 3
Or What’s Our Vector Victor?
Presentation transcript:

Maths Fundamentals Games Fundamentals © by Jarek Francik Kingston University, London

Trigonometry

 a b c

Detection of Collisions

w (X, Y) (p.x, p.y) Condition for collision abs(p.x – X) < w/2 && abs(p.y – Y) < h/2 public boolean hitTest(Point pt); h

w (X, Y) Condition for collision abs(p.x – X) < w/2 + R && abs(p.y – Y) < h/2 + R public boolean hitTest(Point pt); h (p.x, p.y) R R R Detection of Collisions small artifact...

w (X, Y) Condition for collision abs(r.X – X) < (w + r.w)/2 && abs(r.Y – Y) < (h + r.h)/2 public boolean hitTest(Rectangle rect); h Detection of Collisions r.w (r.X, r.Y)r.h

Condition for collision (not complete) abs(s.X – X) < (w + w’)/2 && abs(s.Y – Y) < (h + h’)/2 w (X, Y)h Detection of Collisions s.w (s.X, s.Y) s.h w’ h’

s.w (s.X, s.Y) s.h w’ h’   w1w1 h1h1 w2w2 h2h2 Hidden Slide: how to find x’ and h’

w (X, Y)h Detection of Collisions s.w (s.X, s.Y) s.h

Detection of Collisions w (X, Y)h s.w (s.X, s.Y) s.h

Detection of Collisions w (X, Y)h s.w (s.X, s.Y) s.h Condition for collision (not complete) abs(s.X – X) < (s.w + w’’)/2 && abs(s.Y – Y) < (s.h + h’’)/2 w’’ h’’

Detection of Collisions w (X, Y) h s.w (s.X, s.Y) s.h general case is like this...

Detection of Collisions In general case: 1.rotate around centre of R1 so that edges of R1 are parallel to the axes 2.abs(X 1 – X 2 ) < (w 1 + w’ 2 )/2 && abs(Y 1 – Y 2 ) < (h 1 + h’ 2 )/2 3.rotate around centre of R2 so that edges of R2 are parallel to the axes 4.abs(X 1 – X 2 ) < (w’ 1 + w 2 )/2 && abs(Y 1 – Y 2 ) < (h’ 1 + h 2 )/2 5.if both conditions are true we have a collision public boolean hitTest(Sprite sprite);

Thales’ Theorem and Perspective in 3D

A DB E C Thales Theorem

Perspective in 3D

f z x’ x Notice also that:

Z f Y z y’ y screen image  Perspective in 3D

Linear Function & Linear Equation

y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + at

Linear Function & Linear Equation y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + at  b a=tg  cannot represent a vertical line

Linear Function & Linear Equation y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + at

Linear Function & Linear Equation y = ax + b Ax + By + C = 0 x = x 0 + at y = y 0 + bt  (x 0, y 0 ) a b

Linear Motion x = x 0 + at y = y 0 + bt direction may be determined by either: pair tangent angle if t is time, a and b determine velocity a b (x,y) (x+a,y+b) Sprite *p = new CSpriteXxx(...); p->SetDirection(angle); p->SetDirection(a, b); p->SetSpeed(v); p->SetVelocity(a, b);

xx yy (x 5,y 5 ) xx yy (x 3,y 3 ) can be applied iteratively: x n = x n-1 +  x y n = y n-1 +  y (x 0,y 0 ) xx yy (x 1,y 1 ) xx yy (x 2,y 2 ) xx yy (x 4,y 4 ) Linear Motion

vxvx vyvy (x 5,y 5 ) vxvx vyvy (x 3,y 3 ) Deltas are the Velocity: x n = x n-1 + v x y n = y n-1 + v y (x, y) position (v x, v y ) velocity vector speed (scalar) (x 0,y 0 ) vxvx vyvy (x 1,y 1 ) vxvx vyvy (x 2,y 2 ) vxvx vyvy (x 4,y 4 ) p->GetXVelocity(); p->GetYVelocity(); p->GetSpeed(); p->SetVelocity (a, b); p->SetSpeed(v); Linear Motion

v x3 v y3 (x 3,y 3 ) increase velocity in each step: v xn = v xn-1 + a x v yn = v yn-1 + a y x n = x n-1 + v x y n = y n-1 + v y (ax, ay) acceleration vector acceleration (vector) (x 0,y 0 ) v x1 v y1 (x 1,y 1 ) v x2 v y2 (x 2,y 2 ) x = p->GetXVelocity(); y = p->GetYVelocity(); x += ax; y += ay; p->SetVelocity(x, y) // another method v = p->GetSpeed(); v += a; p->SetSpeed(v); Accelerated Motion

Vectors and Vector Algebra

Vector Geometrical object that: –has magnitude (length) –has direction –can be added to other vectors In 2D plane: In 3D space: In n-dimensional space

Vector In Physics: Vectors: –velocity –acceleration –force –momentum Scalars: –speed –mass –power –energy

Normal Vector Vector perpendicular to a surface In CG widely used to model the shapes, e.g.: –lighting & 3D rendering –calculating the collisions

Adding Vectors B A A + B

Multiplication of 2D Vectors Multiplication of a Vector by a Number A 2A 3A

Multiplication of 2D Vectors Multiplication of a Vector by a Number Cross Product of Vectors cross product A  B is a vector perpendicular to both A and B (in 3D space) ABAB A B  B  A = - A  B Interactive demo:

Multiplication of 2D Vectors Multiplication of a Vector by a Number Cross Product of Vectors Dot Product of Vectors B A  Interactive demo:

Multiplication of 2D Vectors Quick calculation: Dot Product: Cross Product: N is the Normal Vector to A and B

Multiplication of 2D Vectors ABABABAB number (scalar)vector |A||B|cos  |A||B|sin  N  = 0  max0   = 90  0max quick formula:x a x b + y a y b x a y b - y a x b

Multiplication of 3D Vectors Multiplication of a Vector by a Number Dot Product of Vectors Cross Product of Vectors

Example Am I approaching him or not? yes, if: VD > 0 VD = V X X + V Y Y D = X, Y = X E – X R, Y E – Y R V = V X, V Y double x = enemy.GetX() – rocket.GetX(); double y = enemy.GetY() – rocket.GetY(); double vx = rocket.GetXVelocity(); double vy = rocket.GetYVelocity(); if (vx * x + vy * y > 0)

Example Is it on my left or my right? right, if: VxD > 0 VxD = V X Y - V Y X D = X, Y = X E – X R, Y E – Y R V = V X, V Y double x = enemy.GetX() – rocket.GetX(); double y = enemy.GetY() – rocket.GetY(); double vx = rocket.GetXVelocity(); double vy = rocket.GetYVelocity(); if (vx * y - vy * x > 0)