0% found this document useful (0 votes)
13 views10 pages

13 Projection

Uploaded by

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

13 Projection

Uploaded by

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

Planar Geometric Projections

Planar ⩴ project onto a plane (vs. planetarium, e.g.)

EECS 487: Interactive Geometric ⩴ projectors are straight lines


(vs. curved lines in cartography, e.g.)

Computer Graphics Projection ⩴ map from n to n-1 dimensions

Lecture 13: Euclidean geometry describes shapes “as they are”


• Planar Geometric Projections • properties of objects that are unchanged
by rigid motions: lengths, angles, parallel lines
• Orthographic projection
• Perspective projection Projective geometry describes objects “as they appear”
• Projections in OpenGL • lengths, angles, parallel lines become
“distorted” when we look at objects

Projection System Taxonomy of


Common elements: Planar Geometric Projections
• Center of Projection (COP)
Planar Geometric Projections
(for perspective projection)/
Direction of Projection (DOP)
(for parallel projection, ≈COP at ∞) Perspective Parallel
• Projection/view/picture/image plane (PP) Projection Projection

• Projectors/sightlines
One-point Oblique Orthographic
Parallel Two-point
Cavalier Axonometric Multiview
Three-point
Cabinet
Isometric top, bottom,
General front, back,
Dimetric left, right
Parallel Perspective
Trimetric
Lozano-Perez01 Perspective
Multiview Axonometric Orthographic
Orthographic Axonometric:
• projection plane is not parallel to any coordinate plane
• projection direction perpendicular to projection plane

Isometric:
• preserves lengths
• projection plane parallel to one
along 3 principal axes
coordinate plane (project onto • principal axes make
plane by dropping coordinate the same angle with
• preserves ratios,
perpendicular to plane) each other (120º)
but not angles ( not visible)
• projection direction perpendicular • parallel lines remain parallel
to projection plane is considered 120º 120º
• good for exact measurements an affine transform 120º
(CAD, architecture) James07

Parallel Orthographic Projections Orthographic Projection


View volume defined by
left, right, bottom, top, near, and far planes:
⎡ 1 0 0 ⎤
⎢ ⎥
P=⎢ 0 1 0 ⎥
⎢⎣ 0 0 0 ⎥⎦

Are we done?

Yes, but we’ve lost depth (z) information, can’t do: Map it to cvv:
• hidden surface removal
• lighting, etc.
Need to preserve z dimension!
map view volume to canonical view volume
Akenine-Möller & Haines 02 Shirley02
Orthographic Projection Setup Orthographic Projection
From an arbitrary axis-aligned
Simple case: view volume axis-aligned with world bounding box to canonical view volume
coordinate system • translate and scale:
• the view volume is in negative z, n > f

More generally, the view RTR3

volume is not axis-aligned What would the T and S matrices be?


⎡ 2 ⎤ ⎡ 2 ⎤
with world CS (it will always ⎢ 0 0 −
l+r
⎥ ⎢ 0 0 0 ⎥

⎢ 1 0 0
l+r



⎢ r−l r−l ⎥ ⎢ r−l ⎥ 2
be axis-aligned with eye CS): ⎢ 2

b+t ⎥ ⎢ 2 ⎥

⎢ b+t


Po = ST = ⎢
0 0 ⎥ S= ⎢ 0 0 0 ⎥
⎢ 0 1 0 − ⎥
t −b t −b t −b
⎢ ⎥ ⎢ ⎥ T= ⎢
2

⎢ 0 n+ f ⎥ ⎢ 0 0 ⎥ n+ f
2 2 ⎢ ⎥
0 − 0 0 0 1 −
⎢ n− f n− f ⎥ ⎢ n− f ⎥ ⎢ 2 ⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢⎣ 0 0 0 1 ⎥⎦ ⎢⎣ 0 0 0 1 ⎥⎦ ⎣ 0 0 0 1 ⎦
Shirley02

Orthographic Projection and Perspective Projection


Viewing Transform Objects appear smaller as distance from
From an arbitrary viewing center of projection (eye of observer) increases
volume to canonical view volume (perspective foreshortening) ⇒ looks more realistic
• translate eye to origin (human eyes naturally see things in perspective)
• transform to eye coordinate system
• apply orthographic projection
Preserves:
• lines (collinearity)
M world −>canonical = • incidence
⎡ 2 l+r ⎤ (“lies on”, intersects)
⎢ 0 0 − ⎥
⎢ r−l r−l ⎥ ⎡ ux uy uz 0 ⎤ ⎡ 1 0 0 −ex ⎤ • cross ratio
⎢ 2 b+t ⎥ ⎢ ⎥ ⎢ ⎥
⎢ 0 t −b
0 −
t −b ⎥ ⎢

