0% found this document useful (0 votes)
15 views

Cs3vr16 Graphics 2(4)

Uploaded by

fatimabuhari2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Cs3vr16 Graphics 2(4)

Uploaded by

fatimabuhari2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

CS3VR16 : Graphics

Lecture 2 – Aut 2023


p1 RJM 17/08/23 CS3VR16 – Virtual Reality – Graphics -
2
Components for 3D Graphics
 3D Scene Representation
• Intro
• Coordinate Systems
• 3D Primitives
• Matrix Operations
• For transforming objects we wish to
display
• For finding where they are relative to the
eye
• For ensuring 3D representation on 2D
screen
p2 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Overall Aim
Build scenes – eg by transforming basic cubes
View from different positions
Drawing transformed cubes as cubes/pseudo cylinders

Use these to illustrate transforms


p3 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
3D Scenes – 3D Primitives

Cube
Cube moved
at 0,0,0 from 0,0,0

Cube scaled
in different
Cube rotated axes
about one axis

Cube rotated
about axes
p4 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
3D Scenes – 3D Primitives - ops
For each point on cube, transform x, y, z →
x’, y’, z’
eg x’ = x + Tx translation
by Tx
or x’ = x * Sx scaling by
Sx
or x’ = x*Rx + y*Ry rotation (about z
axis)
or x’ = x + y*SHy + z*SHz shear x
And similarly for y’ and z’ …

Could be combination
p5 RJM 17/08/23 of –many
CS3VR16 Graphics operations
-2
© Prof Richard Mitchell 2023
So, need to be able to concatenate these
Crane Example
If say want to model arm of crane
Origin is middle of base
x z
y
Have original cube
Scale so right size
Translate in x and z
Rotate about z axis

Once got overall matrix,


apply to all corners

p6 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
2D to 3D
In 2D, x,y points represented by a vector with extra 1
Homogenous coordinates, and a 3*3 matrix used

[ ][ ][ ]
𝑥′ 𝑣 11 𝑣1 2 𝑣 13 𝑥
𝑦 ′ = 𝑣21 𝑣 22 𝑣 23 𝑦
1 0 0 1 1

In 3D, x,y,z points represented by vector with extra 1


Homogenous coordinates, and a 4*4 matrix used

[][ ][ ]
𝑥′ 𝑣 11 𝑣 12 𝑣 13 𝑣1 4 𝑥

𝑦 𝑣21 𝑣 22 𝑣 23 𝑣 24 𝑦
=
𝑧

𝑣31 𝑣32 𝑣 33 𝑣3 4 𝑧
1 0 0 0 1 1

Rarely, bottom row has other values


p7 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Key Point
Have x,y,z point, put it with extra 1 into vector
Use transform matrix TM, to get new vector
Extract from that the new point x’,y’,z’

[][ ][ ]
𝑥′ 𝑣 11 𝑣 12 𝑣 13 𝑣1 4 𝑥
𝑦′ 𝑣21 𝑣 22 𝑣 23 𝑣 24 𝑦
=
𝑧′ 𝑣31 𝑣32 𝑣 33 𝑣3 4 𝑧
1 0 0 0 1 1

For multiple points, same TM, more columns of points

[ ][ ][ ]
′ ′
𝑥1 𝑥2 𝑣 11 𝑣1 2 𝑣 13 𝑣1 4 𝑥1 𝑥2
′ ′
𝑦1 𝑦2 𝑣21 𝑣 22 𝑣 23 𝑣 24 𝑦1 𝑦2
=
𝑧 ′1 𝑧 ′2 𝑣31 𝑣3 2 𝑣 33 𝑣3 4 𝑧1 𝑧2
1 1 0 0 0 1 1 1
p8 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Scale and Move
2D Matrix to Scale points, 2D Matrix to
by Sx and Sy Move by dx,dy:

[ ] [ ]
𝑆𝑥 0 0 1 0 𝑑𝑥
0 𝑆𝑦 0 0 1 𝑑𝑦
0 0 1 0 0 1

3D Matrix to Scale points, 3D Matrix to Move


by Sx, Sy and Sz by dx,dy,dz:

[ ] [ ]
𝑆𝑥 0 0 0 1 0 0 𝑑𝑥
0 𝑆𝑦 0 0 0 1 0 𝑑𝑦
0 0 𝑆𝑧 0 0 0 1 𝑑𝑧
0 0 0 1 0 0 0 1

p9 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Example – Scale and Move
Cube
z 200x10x1
Start cube unit 0
size, 0,0,0 in mid 12x12x1
y 0
x of cube
10x10x8
0
Bottom of base at z = 0
Want base to be of size 12x12x10

So scale it by?

But is that enough?

p10 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Note on ensuring on ground
Start with unit
cube, origin in ground
its centre

Scale so right
size: 12*12*10 bottom at z=-
5 Move up so
base on
ground

p11 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
So transforms needed
Scale then move, so write in reverse order as

[ ][ ]
1 0 0 0 12 0 0 0
0 1 0 0 0 12 0 0
0 0 1 5 0 0 10 0
0 0 0 1 0 0 0 1

p12 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Applying to a cube
z Each corner is where x,y or z are 0.5 or -0.5
Need to define these in homogenous coords
y
x

[ ]
0.5 0.5 − 0.5 −0.5 0.5 0.5 −0.5 −0.5
−0.5 0.5 0.5 −0.5 − 0.5 0. 5 0. 5 −0. 5
𝑐𝑢𝑏𝑒(h) =
−0.5 − 0.5 − 0.5 −0.5 0.5 0.5 0.5 0.5
1 1 1 1 1 1 1 1
Use this TM on above:

p13 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
And the result is

[ ][ ]
12 0 0 0 0.5 0.5 − 0.5 −0.5 0.5 0.5 −0.5 −0.5
0 12 0 0 −0.5 0.5 0.5 −0.5 − 0.5 0. 5 0. 5 − 0.5
0 0 10 5 −0.5 − 0.5 − 0.5 −0.5 0.5 0.5 0.5 0.5
0 0 0 1 1 1 1 1 1 1 1 1

Looks horrid, but easy as many


0’s

[ ]
6 6 −6 −6 6 6 −6 −6
−6 6 6 −6 −6 6 6 −6
¿
0 0 0 0 10 10 10 10
1 1 1 1 1 1 1 1

- +0.5+0.5=1
0.5+0.5= 0 12x12x1
0 Are these coordinates correct? 0
p14 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Alternative
Did base, by
scaling to right size (12 12 10)
Moving up (0, 0, 5)

Can it be done by a move first?


Move up by ?
Scale by ? 12x12x1
0

p15 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Alternative achieved
Move by 0, 0, 0.5, then scale by 12, 12, 10

[ ] [ ]
12 0 0 0 1 0 0 0
0 12 0 0 0 1 0 0
0 0 10 0 0 0 1 0.5
0 0 0 1 0 0 0 1

What can you say about final result?

p16 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Verifying result
z -0.5, -0.5,
Can find coords of 8 corners 0.5
But verify result by say two, x
opposite corners : y
0.5, 0.5, -0.5

[ ][ ]
12 0 0 0 0 .5 − 0.5
0 12 0 0 0.5 − 0.5
0 0 10 5 −0.5 0.5
0 0 0 1 1 1

=
6,6,0 -6,-6,10

p17 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Upright Section
Opposite corners of 200x10x1
base are at 6,6,0 and - 0
6,-6,10 12x12x1
0
Where are opposite 10x10x8
corners of upright? 0
Bottom of base at z = 0
5,5,10 and -5,-5,90

If scale then move, what two operations are


needed?
Scale by 10,10,80
Move by 0, 0, 50
p18 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Doing the transform
Scale then move, so write in reverse order as

[ ][ ]
1 0 0 0 10 0 0 0 =
0 1 0 0 0 10 0 0
0 0 1 50 0 0 80 0
0 0 0 1 0 0 0 1

[ ][ ]
10 0 0 0 0 .5 − 0.5 =
0 10 0 0 0.5 − 0.5
0 0 80 50 −0.5 0.5
0 0 0 1 1 1

- +40+50=90
40+50=1
p19 RJM 17/08/23
0
CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Arm (without rotation)
In unrotated state, Arm is parallel with x axis

Where is middle of top 200x10x1


