3D Graphics and Transformations
3D Graphics and Transformations
3D Graphics and Transformations
Homogeneous representation of 3D point: |x y z 1|T (w=1 for a 3D point) Transformations will be represented by 4x4 matrices.
1 0 0 0
0 0 tx 1 0 ty 0 1 tz 0 0 1
Translation
Sx 0 0 Sy 0 0 0 0
Scale
0 0 Sz 0
0 0 0 1
1 0 0 0
0 Shx 1 Sh y 0 1 0 0
Shear
0 0 0 1
0 0 0 1
cos( ) 0 sin( ) 0
0 sin( ) 1 0
0 0 0 cos( ) 0 0 0 1
Y-axis
0 0 0 0 1 0 0 1
Rotation About an Arbitrary Axis in Space Assume we want to perform a rotation about an axis in space passing through the point (x0, y0, z0) with direction cosines (cx, cy, cz) by degrees. 1) First of all, translate by: - (x0, y0, z0) = |T|. 2) Next, we rotate the axis into one of the principle axes, let's pick, Z (|Rx|, |Ry|). 3) We rotate next by degrees in Z ( |Rz()|). 4) Then we undo the rotations to align the axis. 5) We undo the translation: translate by (x0, y0, z0) The tricky part is (2) above. This is going to take 2 rotations, 1 about x (to place the axis in the xz plane) and 1 about y (to place the result coincident with the z axis).
Rotation about x by : How do we determine ? Project the unit vector, along OP, into the yz plane as shown below. The y and z components are cy and cz, the direction cosines of the unit vector along the arbitrary axis. It can be seen from the diagram d = sqrt(cy2 + cz2), above, that : therefore cos() = cz/d
sin() = cy/d
Rotation by about y: How do we determine ? Similar to above: Determine the angle to rotate the result into the Z axis: The x component is cx and the z component is d. cos()= d = d/(length of the unit vector) sin()= cx = cx/(length of the unit vector). Final Transformation: M = |T|-1 |Rx|-1 |Ry|-1 |Rz| |Ry| |Rx| |T| If you are given 2 points instead, you can calculate the direction cosines as follows: V = | (x1 -x0) (y1 -y0) (z1 -z0) |T cx = (x1 -x0)/ |V| cy = (y1 -y0)/ |V| cz = (z1 -z0)/ |V|, where |V| is the length of the vector V.
Spaces Object Space definition of objects. Also called Modeling space. World Space where the scene and viewing specification is made Eyespace (Normalized Viewing Space) where eye point (COP) is at the origin looking down the Z axis. 3D Image Space A 3D Perspected space. Dimensions: -1:1 in x & y, 0:1 in Z. Where Image space hidden surface algorithms work. Screen Space (2D) Coordinates 0:width, 0:height
Projections We will look at several planar geometric 3D to 2D projection: -Parallel Projections Orthographic Oblique -Perspective
Projection of a 3D object is defined by straight projection rays (projectors) emanating from the center of projection (COP) passing through each point of the object and intersecting the projection plane.
Perspective Projections
Distance from COP to projection plane is finite. The projectors are not parallel & we specify a center of projection. Center of Projection is also called the Perspective Reference Point COP = PRP Perspective foreshortening: the size of the perspective projection of the object varies inversely with the distance of the object from the center of projection. Vanishing Point: The perspective projections of any set of parallel lines that are not parallel to the projection plane converge to a vanishing point.
X or Y
P(X,Y,Z)
X or Y PP xp or yp (COP) O
f
X or Y PP xp or yp O (COP) f P(X,Y,Z) Z P(X,Y,Z)
=X 1 0 = 0 0
; 0 1 0
yp f 0 0 1
=Y
M per
0 1 f
0 0 0 0
xp
PP xp or yp
X or Y
yp X Y ; ; = = f Z+ f f Z+ f 1 0 = 0 0 0 0 1 0 0 1 0 1 f 0 0 0 1
(COP)
M per
Generalized formulation of perspective projection: X or Y Parametric eqn. of the line L between COP and P: COP + t(P-COP); 0 < t < 1. (COP) Q O (dx, dy, dz) (0, 0, Zp) L PP P(xp, yp, Zp) P(X,Y,Z)
Z Let the direction vector from (0, 0, Zp) to COP be (dx, dy, dz), and Q is the distance from (0, 0, Zp) to COP. Then COP = (0, 0, Zp) + Q(dx, dy, dz). The coordinates of any point on line L is: X = Qdx + (X- Qdx)t; Y = Qdy + (Y- Qdy)t; Z = (Zp + Qdz) + (Z - (Zp + Qdz))t; Using the condition Z = Zp, at the intersection of line L and plane PP:
Qd z t= Z ( Z p + Qd z )
Class work:
Now subsitute to obtain, xp and yp.
d d X Z x + Zp x dz dz xp = Zp Z +1 Qd z
Y Z yp =
dy
dz Zp Z Qd z
+ Zp +1
dy dz
M gen
1 0 = 0 0
0 1 0 0
dx dz dy dz Zp Qd z 1 Qd z
dx zp dz dy zp dz 2 Zp + Zp Qd z Zp +1 Qd z
Parallel Projection Distance from COP to projection plane is infinite. Therefore, the projectors are parallel lines & we specify a direction of projection (DOP) Orthographic: the direction of projection and the normal to the projection plane are the same. (direction of projection is normal to the projection plane).
Axometric orthographic projections use planes of projection that are not normal to a principal axis (they therefore show multiple face of an object.) Isometric projection: projection plane normal makes equal angles with each principle axis. DOP Vector: [1 1 1]. All 3 axis are equally foreshortened allowing measurements along the axes to be made with the same scale. Example Isometric Projection:
Oblique projections : projection plane normal and the direction of projection differ. Plane of projection is normal to a principle axis Projectors are not normal to the projection plane Example Oblique Projection
General oblique projection of a point/line: Projection Plane: x-y plane; P is the projection of P(0, 0, 1) onto x-y plane. `l is the projection of the z-axis unit vector onto x-y plane and is the angle the projection makes with the x-axis. When DOP varies, both `l and will vary. Coordinates of P: (l cos , l sin , 0).
As given in the figure: DOP is (dx, dy, -1) or (l cos , l sin , 1).
What is ?
P(0, 0, 1)
View Specifications: VP, VRP, VUP, VPN, PRP, DOP, CW, VRC
CW VP VPN n COP/PRP
VRP u
VPN n
Implementation of 3D Viewing
2D device coordinates
Canonical view volume for parallel projection is defined by six planes: X = -1; Y = -1; Z = 0; X or Y 1 FP BP X = 1; Y = 1; Z = -1.
Canonical view volume for perspective projection is defined by six planes: X = Z; Y = -Z; Z = -Zmin; X or Y 1 X = -Z; Y = Z; Z = -1.
-1
-Z FP
-1 BP
-Z
-1
-1
Steps for implementing normalizing transformation matrix for parallel projection Translate the VRP to origin Rotate VRC such that VPN (n-axis) aligns with Z-axis (also, u with X and v with Y) Shear (not necessary for pure orthographic) such that DOP is parallel to the Z-axis Translate and scale into parallel-projection canonical view volume Expressions for Step 2 must be derived. Implement using the concept of combined transformation (rotation). 0 0 0 1 Z 0 cos( ) sin( ) 0 Take Rx = 0 sin( ) cos( ) 0 0 0 0 1 Rows are unit vectors, when rotated by Rx, will align with the Y and Z axis respectively. When unit vectors along the principle axes are rotated by Rx, they form the column vectors. Y
Consider a general scenario of combined rotations and use the property derived based on the orthogonality of the R matrix. Y P3 P2 P1 P1 X
Pn Pn
Y P3
X P2
r1x r 1y r1z
r2 x r2 y r2 z
r3 x r3 y r3 z
Where,
P P2 = 1 P P2 1 P P2 x P P2 1 = 1 P P2 x P P2 1 1 = R z x Rx
Z
Y P3 P2 P3 X
Pn
P1
P1 P2 Z
Pn
R y = r1 y r1 y r1 y
r1x r 1y R= r1z 0
r2 x r2 y r2 z 0
r3 x r3 y r3 z 0
0 0 0 1
where,
The overall combined transformation matrix (for WCSVV -> PPCVV), for parallel projection is:
Steps for implementing normalizing transformation matrix for perspective projection Translate the VRP to origin Rotate VRC such that VPN (n-axis) aligns with Z-axis (also, u with X and v with Y) Translate such that COP (or PRP) is at the origin Shear such that center of line of view volume (VVCL) becomes z-axis Scale such that VV becomes the canonical view volume X or Y
V VC L
CW -Z
VPN
VRP
2D device coordinates
X v max X v min Yv max Yv min T ( X v min , Yv min , Z v min ) . S ( , , Z v max Z v min ) . T (1,1,1) 2 2
The Camera Model We specify our initial camera model by identifying the following parameters. 1. A scene, consisting of polygonal elements each represented by their vertices; 2. A point that represents the camera position -- C = [Cx, Cy, Cz],; 3. A point that represents the ``center-of-attention'' of the camera (i.e. where the camera is looking): A = [Ax, Ay, Az]; 4. A field-of-view angle, , representing the angle subtended at the apex of the viewing pyramid. 5. The specification of ``near'' and ``far'' bounding planes. These planes considered perpendicular to the direction-of-view vector at a distance of dn and df from the camera, respectively.
1 u , v, w 1
P(u, v, w) PP (u, v, w) -w
Express as transformation:
u or v
f.tan(/2)
/2
O (COP)
n.tan(/2)
(0, 0, -n)
(0, 0, -f) -w
Transformation of the finite (truncated) viewing pyramid to the cube, -1 < u, v, w < 1. Let us first analyze w-axis only. Use the transformation matrix:
1 0 P= 0 0
0 0 1 0
0 0 ; 0 a 1 0 b 0
and b, please:
The solution:
an + b = n and a. f + b = f
1 Hence the transformation is: 0 P = 0 0 0 1 0 0 0 0 f +n f n 2 f .n f n
f +n a= ; f n 2 f .n b= f n
0 0 1 0
u or v (0,n.tan(/2),-n)
(0,f.tan(/2),-f)
/2
(0, 0, -n) (0, 0, -f) -w
n 2nf + +n f +n
n 2nf + +n f +n
[0 1 -1 1]
n
f
0 cot( / 2) 0 cot( / 2) 0 0 P= 0 0
0 0 f +n f n 2 f .n f n
0 0 1 0 0 0 f n 2 fn f + n 2 fn
0 0 tan( / 2) 0 tan( / 2) 0 0 0 0 P 1 = 1 0 0
Pf = Pd .P
0 0 f (d + 1) + n(d 1) f n 0 0 0 1 d 0
0 0 d 0
0 0 f +n f n 0