How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

Similar documents
Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Computer graphic -- Programming with OpenGL I

Basics of Computational Geometry

Mathematics Background

2D Drawing Primitives

Intermediate Mathematics League of Eastern Massachusetts

PLC Papers Created For:

4: Polygons and pixels

Scalar Field Visualization. Some slices used by Prof. Mike Bailey

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

The figures below are all prisms. The bases of these prisms are shaded, and the height (altitude) of each prism marked by a dashed line:

Grade 6 Mathematics Item Specifications Florida Standards Assessments

Geometry: Semester 2 Practice Final Unofficial Worked Out Solutions by Earl Whitney

Programming of Graphics

CS130 : Computer Graphics Lecture 2: Graphics Pipeline. Tamar Shinar Computer Science & Engineering UC Riverside

An angle that has a measure less than a right angle.

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Student Outcomes. Lesson Notes. Classwork. Opening Exercise (3 minutes)

About Finish Line Mathematics 5

Computer Graphics Fundamentals. Jon Macey

Elementary Planar Geometry

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

CSCI 4620/8626. Coordinate Reference Frames

Boardworks Ltd KS3 Mathematics. S1 Lines and Angles

Unit 1, Lesson 1: Tiling the Plane

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Marching Squares Algorithm. Can you summarize the marching squares algorithm based on what we just discussed?

Digits. Value The numbers a digit. Standard Form. Expanded Form. The symbols used to show numbers: 0,1,2,3,4,5,6,7,8,9

Course Number: Course Title: Geometry

GEOMETRY & INEQUALITIES. (1) State the Triangle Inequality. In addition, give an argument explaining why it should be true.

1. CONVEX POLYGONS. Definition. A shape D in the plane is convex if every line drawn between two points in D is entirely inside D.

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Mgr. ubomíra Tomková GEOMETRY

Prime Time (Factors and Multiples)

Describe Plane Shapes

What would you see if you live on a flat torus? What is the relationship between it and a room with 2 mirrors?

6th Grade Report Card Mathematics Skills: Students Will Know/ Students Will Be Able To...

Number- Algebra. Problem solving Statistics Investigations

Name Date Class. When the bases are the same and you multiply, you add exponents. When the bases are the same and you divide, you subtract exponents.

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

Curvature Berkeley Math Circle January 08, 2013

Year 6 Mathematics Overview

Principles of Computer Game Design and Implementation. Lecture 6

CHAPTER 2 REVIEW COORDINATE GEOMETRY MATH Warm-Up: See Solved Homework questions. 2.2 Cartesian coordinate system

Assignment 1. Simple Graphics program using OpenGL

Computer Graphics. OpenGL

CS 465 Program 4: Modeller

Maths. Formative Assessment/key piece of work prior to end of unit: Term Autumn 1

CSC 8470 Computer Graphics. What is Computer Graphics?

Unit Circle. Project Response Sheet

Lesson 1. Unit 2 Practice Problems. Problem 2. Problem 1. Solution 1, 4, 5. Solution. Problem 3

Developmental Math An Open Program Unit 7 Geometry First Edition

(Refer Slide Time: 00:02:00)

Unit 2. Looking for Pythagoras. Investigation 4: Using the Pythagorean Theorem: Understanding Real Numbers

Scalar Field Visualization I

Geometry. (1) Complete the following:

Moore Catholic High School Math Department

Glossary Common Core Curriculum Maps Math/Grade 6 Grade 8

Data Representation in Visualisation

JMC 2015 Teacher s notes Recap table

202 The National Strategies Secondary Mathematics exemplification: Y7

Vocabulary: Looking For Pythagoras

Scalar Field Visualization I

Grade 9 Math Terminology

Lesson Polygons

(Refer Slide Time 05:03 min)

Number Mulitplication and Number and Place Value Addition and Subtraction Division

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

Ray Tracer I: Ray Casting Due date: 12:00pm December 3, 2001

round decimals to the nearest decimal place and order negative numbers in context

A triangle that has three acute angles Example:

Mathematics; Gateshead Assessment Profile (MGAP) Year 6 Understanding and investigating within number

New Swannington Primary School 2014 Year 6

C if U can Shape and space

Three-Dimensional Shapes

R(-14, 4) R'(-10, -2) S(-10, 7) S'(-6, 1) T(-5, 4) T'(-1, -2)

Year 6 Maths Long Term Plan

SHAPE, SPACE and MEASUREMENT

Area rectangles & parallelograms

15. First make a parallelogram by rotating the original triangle. Then tile with the Parallelogram.

Multiply using the grid method.

Oral and Mental calculation

Angles. An angle is: the union of two rays having a common vertex.