of upright? 0
0,0,90 12x12x1
0
10x10x8
0
‘Arm’ 80% of it in the x direction from 0,0,90
z=?
16 40
0x= x=0
p20 RJM 17/08/23 ? CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
So what scale and move ?
move by 60, 0, 95 scale by 200, 10, 10

[ ] [ ]
1 0 0 60 200 0 0 0
0 1 0 0 0 10 0 0
0 0 1 95 0 0 10 0
0 0 0 1 0 0 0 1

p21 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Verifying result of arm
z=
z=
100
16 40 90
x = 160 0 x = -40

So 0.5, 0.5, -0.5 should be transformed to 160, 5, 90


So -0.5, -0.5, 0.5 should be transformed to -40, -5, 100

p22 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Converting coordinate systems
y y

x
x
z
z
To convert from Left to Right, how does z change?

[ ]
Matrix to achieve this?
1 0 0 0
0 1 0 0
0 0 −1 0
0 0 0 1

p23 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
3D Scenes – 3D Primitives -
shear
Matrix Transforms –
Shear

[ ]
Examples in 2D 2,1 3, 1 𝑠h 𝑦
𝑥 0
1 𝑆𝑇𝑥 = 0 1 0
0,1 1,
1 1,0 0 0 1

[ ]
1,
1,0 1 0 0
3
𝑦 1,2 𝑆 𝑇 𝑦 = 𝑠 h 𝑥𝑦 1 0
Here 𝑠 h 𝑥 = 2 0,1 0 0 1
𝑥
𝑠 h𝑦 = 2

First is shear x by amount in y direction .. Extends..

p24 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
3D Scenes – 3D Primitives –
shear
Matrix Transforms –
Shear

[ ]
𝑦 𝑧
1 𝑠 h𝑥 𝑠 h𝑥 0
𝑥 𝑧
𝑠 h𝑦 1 𝑠 h𝑦 0
𝐓 =
𝑠 h 𝑥𝑧 𝑠 h𝑧𝑦 1 0
0 0 0 1

Applied as (eg.)

[ ][ ] [ ]
𝑦 𝑧 𝑦 𝑧
1 𝑠 h𝑥 𝑠 h𝑥 0 1 1+5 𝑠 h 𝑥 + 2 𝑠 h 𝑥
𝑥 𝑧 𝑥 𝑧
𝑠h 𝑦 1 𝑠h 𝑦 0 5 5+ 𝑠 h 𝑦 + 2 𝑠 h 𝑦
=
𝑠h 𝑥
𝑧 𝑠 h 𝑧𝑦 1 0 2 2+ 𝑠 h 𝑥𝑧 +5 𝑠 h 𝑦𝑧
0 0 0 1 1 1

p25 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Shear Example
Next example will require a
shear.
Have a 3D vertical cuboid of a
leg z
Sheared in x with height z x
Height is 480
Hence, want
x at top x value
is 140 morecalculated
than at by x = x + z * 140/480

[ ]
bottom 1 0 14 / 48 0
0 1 0 0
0 0 1 0
0 0 0 1

p26 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Chair Example - Exercise
Here start with unit cube z
Origin in middle of base

Aim to model aspects of chair


x y
Height of seat is 20
Width of back of seat is 20
Same cross section for all legs, 24
Seat – scale and move
Back – scale and move
Back leg – scale and move
Front leg – scale, shear and move

Need precise coordinates – 2D drawings in x,y,z


p27 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
150
Chair -80 12
0 -
z -150
120
y
x
120
x y 150
-150 140
100 100
0 0

z 500 500
480 480
x
z
y
-220 -80 120 -120 120
p28 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Transforms Needed - Seat
Seat of the chair has to be scaled by
300,300,20 and moved upwards by 480 units
100 150
z 0 -80 12
0 -
-150
500 120
y 480
x
120
150
-150 140
- 120
120
Opposite corners on cube -0.5,-0.5,0 and
0.5,0.5,1
Transform to -150,-150,480 and 150,150,500
Form
p29 overall transform
RJM 17/08/23 matrix,
CS3VR16 – Graphics -show
2 it works
© Prof Richard Mitchell 2023
Transforms Needed - Back
Back of the chair to be scaled by 20,300,500
and moved upwards and across by 140, 0, 500
1000 150
z -80 12
0 -
-150
500 120
y 480
x
120
150
-220 -80 120 -150 140