vx vy vz 0 ⎥



0 1 0 −ey ⎥ Does not always preserve parallel lines:

n+ f

⎢ wx wy wz 0 ⎥ ⎢ 0 0 1 −ez ⎥⎥ • lines parallel to projection plane remain parallel
⎢ 0 0
2
− ⎥
⎢ ⎥ ⎢ 1 ⎥⎦ ⎢⎣ 0 0 0 1 ⎥⎦

n− f n− f

⎣ 0 0 0 • lines not parallel to projection plane converge to a single
⎢⎣ 0 0 0 1 ⎥⎦ point on the horizon called the vanishing point (vp)
M eye→canonical M world→eye Shirley02
The Cross Ratio Classes of Perspective Projection
For the 4 sets of 4 collinear points in the figure, the cross-ratio for
one-point: projection plane parallel to one
corresponding points has the same value (can permute the point
coordinate plane ( to two coordinate axes,
ordering)
one coordinate axis cuts projection plane)

p4 p 2 − p1 p 4 − p 3 two-point: projection plane parallel to one


p1 p3 p 4 − p1 p 3 − p 2 coordinate axis (two coordinate axes cut
p2
projection plane)
⎡ xi ⎤
⎢ ⎥
p i = ⎢⎢ i ⎥
y
z ⎥
⎢ i ⎥
⎢⎣ 1 ⎥⎦

p 3 − p1 p 4 − p 2 p1 − p 3 p4 − p2
p 3 − p 2 p 4 − p1 p1 − p 2 p4 − p3

deMenthon
Seitz08 James07

Classes of Perspective Projection Projective Geometry in 2D


Consider lines and points in P
three-point: projection plane
We extend to 3D to simplify dealing with infinity
not parallel to any coordinate
• origin o out of P, at a distance = 1 from P
axis (three coordinate axes cut
projection plane) To each point m in P we can associate a single ray p = (x1, x2, x3)
To each line l in P we can associate a single plane (A, B, C)
• the equation of line L in projective geometry is Ax1 + Bx2 + Cx3 = 0
x3
Duell (A, B, C ) = L p = (x1, x2, x3)

P
m
l

o
x2 x1
Hulsey James07 deMenthon
Homogeneous Coordinates Perspective Divide
The ray p = (x1, x2, x3) and (λx1, λx2, λx3) How do we “land” back from the projective world to
are the same and are mapped to the same point m in P the 2D Cartesian world of the plane?
• p is the coordinate vector of m, • for point, consider the intersection of ray p = (λx1, λx2, λx3)
(x1, x2, x3) its homogeneous coordinates
with the plane x3 = 1 λ = 1/x3, m = (x1 / x3, x2 / x3, 1)
The planes (A, B, C) and (λA, λB, λC) are the same • for line, intersection of plane Ax1 + Bx2 + Cx3 = 0 with the
and are mapped to the same line l in P plane x3 = 1 is line l = Ax1 + Bx2 + C = 0
• L is the coordinate vector of l,
(A, B, C) its homogeneous coordinates x3 x3
L = (A, B, C) p = (x1, x2, x3) Called “perspective divide” L = (A, B, C) p = (x1, x2, x3)
Point p’ is on line L if L•p’ = 0 p’ P P
m For the mathematically m
l l
inclined, or studying
computer vision: what’s
(A, B, C) the geometric interpretation (A, B, C )
o o
x1 of x3 = 0? x1
x2 deMenthon
x2 deMenthon

Projective Geometry 3D Projective Geometry


Two lines always meet at a
single point, and two points These concepts generalize naturally to 3D
always lie on a single line
Projective geometry does Homogeneous coordinates
not differentiate between • projective 3D points have four coordinates: p = (x, y, z, w)
parallel and non-parallel lines (0, 0, 1) = (0, 0, 2) = …
(7, 1, 1) = (14, 2, 2) = …
Points and lines are dual of (4, 5, 1) = (8, 10, 2) = … Projective transformations
each other • represented by 4×4 matrices

To return from homogeneous


coordinates to Cartesian
coordinates, divide by x3 (w) w=1

w=2
deMenthon, Durand08 Seitz08
Vanishing Points Perspective Projection
What happens to two parallel lines that are not
parallel to the projection plane? Given the coordinates of the orange point
The parametric equation for find the coordinates of the green point
y
a line is: ⎡ p ⎤ ⎡ v ⎤ y' y
tan θ = =
x x
⎢ ⎥ ⎢ ⎥
⎢ p ⎥ ⎢ v ⎥ d z
l = p + tv = ⎢ y ⎥ + t ⎢ y ⎥ y
⎢ p z ⎥ ⎢ vz ⎥ y' = y d z y’
z θ
⎢⎣ 1 ⎥⎦ ⎢⎣ 0 ⎥⎦ e g
Is perspective projection simply: d view plane
After perspective transform:
At the limit, with t ∞, we get
(x, y, z, 1) (xd/z, yd/z, d, 1),
⎡ px + tvx ⎤
⎡ p' ⎤ ⎡ px + tvx ⎤ ⎢ d ⎥
pz + tvz ⎥ a point! [(vx/vz)d, (vy/vz)d, 1]T then map to screen by throwing z
⎢ x ⎥ ⎢ ⎥ ⎢
⎢ p' y ⎥=⎢ py + tvy after
⎥ ⎯perspective
⎯⎯⎯ →⎢ py + tvy ⎥ away the z-coordinate: (xd/z, yd/z, 1)?
⎢ ⎥ ⎢ ( p + tv ) / d ⎥ divide ⎢ d ⎥
⎣ w ⎦ ⎢⎣ z z ⎥⎦ ⎢ pz + tvz ⎥ Each set of parallel lines
⎢ 1 ⎥ intersect at a vanishing point
! ⎣ ⎦

Perspective Projection Matrix Projection System Setup


The coordinate system
Projecting (x, y, z, 1) (xd/z, yd/z, d, 1) and throwing
away d does not preserve the depth information The eye (e) (x’, y’, d, 1)
• acts as the focal point and COP (x, y, z, 1)
• placed at the origin
Instead want P such that:
⎡ d ⎤ • looking down (g) along the e g
x
⎡ x ⎤ ⎢ z
⎥ negative z-axis (axis of projection)
⎥ ⎢ ⎥ perspective

⎥→⎢ ⎥
y d divide
P⎢ y The screen
⎢ z ⎥ ⎢ z ⎥
⎢ 1 ⎥ ⎢ z'
⎥ preserve the relative • lies in the projection plane What does it mean for w=1?
⎣ ⎦ ⎢ ⎥ depth information of
• ⟘ to the z-axis, to the x-y plane What does it mean for w>1?
⎢⎣ 1 ⎥⎦ each point
What is the homogeneous
• located at distance d from the eye
Just like orthographic projection, we need to map
• d is a.k.a. the focal length coordinate (HC) when
projecting from 3D to 2D?
the view volume to a CVV instead of a 2D plane
Perspective Projection View Frustum From Frustum to CVV
View volume (frustum: truncated pyramid):
• defined by (left, right, top, bottom, near, far) clipping planes
• near (n) and far ( f ) distances along –z-axis,
both negative numbers, n > f View volume

• nothing nearer than n will be drawn


avoid numerical problems during
rendering, such as divide by 0 perspective
orthographic
• nothing further than f will be drawn projection,
projection
including
avoid low depth precision for distant objects perspective
divide

To preserve relative depth information,


we must map the frustum to a CVV instead of a 2D plane
RTR3

Perspective Projection Matrix Perspective Projection Matrix


⎡ x ⎤ ⎡ xd z ⎤
⎢ y ⎥ ⎢ ⎥
Want projection matrix P such that: P ⎢ ⎥ → ⎢
yd z ⎥ Second attempt: for a more generic matrix,
⎢ z ⎥ ⎢ z' ⎥ grab the depth info from the point itself:
⎢ 1 ⎥ ⎢ ⎥
What should P be? ⎣ ⎦ ⎣ 1 ⎦
• we’re projecting from 3D to 2D (not 4D to 3D), ⎡ d 0 0 0 ⎤⎡ x ⎤ ⎡ xd ⎤ ⎡ xd z ⎤
⎥⎢ ⎢ ⎥ ⎢ ⎥
use the HC of the projected point to store its depth ⎢ 0 d 0 0 y ⎥ ⎢ yd
⎥ ⎯ ⎯⎯⎯ ⎢ yd z ⎥
info (i.e., the “real” HC in 3D to 2D projection) Pp = ⎢ ⎥⎢ ⎥= after