Area of Plane Shapes 1

Vector Addition. Qty Item Part Number 1 Force Table ME-9447B 1 Mass and Hanger Set ME Carpenter s level 1 String

Math 6: Geometry 3-Dimensional Figures

Log1 Contest Round 2 Theta Circles, Parabolas and Polygons. 4 points each

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

An Introduction to 2D OpenGL

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th

MATHEMATICS Key Stage 2 Year 6

Maya Lesson 6 Screwdriver Notes & Assessment

Properties of a Circle Diagram Source:

Y6 MATHEMATICS TERMLY PATHWAY NUMBER MEASURE GEOMETRY STATISTICS

CMSC427 Final Practice v2 Fall 2017

Shadows in the graphics pipeline

EVERYTHING YOU NEED TO KNOW TO GET A GRADE C GEOMETRY & MEASURES (FOUNDATION)

Rational Numbers: Graphing: The Coordinate Plane

Polygons in the Coordinate Plane

Transcription:

Today s lecture Today we will learn about The mathematics of 3D space vectors How shapes are represented in 3D Graphics Modelling shapes as polygons Aims and objectives By the end of the lecture you will be able to describe 3D coordinates and vectors basic vector mathematics How points are draw using OpenGL How shapes are are drawn using polygons How to use GL_POINTS, GL_TRIANGLES and GL_TRIANGLESTRIP Computer Graphics To do Computer Graphics we have to represent everything as numbers Positions Objects Colours Whatever we want to do with things can be represented as mathematical operations Lets start with positions Coordinates 1

A screen is a 2D grid of pixels Coordinates 2

each pixel has a position defined by 2 numbers x horizontal y vertical any position is relative to the origin Coordinates 3

x and y are distances relative to the top left corner call this the origin The starting point of our coordinates any position is relative to the origin Coordinates 4

doesn t have to be pixels on a screen an represent any point in space by x and y space is continuous not divided into pixels so we use floats not integers Coordinates 5

Again x and y are relative to the origin Coordinates 6

we can combine x and y a single mathematical object a vector (x, y) Coordinates 7

We use vectors to define positions in space but they are always relative positions a point in space is defined by: a vector an origin Coordinates 8

This all works the same in 3D space except vectors now have 3 components (x, y, z) Vectors A vector is a single entity v = (x, y) that combines together x and y It is a convenient way of storing both there are also useful mathematical operations defined on vectors they act on the whole vector not x and y separately Processing has a class PVector 9

Magnitude and Direction Another way of looking at vectors. All vectors have A Magnitude (length) A Director Magnitude and Direction Vectors can have the same magnitude and different directions... Magnitude and Direction 10

the same direction and different magnitudes... or Magnitude and Direction The magnitude is a scalar (single number) The direction is a vector of length 1 The direction gives the relative sizes of x, y, z Magnitude and Direction The larger the magnitude, the longer the vector The relative size of x, y, z in give the direction the vector faces in A negative direction means the opposite direction e.g. setting v.x = v.x reverses the direction along the x axis. 11

Magnitude The magnitude is a scalar (single number) The length of the vector How do we calculate it? Pythagoras Theorem "In a right angle triangle the square on the hypotenuse is the sum of the squares on the other two sides" h 2 = x 2 + y 2 h is the length Magnitude We can use the formula to calculate the magnitude h 2 = x 2 + y 2 12

h = x 2 + y 2 PVector has a method mag for calculating it the mathematical symbol for the magnitude of vector v is v Direction Direction is represented by a vector with length 1 To get the direction you divide a vector by its magnitude The symbol for the direction of v is v v = v V ( x (x, y) =, x 2 +y 2 This it called normalising ) y x 2 +y 2 A vector of length 1 is called normalised PVector has a method normalize for calculating it Multiplying by a Scalar A scalar is a single number (i.e. not a vector) Multiplying a vector by a scalar multiplies the magnitude and keeps the direction the same so 3v goes 3 times as far in the same direction as v so v 2 goes half the distance in the same direction as v so 2v goes twice as far in the opposite direction PVector has a method mult for multiplying by a scalar Vector Addition 13

To add 2 vectors v 1 = (x 1, y 1 ) and v 2 = (x 1, y 2 ) v 1 + v 2 = (x 1 + x 2, y 1 + y 2 ) Gives you the point that is at position v 2 relative to v 1 So the point that is the equivalent of going first v 1 then v 2 relative to the origin Vector Subtraction 14

