Vectors & Matrices CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Slides:



Advertisements
Similar presentations
Homogeneous Transformations CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.
Advertisements

COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Vector Calculus Mengxia Zhu Fall Objective Review vector arithmetic Distinguish points and vectors Relate geometric concepts to their algebraic.
Computer Graphics Lecture 4 Geometry & Transformations.
General Physics (PHYS101)
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Chapter 4.1 Mathematical Concepts
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CS 4731: Computer Graphics Lecture 6: Points, Scalars and Vectors Emmanuel Agu.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Computer Graphics CSC 630 Lecture 2- Linear Algebra.
Midterm Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2004.
Computer Graphics CSE167: Computer Graphics Instructor: Ronen Barzel UCSD, Winter 2006.
Vectors & Matrices CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2006.
Computer Graphics (Fall 2005) COMS 4160, Lecture 2: Review of Basic Math
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
PHYS 218 sec Review Chap. 1. Caution This presentation is to help you understand the contents of the textbook. Do not rely on this review for.
Fall Scalar Quantity (mass, speed, voltage, current and power) 1- Real number (one variable) 2- Complex number (two variables) Vector Algebra (velocity,
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
An Introduction to Robot Kinematics
Chapter 3. Vector 1. Adding Vectors Geometrically
2IV60 Computer Graphics Basic Math for CG
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 2: Review of Basic Math
Chapter 3 Vectors.
Mathematical Fundamentals
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
Graphics CSE 581 – Interactive Computer Graphics Mathematics for Computer Graphics CSE 581 – Roger Crawfis (slides developed from Korea University slides)
6.837 Linear Algebra Review Patrick Nichols Thursday, September 18, 2003.
Patrick Nichols Thursday, September 18, Linear Algebra Review.
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
Mathematical Topics Review of some concepts:  trigonometry  aliasing  coordinate systems  homogeneous coordinates  matrices, quaternions.
Chapter 4.1 Mathematical Concepts
ME 2304: 3D Geometry & Vector Calculus
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
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.
Transformation of Graphics
Multimedia System and Networking UTD Slide- 1 University of Texas at Dallas B. Prabhakaran Animation Process while (not finished) { MoveEverything();
2D Transformation of Graphics
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
6.837 Linear Algebra Review Patrick Nichols Thursday, September 18, 2003.
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Mathematics for Graphics. 1 Objectives Introduce the elements of geometry  Scalars  Vectors  Points Develop mathematical operations among them in a.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Matthew Christian. About Me Introduction to Linear Algebra Vectors Matrices Quaternions Links.
Phy S Lecture 2 Goals of Lecture 2 Introduce Interactive Learning Segments and try a few The Language of Vectors: –Understand conventions used.
What is Kinematics. Kinematics studies the motion of bodies.
Chapter 3 Vectors. Vector quantities  Physical quantities that have both numerical and directional properties Mathematical operations of vectors in this.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Geometric Transformations
3D Transformation A 3D point (x,y,z) – x,y, and z coordinates
3-D Geometric Transformations
Computer Graphics Matrices
Honours Graphics 2008 Session 2. Today’s focus Vectors, matrices and associated math Transformations and concatenation 3D space.
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Honors Geometry.  We learned how to set up a polygon / vertex matrix  We learned how to add matrices  We learned how to multiply matrices.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
Computer Graphics Mathematical Fundamentals Lecture 10 Taqdees A. Siddiqi
Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry "Old Henry And His Old Aunt" Defined using right triangle  x y h.
4. Geometric Objects and Transformations
Transformations. Modeling Transformations  Specify transformations for objects  Allows definitions of objects in own coordinate systems  Allows use.
CSE 167 [Win 17], Lecture 2: Review of Basic Math Ravi Ramamoorthi
Lecture 03: Linear Algebra
Game Programming Algorithms and Techniques
Presentation transcript:

Vectors & Matrices CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005

Project 1 Make a program that renders a simple 3D object (like a cube). It should render several copies of the same object with different positions/rotations. The goal of project 1 is to get familiar with the C++ compiler and OpenGL (or Java, Direct3D…) Due Thursday, October 6, 11:00 am

Project 1: Object Oriented Approach I suggest an object oriented approach that will allow you to add new features easily as the course goes on Create a simple ‘Model’ class that stores an array of triangles Make one or more ‘CreateX()’ member functions that create various basic shapes (CreateCube() for example) Give it a ‘Draw()’ function that outputs the data to GL

Project 1 class Vertex { Vector3 Position; Vector3 Color; public: void Draw(); }; class Triangle { Vertex Vert[3]; public: void Draw(); }; class Model { int NumTris; Triangle *Tri; void Init(int num){delete Tri; Tri=new Triangle[num]; NumTris=num;} public: Model(){NumTris=0; Tri=0;} ~Model(){delete Tri;} void CreateBox(float x,float y,float z); void CreateTeapot(); void Draw(); };

Software Architecture Object oriented Make objects for things that should be objects Avoid global data & functions Encapsulate information Provide useful interfaces Put different objects in different files

Vectors

Coordinate Systems Right handed coordinate system

Vector Arithmetic

Vector Magnitude The magnitude (length) of a vector is: A vector with length=1.0 is called a unit vector We can also normalize a vector to make it a unit vector:

Dot Product

Example: Angle Between Vectors How do you find the angle θ between vectors a and b? a b θ

Example: Angle Between Vectors a b θ

Dot Products with General Vectors The dot product is a scalar value that tells us something about the relationship between two vectors If a · b > 0 then θ < 90º If a · b 90º If a · b = 0 then θ = 90º (or one or more of the vectors is degenerate (0,0,0))

Dot Products with One Unit Vector a u a·u If |u|=1.0 then a·u is the length of the projection of a onto u

Example: Distance to Plane A plane is described by a point p on the plane and a unit normal n. Find the distance from point x to the plane p n x

Example: Distance to Plane The distance is the length of the projection of x-p onto n: p n x x-p

Dot Products with Unit Vectors b θ a a·b = 0 0 < a·b < 1 a·b = -1 a·b = 1 -1 < a·b < 0 a·b

Cross Product

Properties of the Cross Product area of parallelogram ab is a vector perpendicular to both a and b, in the direction defined by the right hand rule if a and b are parallel

Example: Normal of a Triangle Find the unit length normal of the triangle defined by 3D points a, b, and c a b c

Example: Normal of a Triangle b-a c-a a b c

Example: Area of a Triangle Find the area of the triangle defined by 3D points a, b, and c a b c

Example: Area of a Triangle b-a c-a a b c

Example: Alignment to Target An object is at position p with a unit length heading of h. We want to rotate it so that the heading is facing some target t. Find a unit axis a and an angle θ to rotate around. p h t

Example: Alignment to Target p h t t-p θ a

Vector Class class Vector3 { public: Vector3(){x=0.0f; y=0.0f; z=0.0f;} Vector3(float x0,float y0,float z0){x=x0; y=y0; z=z0;} void Set(float x0,float y0,float z0){x=x0; y=y0; z=z0;} void Add(Vector3 &a){x+=a.x; y+=a.y; z+=a.z;} void Add(Vector3 &a,Vector3 &b){x=a.x+b.x; y=a.y+b.y; z=a.z+b.z;} void Subtract(Vector3 &a){x-=a.x; y-=a.y; z-=a.z;} void Subtract(Vector3 &a,Vector3 &b){x=a.x-b.x; y=a.y-b.y; z=a.z-b.z;} void Negate(){x=-x; y=-y; z=-z;} void Negate(Vector3 &a){x=-a.x; y=-a.y; z=-a.z;} void Scale(float s){x*=s; y*=s; z*=s;} void Scale(float s,Vector3 &a){x=s*a.x; y=s*a.y; z=s*a.z;} float Dot(Vector3 &a){return x*a.x+y*a.y+z*a.z;} void Cross(Vector3 &a,Vector3 &b) {x=a.y*b.z-a.z*b.y; y=a.z*b.x-a.x*b.z; z=a.x*b.y-a.y*b.x;} float Magnitude(){return sqrtf(x*x+y*y+z*z);} void Normalize(){Scale(1.0f/Magnitude());} float x,y,z; };

Matrices & Transformations

3D Models Let’s say we have a 3D model that has an array of position vectors describing its shape We will group all of the position vectors used to store the data in the model into a single array: v n where 0 ≤ n ≤ NumVerts-1 Each vector v n has components v nx v ny v nz

Translation Let’s say that we want to move our 3D model from it’s current location to somewhere else… In technical jargon, we call this a translation We want to compute a new array of positions v′ n representing the new location Let’s say that vector d represents the relative offset that we want to move our object by We can simply use: v′ n = v n + d to get the new array of positions

Transformations v′ n = v n + d This translation represents a very simple example of an object transformation The result is that the entire object gets moved or translated by d From now on, we will drop the n subscript, and just write v′ = v + d remembering that in practice, this is actually a loop over several different v n vectors applying the same vector d every time

Transformations Always remember that this compact equation can be expanded out into Or into a system of linear equations:

Rotation Now, let’s rotate the object in the xy plane by an angle θ, as if we were spinning it around the z axis Note: a positive rotation will rotate the object counterclockwise when the rotation axis (z) is pointing towards the observer

We can expand this to: And rewrite it as a matrix equation: Or just: Rotation

We can represent a z-axis rotation transformation in matrix form as: or more compactly as: where

Rotation We can also define rotation matrices for the x, y, and z axes:

Linear Transformations Like translation, rotation is an example of a linear transformation True, the rotation contains sin()’s and cos()’s, but those ultimately just end up as constants in the actual linear equation We can generalize our matrix in the previous example to be:

Linear Equation A general linear equation of 1 variable is: where a and d are constants A general linear equation of 3 variables is: Note: there are no nonlinear terms like v x v y, v x 2, sin(v x )…

System of Linear Equations Now let’s look at 3 linear equations of 3 variables v x, v y, and v z Note that all of the a n, b n, c n, and d n are constants (12 in total)

Matrix Notation

Translation Let’s look at our translation transformation again: If we really wanted to, we could rewrite our three translation equations as:

Identity We can see that this is equal to a transformation by the identity matrix

Identity Multiplication by the identity matrix does not affect the vector

We can apply a uniform scale to our object with the following transformation If s>1, then the object will grow by a factor of s in each dimension If 0<s<1, the object will shrink If s<0, the object will be reflected across all three dimensions, leading to an object that is ‘inside out’ Uniform Scaling

We can also do a more general nonuniform scale, where each dimension has its own scale factor which leads to the equations: Non-Uniform Scaling

Multiple Transformations If we have a vector v, and an x-axis rotation matrix R x, we can generate a rotated vector v′: If we wanted to then rotate that vector around the y-axis, we could simply:

We can extend this to the concept of applying any sequence of transformations: Because matrix algebra obeys the associative law, we can regroup this as: This allows us to concatenate them into a single matrix: Note: matrices do NOT obey the commutative law, so the order of multiplications is important Multiple Transformations

3D Linear Transformations