Upload
vladimir-kirkland
View
60
Download
0
Embed Size (px)
DESCRIPTION
第六章 視景圖形座標轉換. World → Device Transformation. Viewport. World. Device. Windows. WCS (World Coordinate System). PDCS (Physical Device Coordinate System). NDCS (Normalized Coordinate System). UCS (User Coordinate System). WCS:theoretically infinite. - PowerPoint PPT Presentation
Citation preview
1
第六章 視景圖形座標轉換
World → Device Transformation
World Device
Viewport
2
Windows
WCS (World Coordinate System)
NDCS (Normalized Coordinate System)
PDCS (Physical Device Coordinate System)
UCS (User Coordinate System)
WCS : theoretically infinite
Window : a finite region in WCS
Viewport : defines the physical location of the display area within the physical raster
3
Normalization Transformation (N) :
Workstation Transformation (W) :
World Coordinate NormalizedDevice Coordinates
map
Normalized DeviceCoordinate
mapPhysical DeviceCoordinate
Viewing Transformation (V) :V = W N‧
4
maxyw
minyw
minxw maxxw
P
Window
World Coordinate
0 1
1
Normalized DeviceCoordinate (parameter 0~1)
maxyv
minyv
minxv maxxv
WorkstationCoordinate
Viewport
100
0
0
minmin
minmin
yvywSS
xvxwSS
N yy
xx
5
Window – to – Viewport Transformation
Window Viewport
World Normalization Device
6
Mapped to viewport area
maxyw
minyw
minxw maxxw
ww yx ,
maxyv
minyv
minxv maxxv
vv yx ,
7
Point in Window ww yx , vv ,yx in a viewport
minmax
min
minmax
min
xvxv
xvxv
xwxw
xwxw
andminmax
min
minmax
min
yvyv
yvyv
ywyw
ywyw
minminminmax
minmax xvxwxwxwxw
xvxvxv
minminminmax
minmax yvywywywyw
yvyvyv
8
Window – to – Viewport Transformation
minmin
minmin
yvywywSy
xvxwxwSx
yv
xv
Scaling
y
x
S
SMaintain relative proportion( 保持比例 )
如果 yx SS Window size = Viewport size( 大小不變 )
1
1
1 不變放大縮小
Translation平移
min
min
yv
xv
9
Boundary Conflicts( 衝突 )
處理方法
1. Wraparound( 捲折 )
轉折至下方繼續
2. Scissoring( 切斷 )
在 Hardware上切斷
10
3. Saturation( 滲透 )
Boundary Conflicts ( cont. )處理方法
以 為基準向下擠
maxy
4. Clipping( 修剪 )
以 為基準切斷
maxy
11
CLIPPING
1. Analytical World
2. Raster World
幾何計算畫素計算
Point Clipping
PA point
is inside the window yxP ,
Visible
12
Both True maxmin xxx
maxmin yyy
Point Clipping (cont.)
Inside the Window
maxy
miny
maxxminx
13
Clipping lines
Analytical Clipping 1P2P
Check In or Out of 2 end points
Both In
Both Out
One In / One Out
Need to Check Parametric Equation
Need to Calculate Intersection points
14
Line Clipping 修剪
Cohen – Sutherland Algorithm
將 Clip rectangle 分為 9 份將 4-bit code assign 給每一點( 四個邊 )
Each end point
一條線的 2 端點, 每一端點給一個 Code
0 0 0 0 4 3 2 bit 1
從右至左,視 Window之關係位置給予 Code
15
Cohen – Sutherland Algorithm ( cont. )
bit 1 : left bit 2 : right
bit 3 : below bit 4 : above
1001
0001
0101 0100
0000Window
1000 1010
0010
0110
16
Cohen – Sutherland Algorithm ( cont. )bit 1 : sign bit of minxwx bit 2 : sign bit of xxw max
bit 3 : sign bit of minywy bit 4 : sign bit of yyw max
1001
0001
0101
1000
0000
0100
1010
0010
01102
4
3
51
10
6
78
9
17
Logical AND of both codes of end points
Line End point bit codes Logic AND Conclusion
12345
0000 00000100 01001000 00100000 00100001 0100
0000 00100 10000 00000 00000 0
Completely Visible Completely Invisible
No Conclusion Partially VisibleNo Conclusion
1. 0 0 2. 1 0 3. 0
4. 0 0
ANDANDAND
AND
結果 ,兩端全結果 ,兩端非結果 ,
結果 ,兩端皆非
Completely Visible
Completely Invisible
1 0 兩端有 、 Partially Visible
No Conclusion
判斷準則
18
Logical AND of both codes of end points (cont.)
ConclusionNo
VisiblePartiallyNeed to check intersection points
Line Codes of 2 end points AND Conclusion
6789
10
1001 10001000 00001001 00001001 00001001 0001
1000 0000 0000
0000 0001
Completely Invisible Partially Partially Partially
Completely Invisible
19
Partially Visible or No Conclusion( 求線與 Clipping Windows 之交點 )
1. Find Intersection Points
Line 2211 ,,, yxyx
12
12
xx
yym
2. In , Out Intersection Points
2211 ,,, yxyx
(1) 11 yxxmy
xx
LI
LI
(2) 11 yxxmy
xx
RI
RI
Left
Right
Ty
By
RxLx
TL xx , TR xx ,
BL xx , BR xx ,
20
(3)
BI
BI
yym
yyxx
1
1
(4)
TI
TI
yym
yyxx
1
1
Bottom
Top
3. Check Parametric Equations
Each Intersection
Point
Line4 Boundary Line
防止延伸線上的交點
(1) 121
121
,
yyyy
xxxx
yx
I
I
II
Line (線)10
21
(2) LRLI xxxx Boundary(邊界)
10
(3) BTTI yyyx 10
If (1) 、 (2) 、 (3) 皆成立 Intersection True
If 2 intersection points 2211 ,,, IIII yxyx
New Line
If 1 intersection point 2211 ,,, yxyxcheck
the point in window
( code 0000 )
for example 11, yx ( code 0000 ) and II yx ,
定義 New Line
22
Cyrus – Beck Technique
Algorithm :Clipping a 2-D line against a rectangle or a convex 凸 polygon
PEi
Edge Ei
P1P0
Ni
Normal of Edge Ei
(邊線法向量)
0 ii PEtPN
0 ii PEtPN
0 ii PEtPN
23
10PP
EEdge i
被切的線:多邊型的一邊:
Cyrus – Beck Technique (cont.)
(反時針)的:線的參數式:
NormalEEdgeN
tPPPtP
ii
010
在 Edge Ei 上任取一點 P Ei
取 3 個向量:( 1 ) PEi to P0
( 2 ) PEi 在 Edge Ei 上( 3 ) PEi to P1
24
根據
Cyrus – Beck Technique (cont.)
0 ii PEtPN 判斷
0 ii PEtPN
0 ii PEtPN
0 ii PEtPN 在外面 在 Edge 上 在內部
( Counterclockwise Edge Index )
Intersection Point : 10PP with Edge Ei
公式推導如下頁
25
0 ii PEtPN tP
Cyrus – Beck Technique (cont.)
代入
0010 ii PEtPPPN
0010 tPPNPEPN iii
DN
PEPNt
i
ii
0
and 01 PPD
26
Cyrus – Beck Technique (cont.)
P0
P1
P0
P1
P0
P1
PL
PLPL
PE
PE
PE
PEPL
Line 2Line 1 Line 3
交點分類: PE ( Potentially Energy )
PL ( Potentially Leaving )
27
0DN i
Cyrus – Beck Technique (cont.)
PE 090angle
0DN i PL 090angle
Choose a ( PE , PL ) pair
PE : with tE
PL : with tL
The intersecting line segment is defined by ( tE , tL )
28
Calculations for Parametric Line Clipping
Clip Edge Ei
Normal Ni
PEi P0-PEi
Left
Right
Bottom
Top
minxx
minxx
minxx
minxx
yx ,min
yx ,max
min, yx
max, yx
yyxx 0min0 ,
yyxx 0max0 ,
min00 , yyxx
max00 , yyxx
DN
PEPNt
i
ii
0
01
min0
xx
xx
01
max0
xx
xx
01
min0
yy
yy
01
max0
yy
yy
0,1
0,1
1,0
1,0
29
Calculations for Parametric Line Clipping
maxy
miny
minx maxx
11, yx 00 , yx
30
Clipping Polygons
2 Polygons Clipping Each Line
before after
31
Sutherland – Hodgman Algorithm
Polygon : a set of ordered vertices
Compare a polygon to each boundary
Output is a set of vertices defining polygon
依序比較 2 polygons 利用切斷各邊
Original Clip Left Clip Right Clip Bottom Clip Top
32
Polygon – Polygon Clipping
Sutherland – Hodgman Algorithm
Polygon nvvvG ,, 21 clockwise
Traverse vertices clockwise
S :前一點 P :目前點
S
P P SI
S
P S
IP
IN→INSave P
IN→OUTSave I
OUT→OUTNo Save
OUT→INSave I , P
33
Saved Vertices New Polygon
2
6
1
3
4
5
1‘
5‘
2‘
4‘3‘
1‘
5‘
2‘
4‘3‘
34
View Volume
In 3 – D viewing :Projection( 投影 ) Window is used to define a View Volume.
View plane is z = 0 plane
Window is defined by maxmaxminmin ,,, ywxwywxw
on the view plane
Only those objects within the view volume areprojected and displayed on the view plane.
只有在 view volume 內的物體才會被投影及顯示
35
View Volume (cont.)
View volome
WindowWindow
View volome
Parallel Projection Perspective Projection
Truncated Pyramid Frustum截斷角錐幾何體
36
View Volume (cont.)
y
x
z
No display on view plane
y
x
zNo display on view plane
37
Parallel Projection
Far Plane
Window
View VolumeNear Plane
dndf
near : hither此處
far : yon plane彼處 near : front far : back
38
Perspective Projection
dn
df
View Volume
Near Plane
Window
Center ofProjectio
n
39
3 - D
Viewport is a regular parallelepiped( 平行六面體 ) defined innormalized coordinates
3 - D Window - to – viewport mapping
1
000
000
000
zyx
z
y
x
KKK
D
D
D比例
位移
40
3 - D Window - to - viewport mapping (cont.)
dndf
minmax ywyw
minmax xwxw
minmax zvzv
minmax ywyw
minmax xwxw
View Volume 3 - D viewport
y
xz
41
3 - D Window - to - viewport mapping (cont.)
minmax
minmax
xwxw
xvxvDx
minmax
minmax
ywyw
yvyvDy
max min
max minz
zv zvD
zw zw
View Volume : defined by maxmaxminmin ,,, ywxwywxw
and dndf ,
3 - D viewport : defined by maxmaxminmin ,,, vwxvyvxv
and maxmin , zvzv
xx DxwxvK minmin yy DywyvK minmin zz DdnzvK min
42
Clipping against a normalized View Volume
Extension of
orithmABeckCyrus
orithmASutherlandCohen
lg
lg
Code of 6 bits right to left( 六個面 )
000000 back front above below right left
Bit6
Bit1
後 前 上 下 右 左
43
Code of 6 bits right to left (cont.)
bit 1bit 2
bit 3
bit 4
bit 5
bit 6
leftright
below
above
front
back
minxvx
maxxvx
minyvy
maxyvy
minzvz
maxzvz
CodeCode
Logical AND of 2 codes
2 end points of a line
44
Code of 6 bits right to left (cont.)
判斷結果AND = 0 ,兩端皆 0 Inside
AND = 1 ,兩端有 1 Outside
AND = 0 ,兩端有 1 , 0 Partially Inside
AND = 0 ,兩端都有 1 No Conclusion
Check Intersection Points 6 Intersection Points
45
Code of 6 bits right to left (cont.)
Line
1111 ,, zyxP 2222 ,, zyxP
uzzzz
uyyyy
uxxxx
121
121
121
其中 1~0u
1. Intersection of a line with a ( face plane ) of view volume
2. with front minzvz
12
1min
zz
zzvu
46
2. with front
(1) If u not in (0 ~ 1)
Line segment does not intersect
(2) If uin (0 ~ 1)
min
121
12
1min121
zvz
uyyyy
zz
zzvxxxx
I
I
I
(3) If neither Ix Iynor is in
beyond boundary( 超出邊界 )
47
y
z
3. Check Intersection with 6 ( faces ) planes
P2
P1
P2
P1
B
A
maxzvminzv
minyv
maxyv
Side View
48
Cyrus - Beck Algorithm 用在 3 - D