- Assignment 3.

A point is a location in space; what is the difference between two points?

- a vector

Both are designated by two real numbers (in the plane); what's the difference?

- consider translations in the plane
- points change
- vectors don't

- Computer example - addresses and offsets
- offsets are the difference between addresses
- create position independent (relocatable) code by using only offsets.

Thus, we have two kinds of entities, both represented by the same notation. To differentiate

- (x, y, 1) is a point.
- (x, y, 0) is a vector.

Does this make sense?

- P - P -> V
- P + V -> P
- V + V -> V
- P + P doesn't make sense: it gives (x + x', y + y', 2), which isn't defined
- aV -> V
- aP doesn't make sense: it gives (ax, ay, a), which is only defined if a=1..

Important finicky (and practical) point

- The interface we create is, in theory, position independent, but
- to appear on a screen it must be attached to a particular position.

- Thus, when we write
`DrawRectangle( window, x, y, width, height );`

`window`

- indicates the origin to use`x, y`

- is a point at which to start drawing`width, height`

- define vectors that are combined with the starting point to make new points

What does this tell us about graphical user interfaces (more precisely, interfaces that use direct manipulation)?

- doing graphics
- separate DrawRectangle into two parts.
- a point part to place the first vertex
- a vector part to get from the first vertex to each subsequent vertex

- separate `click and drag' into two parts
- a point part to locate the object to be dragged
- a vector part to update geometry while dragging occurs

- make moving the object a vector operation, which depends on the
position of a single reference point
- usually the upper left corner of the enclosing rectangle
- moving the object simply moves the reference point
- implemented in all graphics hardware as bitblt

- separate DrawRectangle into two parts.
- analysing input
- Where a gesture starts is a point.
- When the tracker is sampled the
*n*'th time, the vector from sample*n*-1 to sample*n*is added to the description of the object. - The we have its location, the first point, separated from the object, the vectors, which is translationally invariant.
- Remember the special properties of invariances like
- translation,
- rotation
- scaling

- When the tracker is sampled the
- Getting gestures in a well-defined geometry means that we can apply
them directly to stuff on the display.
- The next few sections show how to do it.

- Where a gesture starts is a point.

We (for some value of we) know a powerful formalism for manipulating the vector part

- linear algebra
- rotation
- scaling
- reflection

- But, remember that vecors are nowhere, so it doesn't matter where the centre of rotation is.

What you may or may not have learned in vector geometry

(x,y) -> (-x,y)

(x,y,0) -> (-x,y,0)

( -1 0 ) (x) (-x) ( 0 1 ) (y) = ( y) ( ) ( ) ( )

( -1 0 ? ) ( x) (-x) ( 0 1 ? ) ( y) = ( y) ( 0 0 ? ) ( 0) ( 0)

(x,y) -> (Ax,Ay)

(x,y,0) -> (Ax,Ay,0)

( A 0 ) (x) (Ax) ( 0 A ) (y) = (Ay) ( ) ( ) ( )

( A 0 ? ) ( x) (Ax) ( 0 A ? ) ( y) = (Ay) ( 0 0 ? ) ( 0) ( 0)

(x,y) -> (x cos(a) - y sin(a),x sin(a) + y cos(a))

(x,y,0) -> (x cos(a) - y sin(a),x sin(a) + y cos(a),0)

( cos(a) -sin(a) ) (x) (x cos(a) - y sin(a)) ( sin(a) cos(a) ) (y) = (x sin(a) + y cos(a)) ( ) ( ) ( )

( cos(a) -sin(a) ? ) ( x) (x cos(a) - y sin(a)) ( sin(a) cos(a) ? ) ( y) = (x sin(a) + y cos(a)) ( 0 0 ? ) ( 0) ( 0 )

T0 transform points we need reference locations

- Reflection: line of reflection: the x-axis
- Scaling: centre of scaling: the origin
- Rotation: centre of rotation: the origin

(x,y,1) -> (-x,y,1)

( -1 0 0 ) ( x) (-x) ( 0 1 0 ) ( y) = ( y) ( 0 0 1 ) ( 1) ( 1)

(x,y,1) -> (Ax,Ay,1)

( A 0 0 ) ( x) (Ax) ( 0 A 0 ) ( y) = (Ay) ( 0 0 1 ) ( 1) ( 1)

(x,y,1) -> (x cos(a) - y sin(a),x sin(a) + y cos(a),1)

( cos(a) -sin(a) 0 ) ( x) (x cos(a) - y sin(a)) ( sin(a) cos(a) 0 ) ( y) = (x sin(a) + y cos(a)) ( 0 0 1 ) ( 1) ( 1 )

Points have one more property: their location with respect to the coordinate system.

- A point changes when we translate it, which is different than a vector.

(x,y,1) -> (x + a, y +b,1)

( 1 0 a ) ( x) (x + a) ( 0 1 b ) ( y) = (y + b) ( 0 0 1 ) ( 1) ( 1 )

There are two ways to rotate a rectangle which is away from the origin.

- Consider it as a collection of points
- Translate to the origin
- Rotate at the origin
- Translate back to where it started

- Consider it as one point plus a collection of vectors
- Rotate the vectors

They `obviously' give the same answer. (Exercise left to the reader.)

You will find both representations in PostScript because one is sometimes more convenient than the other.

But for making a graphical interface it's usually better to stick to one or the other.

Last lecture we talked about points and vectors, how they transform.

How does this help us make graphical user interfaces (more precisely, interfaces that use direct manipulation)?

Let's think for a minute about assignment 5. What needs to be done?

- drawing
- using painter's algorithm and Xlib - need to know parameters like x, y, width, height

- selecting
- depends on an inside test

- transforming
- translate
- rotate
- rescale
- reflect

Here's how we do it.

- Base all things you draw on a small number of basic figures, such as
- a standard line running from (0, 0) to (1, 0)
- a standard rectangle with corners at (0, 0), (0, 1), (1, 1), (1, 0)

- a standard ellipse with zero eccentricity (a circle), centred at (0, 0), of radius 1.
- and so on.

- Use transformations to turn this into any quadrilateral shape
- represent transformations by matrices 3x3
- translation by dx, dy
- point: (x, y, 1) -> (x + dx, y + dy, 1)
- vector: (x, y, 0) -> (x, y, 0)
- Matrix that does this must do its thing in the bottom row

- rotation by t
- point: (x, y, 1) -> (x cos(t) - y sin(t), x sin(t) + y cos(t), 1)
- vector: (x, y, 0) -> (x cos(t) - y sin(t), x sin(t) + y cos(t), 0)
- Matrix that does this must do its thing in the 2x2 part.

- reflect about y-axis
- point: (x, y, 1) -> (-x, y, 1)
- vector: (x, y, 0) -> (-x, y, 0)
- Matrix that does this must do its thing on the diagonal of the 2x2 part

- rescale by a along the x-axis
- point: (x, y, 1) -> (ax, y, 1)
- vector: (x, y, 0) -> (a, y, 0)

Matrix that does this must do its thing on the diagonal of the 2x2 part

- translation by dx, dy

- represent transformations by matrices 3x3

The matrices you need (transposed if you like column vectors rather than row vectors)

- Translation (points only)
( 1.0 0.0 0.0 ) ( 0.0 1.0 0.0 ) ( dx dy 1.0 )

- Rotation about the origin
( cos(t) sin(t) 0.0 ) ( -sin(t) cos(t) 0.0 ) ( 0.0 0.0 1.0 )

- Scale along the x-axis
( a 0.0 0.0 ) ( 0.0 1.0 0.0 ) ( 0.0 0.0 1.0 )

- Reflect about the y-axis
( -1.0 0.0 0.0 ) ( 0.0 1.0 0.0 ) ( 0.0 0.0 1.0 )

These are standard transformations. How do we do more interesting and useful work?

- Make the transformations we want as compositions of the basic transformations
- Examples.
- Rotation about an arbitrary point.
- Scaling along an arbitrary direction.
- Scaling about an arbitrary point and along an arbitrary direction.
- Reflection in an arbitrary line.

These matrices transform points and vectors. Let's see how we do drawing.

- Store the standard shape in terms of points and vectors.
- Know how to draw the standard shape in terms of its points and vectors.
- Store with it a transformation matrix that turns it into the actual shape.
- Draw the actual shape using the transformed points and vectors.

And let's see how we do the inside test. (We could just use the transformed points, but there's an easier way to do it.)

- Fact. The transformations above - when applied to a point and a shape - do not affect whether or not the point is inside the shape.
- This gives us two options for doing the inside test
- Transform the standard shape into the point's world, using the transformation matrix stored with the point.
- Transform the point into the standard shape's world, using the inverse of the transformation matrix.

We prefer the second, because we can choose the standard object so that the inside test is easy.

Therefore store the inverse matrix with the shape, along with the transformation matrix.

Exercises.

- What is the inverse matrix of each of the basic matrices?
- How do we multiply inverse matrices?

Return to: