COM336
Topic 3 : View ports & clipping
COM336
WINDOWS, VIEWPORTS & CLIPPING
THE WORLD
THE WINDOWTHE DEVICE
THE VIEWPORT
COM336
YMAX
YMIN
vMAX
VMIN
VY
UX
.(x,y) .(u,v)
UMIN UMAXXMIN XMAX
By simple proportion for the x co-ordinate :
x xx x
u uu u
min
max min
min
max min
u uu ux x
x x
minmax min
max minmin.Rearrange
COM335
axis(xmin,xmax,ymin,ymax,zmin,zmax,colmin,colmax)
axis square
hold on (or off)
MATLAB programming of the view port
Topic 4
3D Transforms &
Projection
Translation & Scaling
1000000000000
scalingfor and
1000100010001
ation For transl z
y
x
z
y
x
SS
S
TTT
Rotation in 3D
R
Rx
Ry
Rz
Z axis rotation
1000010000)()(00)()(
CosSinSinCos
RZ
X & Y axis rotation
10000)(0)(00100)(0)(
10000)()(00)()(00001
CosSin
SinCos
RCosSinSinCos
R YX
COM335
function CubeProject
%To illustrate normal perspective projection
%First define the basic cube
V = [2 -2 -2 1; 2 -2 2 1; 2 2 2 1; 2 2 -2 1; -2 -2 -2 1; -2 -2 2 1; -2 2 2 1; -2 2 -2 1];
F = [1 2 3 4; 3 7 8 4; 7 6 5 8; 6 2 1 5; 2 6 7 3; 4 8 5 1];
VT = V';
%Define suitable rotation angles to orientate the cube
thetaY = 60*pi/180;
thetaX = 30*pi/180;
%Set up a rotation matrix for the Y axis
YROT = [cos(thetaY) 0 -sin(thetaY) 0 ; 0 1 0 0; sin(thetaY) 0 cos(thetaY) 0; 0 0 0 1];
XROT = [1 0 0 0 ; 0 cos(thetaX) -sin(thetaX) 0; 0 sin(thetaX) cos(thetaX) 0; 0 0 0 1];
%Now do the rotations
VT = XROT*YROT*VT;
%Strip off the homogeneous co_ordinate to use the patch command
VP = zeros(3,8);
VP=VT(1:3,:);
patch('Vertices',VP','Faces',F,'facecolor','red')
%axes('Ambientlightcolor',[1 1 1];
axisarray = [-5 5 -5 5 -5 5 0 1];
axis(axisarray)
COM335
-10,-20,0
-10,-20,20
0,-20,30
10,-20,20
10,-20,0
-10,20,0
-10,20,20
0,20,30
10,20,20
10,20,0
1,2,3,4,5
5,4,9,10,0
6,7,2,1,0
4,3,8,9,0
7,8,3,2,0
10,9,8,7,6
1,5,10,6,0
Disc file data for the model house
Vertex data Face data
COM335
function HouseDraw
%Draws a simple house
%Data on nodes is read from a text file NHouse.txt
%Data on patches is read from a text file PHouse.txt
Node = dlmread('NHouse.txt');
%Now read in the uncorrected patch data
UPatch = dlmread('PHouse.txt');
%First find how many patches we need
%We don't care about the other dimension X
[numpatches,X]=size(UPatch);
%Now lets sort into 4 node & 5 node faces
num4 = 0;
for k = 1:numpatches
if UPatch(k,5)==0
num4 = num4 + 1;
end
end
COM335
Face4 = zeros(num4,4);
Face5 = zeros(numpatches-num4,5);
j = 1;
i=1;
for k = 1:numpatches
if UPatch(k,5)==0
Face4(j,:)=UPatch(k,1:4);
j=j+1;
else
Face5(i,:)=UPatch(k,:);
i = i+1;
end
end
patch('Vertices',Node,'Faces',Face4,'FaceVertexCData',hsv(5),'FaceColor','flat')
patch('Vertices',Node,'Faces',Face5,'FaceVertexCData',hsv(2),'FaceColor','flat')
axis_data = [-40 40 -40 40 -40 40 0 1];
axis(axis_data)
axis square
rotate3d on
COM335
Running housedraw
C
Parallel Perspective
Figure 5.1 : Parallel & Perspective projections
COM335
The medieval world did not understand perspective
COM335
The medieval world did not understand perspective
COM335
The classical Greek world used perspective
Co-ordinate axes for projection
Figure 5.2 : Co-ordinate system for projection
O
Y
Z
X
Definition of projection
X
Y
Z
XP
YP
R
P
Q
General parallel projection
100000000)sin(.100)cos(01
RR
P {x,y,z}
C - d - - z -
(u,v)
Normal perspective projection
COM335
vd
yz d
( )
zSy
dzyv .
1
Calculating the transform by similar triangles
COM335
S zS z
( )( )0 0 0
0 0 00 0 0 00 0 0 1
1
1
dz
zS
Normal perspective projection as matrix multiplication
COM335
10
1
1
10
11100000000100001
dzydzx
dz
yx
zyx
d
An alternative (and better) matrix representation
Single vanishing pointVP
Figure 5.5 : A Single Vanishing Point
COM335
X
Y
Z
Y axis
vanishing point
X axis
vanishing point
Two point perspective projection
Transverse Mercator
P
Q
Prime survey meridean
Figure 5.6 : Transverse Mercator Projection
Secondary survey meridean
COM335
t = Tanφ
ω = λ – λ0
E’ = ( K0νωCosφ ){ 1 + term1 + term2 + term3 }
Term1 = ( ω2 / 6 )Cos2φ( ψ – t2)
Term2 = ( ω4 / 120 )Cos4φ[ 4ψ3( 1 – 6t2 ) + ψ2( 1 + 8t2 ) – ψ2t2 + t4 ]
Term3 = ( ω6 / 5040 )Cos6φ( 61 – 479t2 + 179t4 – t6 )
E = E’ + False Easting
N’ = K0{ m + Term1 + Term2 + Term3 + Term4 }
Term1 = ( ω2 / 2 )νSinφ Cosφ
Term2 = ( ω4 / 24 )νSinφ Cos3φ( 4ψ2 + ψ – t2 )
Term3 = ( ω6 / 720 )νSinφ Cos5φ[ 8ψ4( 11 – 24t2 ) – 28ψ3( 1 – 6t2 ) + ψ2( 1 – 32t2 ) – ψ( 2t2 ) + t4 ]
Term4 = ( ω8 / 40320 )νSinφ Cos7φ( 1385 – 3111t2 + 543t4 – t6 )
N = N’ + False Northing
The Redfearn Equations
http://www.surveyplanet.com/Resources/standards
COM335