transformations - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ecm2410/slides04.pdf ·...

Post on 30-Jul-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

ECM2410: Graphics and Animation

Transformations

Part I

Transformations 1/15

Transformations

Coordinate systems

The reason

Vectors and matrices

The maths

Homogeneous coordinates

A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems

The reason

Vectors and matrices

The maths

Homogeneous coordinates

A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices

The maths

Homogeneous coordinates

A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices

The maths

Homogeneous coordinates

A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates

A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates

A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D

The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D The API

Clocks

An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D The API

Clocks An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D The API

Clocks An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D The API

Clocks An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Transformations

Coordinate systems The reason

Vectors and matrices The maths

Homogeneous coordinates A trick

Java2D The API

Clocks An example

ReferencesHearn & Baker, Computer Graphics, Chapter 5.Foley et al, Computer Graphics, Chapter 5.

Introduction Transformations 2/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Coordinate Systems

User space

Device space

User space (world coordinates)Space in which parts of scene are modelledMoveable: location set with affineTransform class.

Device space (screen coordinates)Coordinates in which picture is renderedSize set with java.awt.setSize()

Introduction Transformations 3/15

Building Complex Objects

Device Coordinates

Construct complex objects from simpler ones, each havingits own local coordinate system.

Transform objects into place.

Introduction Transformations 4/15

Building Complex Objects

Device Coordinates

Construct complex objects from simpler ones, each havingits own local coordinate system.

Transform objects into place.

Introduction Transformations 4/15

Building Complex Objects

Device Coordinates

Construct complex objects from simpler ones, each havingits own local coordinate system.

Transform objects into place.

Introduction Transformations 4/15

Building Complex Objects

Device Coordinates

Construct complex objects from simpler ones, each havingits own local coordinate system.

Transform objects into place.

Introduction Transformations 4/15

Coordinates and Points

Cartesian Coordinates

(3,2)

3

2

(0,0)

a

a =

(32

)

The Point class represents a 2-dimensional point or vector:

a = new Point2D.Double(3.0, 2.0);double ax = a.getX(); // 3.0double ay = a.getY(); // 2.0

Introduction Transformations 5/15

Coordinates and Points

Cartesian Coordinates

(3,2)

3

2

(0,0)

a

a =

(32

)

The Point class represents a 2-dimensional point or vector:

a = new Point2D.Double(3.0, 2.0);double ax = a.getX(); // 3.0double ay = a.getY(); // 2.0

Introduction Transformations 5/15

Coordinates and Points

Cartesian Coordinates

(3,2)

3

2

(0,0)

aa =

(32

)

The Point class represents a 2-dimensional point or vector:

a = new Point2D.Double(3.0, 2.0);double ax = a.getX(); // 3.0double ay = a.getY(); // 2.0

Introduction Transformations 5/15

Coordinates and Points

Cartesian Coordinates

(3,2)

3

2

(0,0)

aa =

(32

)

The Point class represents a 2-dimensional point or vector:

a = new Point2D.Double(3.0, 2.0);double ax = a.getX(); // 3.0double ay = a.getY(); // 2.0

Introduction Transformations 5/15

Coordinates and Points

Cartesian Coordinates

(3,2)

3

2

(0,0)

aa =

(32

)

The Point class represents a 2-dimensional point or vector:

a = new Point2D.Double(3.0, 2.0);double ax = a.getX(); // 3.0double ay = a.getY(); // 2.0

Introduction Transformations 5/15

Coordinates and Points

Cartesian Coordinates

(3,2)

3

2

(0,0)

aa =

(32

)

The Point class represents a 2-dimensional point or vector:

a = new Point2D.Double(3.0, 2.0);double ax = a.getX(); // 3.0double ay = a.getY(); // 2.0

Introduction Transformations 5/15

Coordinates and Points

Cartesian Coordinates

(3,2)

3

2

(0,0)

aa =

(32

)

The Point class represents a 2-dimensional point or vector:

a = new Point2D.Double(3.0, 2.0);double ax = a.getX(); // 3.0double ay = a.getY(); // 2.0

Introduction Transformations 5/15

Matrices

Find[12

]

[1 −3−5 4

]

Matrices Transformations 6/15

Matrices

Find[12

]

[1 −3−5 4

]

Matrices Transformations 6/15

Matrices

Find[12

]

[1 −3−5 4

]

Matrices Transformations 6/15

Matrices

Find[12

] [1 −3−5 4

]

Matrices Transformations 6/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]

=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]

=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]

=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Matrix Transformations

Matrices: operators for transforming vectors

[1 −3−5 4

] [12

]=

[−53

]

Ax = x′

x local coordinatesx′ screen coordinates

Matrices Transformations 7/15

Dilbert

public class DilbertTransextends JComponent {

dilbert D = new Dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

D.setColour(Color.black);D.paint(g2); // Screen coordinates

AffineTransform A = new AffineTransform();// Manipulate transformationg2.setTransform(A); // Apply transformD.setColour(Color.magenta);D.paint(g2);

}

Matrices Transformations 8/15

Dilbert

