geometric objects and transformations · pdf filegeometric objects- scalars points are useful...

Post on 06-Mar-2018

228 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

GEOMETRIC OBJECTS AND

TRANSFORMATIONS

Introduction

In computer graphics many applications need to alter or

manipulate a picture, for example, by changing its size,

position or orientation.

This can be done by applying a geometric transformation to

the coordinate points defining the picture.

Definition: Geometry

The branch of mathematics concerned with the properties of and

relationships between points, lines, planes, and figures.

2

Geometric Objects- Points

Point is a fundamental geometric object.

In a three-dimensional geometric system, a point is a location

in space.

The only property that a point possesses is that point’s

location; a mathematical point has neither a size nor a shape.

3

Geometric Objects- Scalars

Points are useful in specifying geometric objects but are not

sufficient by themselves. We need real numbers to specify

quantities such as the distance between two points.

Real numbers—and complex numbers, which we will use

occasionally—are examples of scalars.

Scalars are objects that obey a set of rules that are abstractions

of the operations of ordinary arithmetic

4

Geometric Objects- Vectors

Vectors allow us to work with directions.

Physicists and mathematicians use the term vector for any

quantity with direction and magnitude. Physical quantities,

such as velocity and force, are vectors. A vector does not,

however, have a fixed location in space

In computer graphics, we often connect points with directed

line segments, A directed line segment has both magnitude—

its length—and direction—its orientation—and thus is a

vector.

5

The Computer Science View :

Vector ,Scalar , Point

Computer scientist prefers to see vector , scalar and point as

abstract data types (ADTs).

An ADT is a set of operations on data; the operations are

defined independently of how the data are represented

internally or of how the operations are implemented.

The notion of data abstraction is fundamental to modern

computer science. For example, the operation of adding an

element to a list or of multiplying two polynomials can be

defined independently of how the list is stored or of how real

numbers are represented on a particular computer

6

The Computer Science View :

Vector ,Scalar , Point

From a computational point of view, we

should be able to declare geometric objects through code such

as

vector u,v;

point p,q;

scalar a,b;

7

Dot and cross products

Many of the geometric concepts relating the orientation

between two vectors are in terms of the dot (inner) and cross

(outer) products of two vectors.

The dot product of u and v is written u . v. If u . v = 0, u and v

are said to be orthogonal.

In a Euclidean space, the magnitude of a vector is defined.

The square of the magnitude of a vector is given by the dot

product

|u|2 = u . u.

The cosine of the angle between two vectors is given by

cos θ = u . v

|u||v|

8

Dot and cross products con..

In addition, |u| cos θ = u . v/|v| is the length of the orthogonal

projection of u onto v, as shown in figure below .

Thus, the dot product expresses the geometric result that the

shortest distance from a point (the end of the vector u) to the

line segment v is obtained by drawing the vector orthogonal to

v from the end of u

9

In a vector space, a set of vectors is linearly independent if

we cannot write one of the vectors in terms of the others using

scalar-vector addition. A vector space has a dimension, which

is the maximum number of linearly independent vectors that

we can find.

Given any three linearly independent vectors in a three-

dimensional space, we can use the dot product to construct

three vectors, each of which is orthogonal to the other two.

Dot and cross products con..

10

We can also use two nonparallel vectors, u and v, to determine

a third vector n that is orthogonal to them.This vector is the

cross product

n = u × v.

The magnitude of the cross

product gives the magnitude of the sine of the angle θ between

u and v

| sin θ| = |u × v|

|u||v|

Dot and cross products con..

11

Three dimensional Primitives

Three features characterize three-dimensional objects that fit

well with existing graphics hardware and software:

1.The objects are described by their surfaces and can be

thought of as being hollow

2.The objects can be specified through a set of vertices in

three dimensions.

3. The objects either are composed of or can be approximated

by flat, convex polygons

12

Three dimensional Primitives

Curves in 3D Surface in 3 D Volumetric object

13

Coordinates free geometry

Points exist in space regardless of any reference or coordinate

system. Thus, we do not need a coordinate system to specify a

point or a vector.

Object and coordinate system Object without coordinate system

14

Homogenous Coordinates

Let’s move our problem into 3D.

Let point (x, y) in 2D be represented by point (x, y, 1) in the new

space.

Scaling our new point by any value a puts us somewhere along a

particular line: (ax, ay, a).

A point in 2D can be represented in many ways in the new space.

(2, 4) ---------- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.

y y

x

x

w

15

Homogenous Coordinates

We can always map back to the original 2D point by dividing

by the last coordinate

(15, 6, 3) --- (5, 2).

(60, 40, 10) - ?.

Why do we use 1 for the last coordinate?

The fact that all the points along each line can be mapped

back to the same point in 2D gives this coordinate system its

name – homogeneous coordinates.

16

Frames In OpenGl

OpenGL is based on a pipeline model, the first part of which

is a sequence of operations on vertices, many of which are

geometric.

We can characterize such operations by a sequence of

transformations or as a sequence of changes of frames for the

objects specified by an application program.

17

Frames In Open Gl Pipeline

1.Object (or model) coordinates

2. World coordinates

3. Eye (or camera) coordinates

4. Clip coordinates

5. Normalized device coordinates

6. Window (or screen) coordinates

18

Data Structures for object representation

19

2D Transformations

What is transformations?

The geometrical changes of an object from a current state to

modified state.

A rule for moving every point in a plane figure to a new

location.

20

Affine transformation

In geometry, an affine transformation is a transformation

which preserves straight lines (all points lying on a line

initially still lie on a line after transformation) and ratios of

distances between points lying on a straight line. It does not

necessarily preserve angles or lengths, but does have the

property that sets of parallel lines will remain parallel to each

other after an affine transformation.

21

Affine transformation con..

Examples of affine transformations include translation,

geometric contraction, expansion, reflection, rotation

An affine transformation is equivalent to a linear

transformation followed by a translation

22

Types of Transformation

Translation

Rotation

Scaling

23

Translation

A translation moves all points in an

object along the same straight-line

path to new positions.

The path is represented by a vector,

called the translation or shift vector.

We can write the components:

p'x = px + tx

p'y = py + ty

or in matrix form:

P' = P + T

tx

ty

x’

y’

x

y

tx

ty = +

(2, 2)= 6

=4

?

24

Translation con…

In a translation a figure slides up or down, or left or

right. No change in shape or size. The location

changes.

In graphing translation, all x and y coordinates of a

translated figure change by adding or subtracting.

25

Rotation

A rotation repositions all

points in an object along a

circular path in the plane

centered at the pivot point.

First, we’ll assume the

pivot is at the origin.

P

P’

26

Rotation• Review Trigonometry

=> cos = x/r , sin = y/r

• x = r. cos , y = r.sin

P(x,y)

x

yr

x’

y’

P’(x’, y’)

r

=> cos (+ ) = x’/r

•x’ = r. cos (+ )

•x’ = r.coscos -r.sinsin

•x’ = x.cos – y.sin

=>sin (+ ) = y’/r

y’ = r. sin (+ )

•y’ = r.cossin + r.sincos

•y’ = x.sin + y.cos

Identity of Trigonometry

27

Rotation• We can write the components:

p'x = px cos – py sin

p'y = px sin + py cos

• or in matrix form:

P' = R • P

• Rotation matrix

P(x,y)

x

yr

x’

y’

P’(x’, y’)

cossin

sincosR

28

Rotation

Example

Find the transformed point, P’, caused by rotating P= (5,

1) about the origin through an angle of 90.

cossin

sincos

cossin

sincos

yx

yx

y

x

90cos190sin5

90sin190cos5

0115

1105

5

1

29

Chapter 4 - 30

Rotating about another point

How can I rotate around another fixed point, e.g. [1, 2, 3]?

Translate [1, 2, 3] -> 0, 0, 0 (T)

Rotate (R)

Translate back (T-1)

T-1 R T P = P'

Chapter 4 - 31

Rotating about another axis

How can I rotate about an arbitrary axis?

Can combine rotationsabout z, y, and x:Rx Ry Rz P = P'

Note that ordermatters and anglescan be hard to find

Scaling• Scaling changes the size of an

object and involves two scale

factors, Sx and Sy for the x-

and y- coordinates

respectively.

• Scales are about the origin.

• We can write the components:

p'x = sx • px

p'y = sy • py

or in matrix form:

P' = S • P

Scale matrix as:

y

x

s

sS

0

0

P

P’

32

Scaling• If the scale factors are in between 0

and 1 the points will be moved closer to the origin the object will be smaller.

P(2, 5)

P’

• Example :

•P(2, 5), Sx = 0.5, Sy = 0.5

•Find P’ ?

33

Scaling• If the scale factors are in between 0

and 1 the points will be moved closer to the origin the object will be smaller.

P(2, 5)

P’

• Example :

•P(2, 5), Sx = 0.5, Sy = 0.5

•Find P’ ?

•If the scale factors are larger than 1

the points will be moved away from

the origin the object will be larger.

P’

• Example :

•P(2, 5), Sx = 2, Sy = 2

•Find P’ ?

34

Scaling

• If the scale factors are the same, Sx

= Sy uniform scaling

• Only change in size (as previous

example)

P(1, 2)

P’

•If Sx Sy differential scaling.

•Change in size and shape

•Example : square rectangle

•P(1, 3), Sx = 2, Sy = 5 , P’ ?

35

Matrix Math

Why do we use matrix?

More convenient organization of data.

More efficient processing

Enable the combination of various concatenations

Matrix addition and subtraction

a

b

c

d

a c

b d=

36

Matrix Math

Type of matrix

a ba

b

Row-vector Column-vector

37

Matrix Representation of Transformations

Translation

1100

10

01

1

y

x

t

t

y

x

y

x

38

Matrix Representation

Rotation

Scaling

1100

0cossin

0sincos

1

y

x

y

x

z

y

x

Sz

s

s

z

y

x

y

x

00

00

00

39

Composite Transformation

We can represent any sequence of transformations as a single matrix.

No special cases when transforming a point – matrix • vector.

Composite transformations – matrix • matrix.

Composite transformations:

Rotate about an arbitrary point – translate, rotate, translate

Scale about an arbitrary point – translate, scale, translate

40

Virtual Trackball

The use of the mouse position to control rotation about two

axes provides us with most of the functionality of a trackball.

One of the benefits of such a device is that we can create a

frictionless trackball that, once we start it rotating, will

continue to rotate until stopped by the user.

The device will support continuous rotations of objects but

will still allow changes in the speed and orientation of the

rotation.

We can also do the same for translation and other

parameters that we can control from the mouse

41

Virtual Trackball42

top related