cs u540 computer graphics
Download
Skip this Video
Download Presentation
CS U540 Computer Graphics

Loading in 2 Seconds...

play fullscreen
1 / 23

CS U540 Computer Graphics - PowerPoint PPT Presentation


  • 102 Views
  • Uploaded on

CS U540 Computer Graphics. Prof. Harriet Fell Spring 2009 Lecture 19 – February 12, 2009. Vectors. A vector describes a length and a direction. a zero length vector. a. b. 1. a unit vector. a = b. a. -d. d. c. Vector Difference. a. -a. Vector Operations. b. b+a. a. c-d. b.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CS U540 Computer Graphics' - chico


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
cs u540 computer graphics

CS U540Computer Graphics

Prof. Harriet Fell

Spring 2009

Lecture 19 – February 12, 2009

vectors
Vectors
  • A vector describes a length and a direction.

a zero length vector

a

b

1

a unit vector

a = b

vector operations

a

-d

d

c

Vector Difference

a

-a

Vector Operations

b

b+a

a

c-d

b

Vector Sum

cartesian coordinates
Cartesian Coordinates
  • Any two non-zero, non-parallel 2D vectors form a 2D basis.
  • Any 2D vector can be written uniquely as a linear combination of two 2D basis vectors.
  • x and y (or i and j) denote unit vectors parallel to the x-axis and y-axis.
  • x and y form an orthonormal 2D basis.

a = xax + yay

a =( xa, ya) or

  • x, y and z form an orthonormal 3D basis.

or a =(ax,ay)

vector length
Vector Length

Vector a =( xa, ya )

||a||

ya

a

xa

dot product

a

b

Dot Product

Dot Product

a =( xa, ya ) b =( xb, yb )

ab = xa xb + ya yb

ab = abcos()

xa= acos(+)

xb= bcos()

xa= asin(+)

xb= bsin()

projection

a

b

ab

Projection

a =( xa, ya ) b =( xb, yb )

ab = abcos()

The length of the projection of a onto b is given by

3d vectors
3D Vectors

This all holds for 3D vectors too.

a =( xa, ya, za ) b =( xb, yb, zb )

ab = xa xb + ya yb + za zb

ab = abcos()

vector cross product
Vector Cross Product

axb

axb is perpendicular to a and b.

Use the right hand rule to determine the direction of axb.

b

a

Image from www.physics.udel.edu

cross product and area

b

||a||

a

Cross Product and Area

axb

b

a

||a||x||b|| = area pf the parallelogram.

linear interpolation

b

(1-t)L

tL

L

a

Linear Interpolation
  • LERP: /lerp/, vi.,n.
    • Quasi-acronym for Linear Interpolation, used as a verb or noun for the operation. “Bresenham\'s algorithm lerps incrementally between the two endpoints of the line.”

p = (1 – t) a + t b = a + t(b – a)

lerp demo

t = 1

t = .75

t = .5

t = .25

t = 0

Lerp Demo

p = (1 – t) a + t b = a + t(b – a)

b

L

a

triangles
Triangles

a

If (x, y) is on the edge ab,

(x, y) = (1 – t) a + t b = a + t(b – a).

Similar formulas hold for points on the other edges.

If (x, y) is in the triangle:

(x, y) =  a +  b +  c

 +  +  = 1

( ,  ,  ) are the

Barycentriccoordinates of (x, y).

(x,y)

c

b

triangles1
Triangles

p = a + (b-a) + (c-a)

 = 2

 = 1

 = 0

 = -1

 = 2

p = (1- - )a + b + c

 = 1-  - 

p = p(, ,) =

a + b + c

 = 1

c

c-a

 = 0

b

b-a

a

Barycentric coordinates

 = -1

 = 0

 = 1

barycentric coordinates as areas
Barycentric Coordinates as Areas

a

(x,y)

where A is the area of the

triangle.

 +  +  = 1

c

b

3d triangles
3D Triangles

a

This all still works in 3D.

(x,y,z)

where A is the area of the

triangle.

 +  +  = 1

c

b

But how do we find the areas of the triangles?

3d triangles areas
3D Triangles - Areas

axb

B

b

C

a

A

triangle assignment
Triangle Assignment

http://www.ccs.neu.edu/home/fell/CSU540/programs/CSU540ColorTriangle.html

portable pixmap format ppm
Portable Pixmap Format (ppm)

A "magic number" for identifying the file type.

  • A ppm file\'s magic number is the two characters "P3".
  • Whitespace (blanks, TABs, CRs, LFs).
  • A width, formatted as ASCII characters in decimal.
  • Whitespace.
  • A height, again in ASCII decimal.
  • Whitespace.
  • The maximum color value again in ASCII decimal.
  • Whitespace.
  • Width * height pixels, each 3 values between 0 and maximum value.
    • start at top-left corner; proceed in normal English reading order
    • three values for each pixel for red, green, and blue, resp.
    • 0 means color is off; maximum value means color is maxxed out
    • characters from "#" to end-of-line are ignored (comments)
    • no line should be longer than 70 characters
ppm example
ppm Example

P3

# feep.ppm

4 4

15

0 0 0 0 0 0 0 0 0 15 0 15

0 0 0 0 15 7 0 0 0 0 0 0

0 0 0 0 0 0 0 15 7 0 0 0

15 0 15 0 0 0 0 0 0 0 0 0

slide23

private void saveImage() {

String outFileName = “my.ppm";

File outFile = new File(outFileName);

int clrR, clrG, clrB;

try {

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));

out.println("P3");

out.print(Integer.toString(xmax-xmin+1)); System.out.println(xmax-xmin+1);

out.print(" ");

out.println(Integer.toString(ymax-ymin+1)); System.out.println(ymax-ymin+1);

out.println("255");

for (int y = ymin; y <= ymax; y++){

for (int x = xmin; x <= xmax; x++) {

// compute clrR, clrG, clrB

out.print(" "); out.print(clrR);

out.print(" "); out.print(clrG);

out.print(" "); out.println(clrB);

}

}

out.close();

} catch (IOException e) {

System.out.println(e.toString());

}

}

ad