public class DilbertTransextends JComponent {

dilbert D = new Dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

D.setColour(Color.black);D.paint(g2); // Screen coordinates

AffineTransform A = new AffineTransform();// Manipulate transformationg2.setTransform(A); // Apply transformD.setColour(Color.magenta);D.paint(g2);

}

Matrices Transformations 8/15

Dilbert

public class DilbertTransextends JComponent {

dilbert D = new Dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

D.setColour(Color.black);D.paint(g2); // Screen coordinates

AffineTransform A = new AffineTransform();// Manipulate transformationg2.setTransform(A); // Apply transformD.setColour(Color.magenta);D.paint(g2);

}

Matrices Transformations 8/15

Dilbert

public class DilbertTransextends JComponent {

dilbert D = new Dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

D.setColour(Color.black);D.paint(g2); // Screen coordinates

AffineTransform A = new AffineTransform();// Manipulate transformationg2.setTransform(A); // Apply transformD.setColour(Color.magenta);D.paint(g2);

}

Matrices Transformations 8/15

Dilbert

public class DilbertTransextends JComponent {

dilbert D = new Dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

D.setColour(Color.black);D.paint(g2); // Screen coordinates

AffineTransform A = new AffineTransform();// Manipulate transformationg2.setTransform(A); // Apply transformD.setColour(Color.magenta);D.paint(g2);

}

Matrices Transformations 8/15

Dilbert

public class DilbertTransextends JComponent {

dilbert D = new Dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

D.setColour(Color.black);D.paint(g2); // Screen coordinates

AffineTransform A = new AffineTransform();// Manipulate transformationg2.setTransform(A); // Apply transformD.setColour(Color.magenta);D.paint(g2);

}

Matrices Transformations 8/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]

Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]

Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]

Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]

Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotation Matrices

x′ = Rx[x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]

=

[x cos θ − y sin θx sin θ + y cos θ

]Rotation by θ

Rotation matrices leave the length of the vector unchanged.

|x′|2 = (x cos θ − y sin θ)2 + (x sin θ + y cos θ)2

= x2 + y2

= |x|2

Matrices Transformations 9/15

Rotations

Dilbert D =new Dilbert("./dilbert.txt");

. . .

AffineTransformation A =new AffineTransformation();

A.rotation(-Math.PI/12);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

Angles in radians:π radians = 180◦

Java2D rotationsincrease clockwise

Matrices Transformations 10/15

Rotations

Dilbert D =new Dilbert("./dilbert.txt");

. . .

AffineTransformation A =new AffineTransformation();

A.rotation(-Math.PI/12);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

Angles in radians:π radians = 180◦

Java2D rotationsincrease clockwise

Matrices Transformations 10/15

Rotations

Dilbert D =new Dilbert("./dilbert.txt");

. . .

AffineTransformation A =new AffineTransformation();

A.rotation(-Math.PI/12);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

Angles in radians:π radians = 180◦

Java2D rotationsincrease clockwise

Matrices Transformations 10/15

Rotations

Dilbert D =new Dilbert("./dilbert.txt");

. . .

AffineTransformation A =new AffineTransformation();

A.rotation(-Math.PI/12);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

Angles in radians:π radians = 180◦

Java2D rotationsincrease clockwise

Matrices Transformations 10/15

Rotations

Dilbert D =new Dilbert("./dilbert.txt");

. . .

AffineTransformation A =new AffineTransformation();

A.rotation(-Math.PI/12);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

Angles in radians:π radians = 180◦

Java2D rotationsincrease clockwise

Matrices Transformations 10/15

Rotations

Dilbert D =new Dilbert("./dilbert.txt");

. . .

AffineTransformation A =new AffineTransformation();

A.rotation(-Math.PI/12);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

Angles in radians:π radians = 180◦

Java2D rotationsincrease clockwise

Matrices Transformations 10/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling

A.scale(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint();

[x ′

y ′

]=

[λxµy

]=

[λ 00 µy

] [xy

]

Diagonal matrices scale thevectorEqual entries on diagonal giveisotropic scalingUnequal entries on diagonal giveanisotropic scalingDilbert was scaled by:A.scale(2.0, 0.5);

Matrices Transformations 11/15

Scaling to fit window

public class DilbertAutoscale extends JComponent {private Dilbert D = new dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

GeneralPath path = D.getpath(); // Path describing dilbertRectangle2D bbox = path.getBounds2D(); // Bounding box

AffineTransform A = new AffineTransform();A.scale(0.9*getWidth() / bbox.getMaxX(),

0.9*getHeight() / bbox.getMaxY());g2.transform(A);

D.setColour(Color.blue);D.paint(g2);

}

Exercise:Modify DilbertAutoScale to preserve Dilbert’s aspect ratio.

Matrices Transformations 12/15

Scaling to fit window

public class DilbertAutoscale extends JComponent {private Dilbert D = new dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

GeneralPath path = D.getpath(); // Path describing dilbertRectangle2D bbox = path.getBounds2D(); // Bounding box

AffineTransform A = new AffineTransform();A.scale(0.9*getWidth() / bbox.getMaxX(),

0.9*getHeight() / bbox.getMaxY());g2.transform(A);

D.setColour(Color.blue);D.paint(g2);

}

Exercise:Modify DilbertAutoScale to preserve Dilbert’s aspect ratio.

Matrices Transformations 12/15

Scaling to fit window

public class DilbertAutoscale extends JComponent {private Dilbert D = new dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

GeneralPath path = D.getpath(); // Path describing dilbertRectangle2D bbox = path.getBounds2D(); // Bounding box

AffineTransform A = new AffineTransform();A.scale(0.9*getWidth() / bbox.getMaxX(),

0.9*getHeight() / bbox.getMaxY());g2.transform(A);

D.setColour(Color.blue);D.paint(g2);

}

Exercise:Modify DilbertAutoScale to preserve Dilbert’s aspect ratio.

Matrices Transformations 12/15

Scaling to fit window

public class DilbertAutoscale extends JComponent {private Dilbert D = new dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

GeneralPath path = D.getpath(); // Path describing dilbertRectangle2D bbox = path.getBounds2D(); // Bounding box

AffineTransform A = new AffineTransform();A.scale(0.9*getWidth() / bbox.getMaxX(),

0.9*getHeight() / bbox.getMaxY());g2.transform(A);

D.setColour(Color.blue);D.paint(g2);

}

Exercise:Modify DilbertAutoScale to preserve Dilbert’s aspect ratio.

Matrices Transformations 12/15

Scaling to fit window

public class DilbertAutoscale extends JComponent {private Dilbert D = new dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

GeneralPath path = D.getpath(); // Path describing dilbertRectangle2D bbox = path.getBounds2D(); // Bounding box

AffineTransform A = new AffineTransform();A.scale(0.9*getWidth() / bbox.getMaxX(),

0.9*getHeight() / bbox.getMaxY());g2.transform(A);

D.setColour(Color.blue);D.paint(g2);

}

Exercise:Modify DilbertAutoScale to preserve Dilbert’s aspect ratio.

Matrices Transformations 12/15

Scaling to fit window

public class DilbertAutoscale extends JComponent {private Dilbert D = new dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

GeneralPath path = D.getpath(); // Path describing dilbertRectangle2D bbox = path.getBounds2D(); // Bounding box

AffineTransform A = new AffineTransform();A.scale(0.9*getWidth() / bbox.getMaxX(),

0.9*getHeight() / bbox.getMaxY());g2.transform(A);

D.setColour(Color.blue);D.paint(g2);

}

Exercise:Modify DilbertAutoScale to preserve Dilbert’s aspect ratio.

Matrices Transformations 12/15

Scaling to fit window

public class DilbertAutoscale extends JComponent {private Dilbert D = new dilbert("./dilbert.txt");. . .

public void paint(Graphics g) {Graphics2D g2 = (Graphics2D)g;

GeneralPath path = D.getpath(); // Path describing dilbertRectangle2D bbox = path.getBounds2D(); // Bounding box

AffineTransform A = new AffineTransform();A.scale(0.9*getWidth() / bbox.getMaxX(),

0.9*getHeight() / bbox.getMaxY());g2.transform(A);

D.setColour(Color.blue);D.paint(g2);

}

Exercise:Modify DilbertAutoScale to preserve Dilbert’s aspect ratio.

Matrices Transformations 12/15

Axis Aligned Bounding Box

Smallest axis-parallel rectangle containing the object

Matrices Transformations 13/15

Axis Aligned Bounding Box

Smallest axis-parallel rectangle containing the object

Matrices Transformations 13/15

Axis Aligned Bounding Box

Smallest axis-parallel rectangle containing the object

Matrices Transformations 13/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Shear

A.shear(λ, µ);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + λy

y

]=

[1 λ0 1

] [xy

][

x ′

y ′

]=

[x

µx + y

]=

[1 0µ 1

] [xy

]

One coordinate is leftunchanged.

Dilbert was sheared with[1 10 1

]A.shear(1, 0);

Matrices Transformations 14/15

Translation

A.translate(150.0, 50.0);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + txy + ty

]

=

[xy

] [txty

]x′ = x + t

Matrices Transformations 15/15

Translation

A.translate(150.0, 50.0);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + txy + ty

]

=

[xy

] [txty

]x′ = x + t

Matrices Transformations 15/15

Translation

A.translate(150.0, 50.0);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + txy + ty

]

=

[xy

] [txty

]x′ = x + t

Matrices Transformations 15/15

Translation

A.translate(150.0, 50.0);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + txy + ty

]

=

[xy

] [txty

]x′ = x + t

Matrices Transformations 15/15

Translation

A.translate(150.0, 50.0);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + txy + ty

]

=

[xy

] [txty

]x′ = x + t

Matrices Transformations 15/15

Translation

A.translate(150.0, 50.0);g2.transform(A);D.setColour(Color.magenta);D.paint(g2);

[x ′

y ′

]=

[x + txy + ty

]

=

[xy

] [txty

]x′ = x + t

Matrices Transformations 15/15

top related