⎢ 0 0 d 0 ⎥⎢ z ⎥ ⎢ zd ⎥ perspective
divide ⎢ d ⎥
• first attempt: ⎢ ⎥
⎡ xd z ⎤
⎢⎣ 0 0 1 0 ⎥⎦ ⎢
⎣ 1 ⎥⎦ ⎢⎣ ⎥
z ⎦ ⎣ 1 ⎦
⎡ d 0 0 0 ⎤ ⎡ x ⎤ ⎡ xd ⎤ !
⎢ 0 d 0 0 ⎥ ⎢ y ⎥ ⎢ yd ⎥ ⎢ ⎥
Pp = ⎢ ⎥⎢ ⎥= ⎢ ⎥ ⎯⎯⎯after
⎯perspective → ⎢ y d z ⎥ Are we done?
⎢ 0 0 d 0 ⎥ ⎢ z ⎥ ⎢ zd ⎥ divide ⎢ d ⎥
⎢ ⎥ • the projected x-, y-, and HC are correct already, but after
⎢⎣ 0 0 0 z ⎥⎦ ⎢ 1 ⎥ ⎢ z ⎥
! ⎣ ⎦ ⎣ ⎦ ⎣ 1 ⎦ perspective divide, all depths mapped to d!
Any problem? • 3rd row of matrix must be tweaked to preserve relative
depth info (z’)
Perspective Projection Matrix Perspective Projection Matrix
Frustum Rectangular box
For the 3rd row of P:
Let d = n ⎡ x ⎤ ⎡ xn z ⎤
⎢ y ⎥ ⎢ ⎥ • want a and b such that:
Want:!P ⎢ ⎥ → ⎢ yn z ⎥! ⎡ x ⎤ ⎡ x ⎤ ⎡ x ⎤ ⎡ xn f ⎤
⎢ z ⎥ ⎢ z' ⎥ ⎢ y ⎥ ⎢ y ⎥ ⎢ y ⎥ ⎢ ⎥
The 1st and 2nd rows of P are correct ⎢ 1 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ yn f ⎥
⎢ ⎥ → ⎢ ⎥ !and!P →
already, for the 3 row (third attempt): ⎣ ⎦ ⎣ 1
rd ⎦ P
! ⎢ n ⎥ ⎢ n ⎥ ⎢ f ⎥ ⎢ f ⎥
• the computation of z’ does not rely on x and y, ⎢ 1 ⎥ ⎢ 1 ⎥ ⎢ ⎥ ⎢ ⎥
! ⎣ ⎦ ⎣ ⎦ ⎣ 1 ⎦ ⎢⎣ 1 ⎥⎦
set the first two numbers of the row to 0
• we can use the remaining two numbers to • or, for z=n, a+b/z = n and for z=f, a+b/z = f
compute z’, let them be unknowns a and b for now: for!z = n : !a + b n = n, !a = n − b n
⎡ xn z ⎤ for!z = f : !a + b f = f ,
⎡ n 0 0 0 ⎤⎡ x ⎤ ⎡ xn ⎤
⎢ ⎥⎢ ⎢
y ⎥ ⎢ yn
⎥ ⎢ ⎥ substituting!for!a:! ( n − b n ) + b f = f nf
Pp = ⎢
0 n 0 0
⎥⎢ ⎥= ⎥ ⎯ ⎯⎯⎯
after
→ ⎢ y n z ⎥
⎢ 0 0 a b ⎥⎢ z ⎥ ⎢ az + b ⎥ perspective
divide
⎢ a+b z ⎥ b ( n − f ) = ( f − n ) nf , !b = −nf
⎢ ⎥
⎢⎣ 0 0 1 0 ⎥⎦ ⎢
⎣ 1 ⎥⎦ ⎢⎣ z ⎥
⎦ ⎢⎣ 1 ⎥⎦ !substituting!for!b:!a = n − ( −nf ) n, !a = n + f
!

Perspective Divide Perspective Foreshortening