Opposite corners on cube -0.5,-0.5,0 and


0.5,0.5,1
Transform to 130,-150,500 and 150,150,1000
Form
p30 overall transform
RJM 17/08/23 matrix,
CS3VR16 – Graphics -show
2 it works
© Prof Richard Mitchell 2023
Transforms Needed – Back Leg
One back leg of the chair has to be scaled by
24,24,480 and moved to 120, 120, 0
1000 150
z -80 12
0 -
-150
500 120
y 480
x
120
150
-220 -80 120 -150 140

Opposite corners on cube -0.5,-0.5,0 and


0.5,0.5,1
Transform to 108,108, 0 and 132, 132, 480
Form
p31 overall transform
RJM 17/08/23 matrix,
CS3VR16 – Graphics -show
2 it works
© Prof Richard Mitchell 2023
Front Leg
Front leg needs shearing – lets find out what
480
Leg cross section 48 500
But angled … 480
Length – by Pythagoras a a
0 140
-220 -80
Horizontal cross section affected by skew

24 So scale leg 25,24,480


Skew leg x = x + 140z/480
25
p32 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Transforms Needed – Front Leg

So scale leg 25,24,480 1000


Skew leg x = x + 14z/48
Then move so middle of 500
base at -220, 120,0 480

-220 -80 120

Opposite corners on cube -0.5,-0.5,0 and


0.5,0.5,1
Transform to -232.5,108, 0 and -67.5, 132, 480
Form overall transform matrix, show it works
p33 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Summary
In this lecture we have introduced
4*1 homogeneous vectors for x,y,z points
4*4 transformation matrices
for translation, scaling, and shear
Combinations of these matrices : order important
We applied these to many points on an object
Next week, consider rotation, building models, and
working out where coordinates are relative to eye
Next slides, answers to chair – use them to check

p34 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Answers to Chair - seat
Seat of the chair has to be scaled by
300,300,20 and moved upwards by 480 units

[ ][ ][ ]
1 0 0 0 300 0 0 0 300 0 0 0
0 1 0 0 0 300 0 0 0 300 0 0
=
0 0 1 480 0 0 20 0 0 0 20 480
0 0 0 1 0 0 0 1 0 0 0 1

p35 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Answers to Chair - back
Back of the chair has to be scaled by
20,300,500 and moved upwards by 140, 0, 500

[ ][ ][ ]
1 0 0 140 20 0 0 0 20 0 0 140
0 1 0 0 0 300 0 0 0 300 0 0
=
0 0 1 500 0 0 500 0 0 0 500 500
0 0 0 1 0 0 0 1 0 0 0 1

p36 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Answers to Chair – back leg
One back leg of the chair has to be scaled by
24,24,480 and moved to 120, 120, 0

[ ][ ][ ]
1 0 0 120 24 0 0 0 24 0 0 120
0 1 0 120 0 24 0 0 0 24 0 120
=
0 0 1 0 0 0 480 0 0 0 480 0
0 0 0 1 0 0 0 1 0 0 0 1

p37 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023
Answers to Chair – front leg
Scale 25,24,480; Skew x = x + 14z/48; Move -220,
120,0

[ ][ ][ ]
1 0 0 − 22 0 1 0 14 / 48 0 25 0 0 0
0 1 0 12 0 0 1 0 0 0 24 0 0
0 0 1 0 0 0 1 0 0 0 48 0 0
0 0 0 1 0 0 0 1 0 0 0 1

[ ][ ]
1 0 0 −2 2 0 25 0 140 0
0 1 0 120 0 24 0 0
¿
0 0 1 0 0 0 480 0
0 0 0 1 0 0 0 1

[ ]
25 0 140 − 220
0 24 0 12 0
¿
0 0 480 0
0 0 0 1
p38 RJM 17/08/23 CS3VR16 – Graphics - 2
© Prof Richard Mitchell 2023
Final Result

[ ]
− 12.5 − 220 12.5 +140 − 220
− 12+120 12+120
=
0 480
1 1

[ ]
− 232.5 −67.5
108 132
=
0 480
1 1

p39 RJM 17/08/23 CS3VR16 – Graphics - 2


© Prof Richard Mitchell 2023

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy