32
Introduction to Computer Graphics Instructor: Sonny Chan TA: Kamyar Allahverdi Tutorial 03

Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • [email protected] • No foods or drinks in the lab

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Introduction to Computer Graphics

Instructor: Sonny Chan TA: Kamyar Allahverdi

Tutorial 03

Page 2: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Intro• Kamyar Allahverdi

• CPSC 453 Tutorial 03

• Contact:

[email protected]

• No foods or drinks in the lab

Page 3: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Intro

• You can code in Windows/Linux/Mac

• Labs done in Linux

Page 4: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Intro• Register for Piazza:

• https://piazza.com/ucalgary.ca/fall2016/cspc453

• Ask questions here

• TA Class Materials:

• http://kamyarinfinity.me/courses/cpsc453/

Page 5: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Assignments

• 5 Assignments (50% of your total grade)

• Written component

• Programming component

• Can use at most 5 late days for all of programming parts.

Page 6: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Assignment 1Line & Polygon Geometry

Page 7: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Written PartParametric Equation

Courtesy of Krishnavedala

Page 8: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• Why?

• Use a parameter to define a curve

• Why?

• Move over them

• Draw them

Page 9: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation

• How do you move over a circle?

Page 10: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation

x

2 + y

2 = 1

Page 11: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation

x

2 + y

2 = 1

x = ±p1� y

2

Page 12: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation

x

2 + y

2 = 1

x = ±p1� y

2

Page 13: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation

• Define circles in a different way

Page 14: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Polar Coordinates• Define circles using Polar Coordinates

θr

P

r = 1

0 ✓ 2⇡

Page 15: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Polar Coordinates• How to go back to Cartesian Coordinates?

θr

P

x = r cos ✓

y = r sin ✓

Page 16: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Polar Coordinates• How to go back to Cartesian Coordinates?

θ

rx = r cos ✓

y = r sin ✓

x

y

Page 17: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Polar Coordinates• And how about finding polar coordinates?

θ

r

x

y

sin

2✓ + cos

2✓ = 1

x

2+ y

2= r

2cos

2✓ + r

2sin

2✓

x

2+ y

2= r

2

r =

px

2+ y

2

Page 18: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Polar Coordinates• And how about finding polar coordinates?

θ

r

x

ytan ✓ =

y

x

✓ = arctany

x

Page 19: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Polar Coordinates• Define circles using Polar Coordinates

θr

P

r = 1

0 ✓ 2⇡

Page 20: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Polar Coordinates• Define circles using Polar Coordinates

θr

P

x = cos ✓

y = sin ✓

Page 21: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• Here, θ is a parameter

θr

P

x = cos ✓

y = sin ✓

Page 22: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• Here, θ is a parameter

• We can draw/move over the circle by incrementing θ θ

r

P

x = cos ✓

y = sin ✓

Page 23: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• What about this?

θr

P

x = cos 2✓

y = sin 2✓

Page 24: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• What about this?

θr

P

x = 2 cos 2✓

y = sin 2✓

Page 25: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• What about this?

θr

P

x = 2 cos 2✓

y = sin 2✓

Page 26: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• What is radius?

θr

P

x = 2 cos 2✓

y = sin 2✓

Page 27: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• What is radius?

θr

P

x = 2 cos 2✓

y = sin 2✓

r =px

2 + y

2

=p4cos2✓ + sin

2✓

=p1 + 3cos2✓

1 r p4 = 2

Page 28: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• Generally, not very easy to guess the shape

x = cos (

t

2

)

y =

1

2

sin (t)

Page 29: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Parametric Equation• Generally, not very easy to guess the shape

• Let’s try WolframAlpha!

x = cos (

t

2

)

y =

1

2

sin (t)

Page 30: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Assignment 1• Written part deadline: Thursday, September 22, 11:59 PM

• Programming part deadline: Friday, September 30, 11:59 PM

• The written part can’t use your 5 late days!

Page 31: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Assignment 1• Prepare for the next session:

• Install GLFW, if working on your laptop

• Take a look at the boilerplate code

Page 32: Introduction to Computer Graphics · Intro • Kamyar Allahverdi • CPSC 453 Tutorial 03 • Contact: • kamyar.allahverdi@gmail.com • No foods or drinks in the lab

Resources• GLFW quick start:

• http://www.glfw.org/docs/latest/quick.html

• Fractals Programming:

• http://natureofcode.com/book/chapter-8-fractals/

• Parametric Equations:

• https://en.wikipedia.org/wiki/Parametric_equation