Then divide by the homogenous coordinate What is the effect of perspective divide
squeezing the frustum into a rectangular box on the shape of objects?
⎡ xn z ⎤
⎡ n 0 0 0 ⎤⎡ x ⎤ ⎡ nx ⎤ ⎢ ⎥
⎢ ⎥⎢ ⎥ ⎢ ny
⎥ ⎢ yn z ⎥
⎢ 0 n 0 0 ⎥⎢ y ⎥ ⎢ ⎥ ⎯perspective
= ⎯⎯⎯ → ⎢ nf ⎥
⎢ 0 0 n+ f −nf ⎥⎢ z ⎥ ⎢ (n + f )z − nf ⎥ divide
⎢ n+ f − ⎥
⎥⎢ ⎢ ⎥
⎢ 1 ⎥⎦ ⎣ ⎢ ⎥
0 0 1 0 z
⎣ ⎦⎣ z ⎦ ⎢⎣ ⎥⎦
1

Note how n/z


conveniently cancels
the negative signs out After perspective divide, an object further away
Shirley02 appears to be smaller than an equal-size object nearby
Curless08
From Frustum to CVV Losing Depth Precision ⎡
x' ⎤ ⎢
⎡ nx z ⎤

⎢⎥
y' ⎥ ⎢ ⎥
ny z
Now reposition and scale the rectangular box Recall that after perspective divide we have: ⎢⎢ =⎢
z' ⎥ ⎢ n + f −
fn ⎥


1 ⎦⎥ ⎢ z ⎥
⎡ 2 r+l ⎤ ⎣ ⎢ ⎥
1
⎢ 0 0 − ⎥ As a consequence of perspective foreshortening, ⎣ ⎦
⎢ r−l r−l ⎥⎡ ⎤
⎢ 2 t+b ⎥⎢
n 0 0 0
⎥ z’ is not linearly related to z:
0 0 − 0 n 0 0
Pp = STP = Po P = ⎢ t−b t−b ⎥⎢ ⎥
⎢ ⎥⎢ 0 0 n+ f −nf ⎥
⎢ 0 2 n+ f ⎥⎢ ⎥ nf
0 − 0 0 1 0 z' = n + f −
⎢ n− f n− f ⎥⎣ ⎦
⎢ ⎥ z
⎢⎣ 0 0 0 1 ⎥⎦ nf Δz z2
⎡ 2n l+r ⎤ Δz ' ≈ ; !Δz ≈ Δz '
⎢ 0 0 ⎥ z 2
fn
Assume viewing transform has been ⎢ r−l l−r ⎥
b+t max !Δz!is!when!z = f
done, so after perspective divide ⎢
0
2n
0 ⎥
⎥ n→0
(not shown) we’re only dealing with =⎢ t −b b−t f
⎢ ⎥ At!z = f ,!Δz = Δz ', !as!n → 0,
axis-aligned viewing volume ⎢ 0 n+ f 2nf ⎥ n
0
⎢ n− f f −n ⎥ near!the!far!plane!(f ),!Δz → ∞!but!must!be!covered!by
Redbook10
⎢ ⎥
⎢⎣ 0 0 1 0 ⎥⎦
!the!same!Δz ' !as!smaller!Δz!that!are!closer!to!n
See also http://www.songho.ca/opengl/gl_projectionmatrix.html

Losing Depth Precision Losing Depth Precision


Δz1 Δz2
Δz’2, f
As a consequence of perspective foreshortening, far=100
z’ is not linearly related to z: as z gets closer to f, Δz’2, f

the same amount of Δz’ must represent larger Δz


Δz’1, n

For example: let n = 10, f = 90,


Δz’1, n
for z1 = 10, z’1 = 10 Δz1 = 1
for z2 = 11, z’2 = 18.182 Δz’1= 8.182
... RTR3

for zk-1 = 89, z’k-1 = 89.888 Δzk-1 = 1


for zk = 90, z’k = 90 Δz’k-1= 0.112
Implication of the non-linear mapping:
• information on the far plane loses precision
z-buffer punch through or z-fighting
• distances closer to origin are exaggerated
Effect is ameliorated if n set further from origin Akeley07
z-Buffer Quantization
z-values stored as non-negative integers
Integers are represented in b (=16 or 32) bits,
giving a range of B (= 2b) values {0, 1, 2, . . . , B-1}
Floating point z’-values are discretized into integer bins:
Δz’ = (f−n)/B, so for example for n = 10, f = 90, both
z1 = 89, z’1 = 100−(900/89) = 89.888 and
z2 = 90, z’2 = 100−(900/90) = 90
are both discretized to z’ = 90
Moral of the story: choose n as far away from origin as
possible and f as near as possible (to reduce Δz’)

You might also like