negating a vector v creates a vector in the opposite direction If you subtract a vector from another v 1 v 2 you first go v 1 relative to the origin and then go back v 2 (i.e. you go in the opposite direction of v 2 If v 1 and v 2 are positions of points then v 1 v 2 will give you the vector that goes from v 2 to v 1 Vector Addition 15

Another way to think about vector addition A point is a vector relative to somewhere? What if we want to know the vector of a point relative to somewhere else? i.e. changing the origin Vector Addition 16

If we know B relative to A and C relative to B How do we get C relative to A? Vector Addition 17

If we know B relative to A and C relative to B How do we get C relative to A? Adding the vector from B->C to that from A->B gives you the vector from A->C Vector Subtraction 18

If we know B and C both relative to A. How do we get C relative to B? Adding the vector from B->C to that from A->B gives you the vector from A->C Vector Subtraction 19

If we know B and C both relative to A. How do we get C relative to B? You subtract the vector A->B from A->C to get B->C Vectors 20

House Gardener Garden Tree If you know the position of the tree relative to the Garden, what is its position in the world? what is its position relative to the house? what vector does the Gardener have to walk along to get to the tree? Vectors 21

House Gardener Garden Tree If you know the position of the tree relative to the Garden, what is its position in the screen? if the position of the tree is t and the origin of the garden is g the screen position is t + g what is its position relative to the house? what vector does the Gardener have to walk along to get to the tree? Vectors 22

House Gardener Garden Tree If you know the position of the tree relative to the Garden, what is its position in the screen? what is its position relative to the house? if the position of the house is h the position relative to the house is t + g h what vector does the Gardener have to walk along to get to the tree? Vectors 23

House Gardener Garden Tree If you know the position of the tree relative to the Garden, what is its position in the screen? what is its position relative to the house? what vector does the Gardener have to walk along to get to the tree? if the gardener s position (relative to the garden) is p t p Distance between 2 points Lets bring this all together How do we calculate the distance between two points v 1 and v 2? Distance between 2 points Lets bring this all together How do we calculate the distance between two points v 1 and v 2? 24

We want the length of the vector between v 1 and v 2 We want the length of v 1 v 2 v 1 v 2 = (x 1 x 2 ) 2 + (y 1 y 2 ) 2 Moving at constant rate towards a point You have an object at a start position v 1 and you want to get to an end position v 2 at constant speed s v 1 v 2 is the vector we want to move along We need the direction from this vector v 1 v 2 v 1 v 2 The magnitude is the same as the speed s multiply the direction by the magnitude: s v1 v2 v 1 v 2 I will ask you to do this in Processing in the next lab Aims and objectives By the end of the lecture you will be able to describe 3D coordinates and vectors basic vector mathematics How points are draw using OpenGL How shapes are are drawn using polygons How to use GL_POINTS, GL_TRIANGLES and GL_TRIANGLESTRIP 1 Shapes in OpenGL OpenGL Drawing in OpenGL is all based around points defined as an (x, y, z) vector relative to an origin In OpenGL they are called Verteces (sing. Vertex) Vertex is a mathematical term which basically means a corner, or somewhere where lines meet Soon we will see how they are used 25

Drawing Verteces To draw a vertex we use a method called gl.glvertex3f The 3f bit means that it takes 3 floats for x, y, and z There are other different variants that take different arguments (look them up) Drawing Verteces g l. g l B e g i n ( g l. GL_POINTS ) ; g l. g l V e r t e x ( 2 0 0, 100, 300); g l. glend ( ) ; All drawing code in OpenGL needs to be in between a call to glbegin and glend The GL_POINTS bit means that were are drawing the verteces as a set of points Drawing Verteces g l. g l B e g i n ( g l. GL_POINTS ) ; g l. g l V e r t e x ( 1 0 0, 100, 300); g l. g l V e r t e x ( 1 0 0, 300, 300); g l. g l V e r t e x ( 3 0 0, 200, 300); g l. glend ( ) ; Lets draw a triangle This draws 3 points What if we want to draw a filled in triangle? Drawing A Triangle g l. g l B e g i n ( g l. GL\ _TRIANGLES ) ; g l. g l V e r t e x ( 1 0 0, 100, 300); g l. g l V e r t e x ( 1 0 0, 300, 300); g l. g l V e r t e x ( 3 0 0, 200, 300); g l. glend ( ) ; GL_TRIANGLE takes each 3 points and draws a triangle out of them Polygons In CG we build 3D shapes from a surface made out of polygons 2D shapes like triangles and squares They are defined by the points at their corners (Verteces) complex 3D surfaces can be build up out of a mesh of polygons 26

Triangles We normally use Triangles because they are the simplest polygons They are simple: you can t get two sides that cross eachother They are convex: you can t have bits that poke in They are always planar: all 3 verteces lie on the same plane (they are flat) This means we can have efficient algorithms for rendering them Sometimes we also use quadrilaterals (quads) 4 sided shapes Triangles They are simple: you can t get two sides that cross eachother They are convex: you can t have bits that poke in They are always planar: all 3 verteces lie on the same plane (they are flat) 27

Triangles They are simple: you can t get two sides that cross eachother They are convex: you can t have bits that poke in They are always planar: all 3 verteces lie on the same plane (they are flat) Triangles 28

They are simple: you can t get two sides that cross eachother They are convex: you can t have bits that poke in They are always planar: all 3 verteces lie on the same plane (they are flat) Creating Complex Shapes g l. g l B e g i n ( g l. GL_TRIANGLES ) ; g l. g l V e r t e x ( 1 0 0, 100, 300); g l. g l V e r t e x ( 1 0 0, 300, 300); g l. g l V e r t e x ( 3 0 0, 100, 300); g l. g l V e r t e x ( 1 0 0, 300, 300); g l. g l V e r t e x ( 3 0 0, 100, 300); g l. g l V e r t e x ( 3 0 0, 300, 300); g l. glend ( ) ; We can create a square by putting wo triangles together 29

the last two verteces of the first triangle are the same as the first two of the second This is quite inefficient you have to draw them twice Triangle strips With GL_TRIANGLES verteces are grouped into triangle by take them 3 at a time GL_TRIANGLESTRIP does it more efficiently Triangle strips The first 3 verteces are formed into a triangle After that triangles are formed by using the last two verteces of the previous triangle and then next vertex in sequence g l. g l B e g i n ( g l. GL_TRIANGLESTRIP ) ; g l. g l V e r t e x ( 1 0 0, 100, 300); g l. g l V e r t e x ( 1 0 0, 300, 300); g l. g l V e r t e x ( 3 0 0, 300, 300); g l. glend ( ) ; 30

More efficient Gets much better when you have really big meshes Triangle fans GL_TRIANGLEFAN is similar to a triangle strip except each triangle is formed from The very first vertex in the list The last vertex in the previous triangle The next vertex in the list Drawing a Cube with a Triangle strip How would you draw a cube using a triangle strip? Drawing a Cube with a Triangle strip 31

g l. g l B e g i n ( g l. GL_TRIANGLESTRIP ) ; g l. g l V e r t e x ( 1 0 0, 100, 100); g l. g l V e r t e x ( 1 0 0, 300, 100); g l. g l V e r t e x ( 3 0 0, 300, 100); g l. g l V e r t e x ( 3 0 0, 300, 300); g l. g l V e r t e x ( 3 0 0, 100, 300); g l. g l V e r t e x ( 1 0 0, 100, 100); g l. g l V e r t e x ( 1 0 0, 100, 300); g l. g l V e r t e x ( 1 0 0, 300, 300); g l. g l V e r t e x ( 1 0 0, 300, 100); g l. g l V e r t e x ( 1 0 0, 300, 100); g l. g l V e r t e x ( 1 0 0, 300, 300); g l. g l V e r t e x ( 1 0 0, 100, 300); g l. g l V e r t e x ( 3 0 0, 100, 300); g l. glend ( ) ; More complex objects Cubes are fine but what about more complex objects There are a couple of libraries that help GLU is part of the OpenGL distribution, it has a number of methods for creating shapes The Processing OBJ loader by Saito allows you to load in objects created in a modeling tool like Maya or Blender Look them up Height Maps 32

Generating Terrain A grid of polygons (quads) evenly spaced in x and z y-value is the height, given by a data set or function called a height map Height Maps g l. g l B e g i n ( g l.gl_quads ) ; f o r ( i n t i = 0 ; i < heightmap. l e n g t h 1; i ++) f o r ( i n t j = 0 ; j < heightmap [ i ]. l e n g t h 1; j ++) { g l. g l V e r t e x 3 f ( i s p a c i n g, heightmap [ i ] [ j ], j s p a c i n g ) ; g l. g l V e r t e x 3 f ( i s p a c i n g, heightmap [ i ] [ j + 1 ], ( j +1) s p a c i n g ) ; g l. g l V e r t e x 3 f ( ( i +1) s p a c i n g, heightmap [ i + 1 ] [ j + 1 ], ( j +1) s p a c i n g ) ; g l. g l V e r t e x 3 f ( ( i +1) s p a c i n g, heightmap [ i + 1 ] [ j ], j s p a c i n g ) ; } g l. glend ( ) ; Aims and objectives By the end of the lecture you will be able to describe 3D coordinates and vectors basic vector mathematics How points are draw using OpenGL How shapes are are drawn using polygons How to use GL_POINTS, GL_TRIANGLES and GL_TRIANGLESTRIP 33