2d windows - cs.carleton.edu · 2d windows world coordinates: coordinate system in which objects...
TRANSCRIPT
![Page 1: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/1.jpg)
2D WindowsWorld Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc.
xw
yw
![Page 2: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/2.jpg)
2D WindowsScreen Coordinates: Coordinate system in which objects are displayed. Usually measured in pixels
xs
ys
CRT Display
![Page 3: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/3.jpg)
2D Windows
xw
ywWorld coordinates are limited by specifying a world window
xwl xwr
ywt
ywb
![Page 4: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/4.jpg)
2D Windows
xw
ywAn “eye” coordinate system is placed at the center of this window.
xwl xwc xwr
ywt
ywc
ywb
xe
ye
xe = xwxwcye = ywywc
![Page 5: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/5.jpg)
2D Windows
xs
ys
A “viewport” is specified in the screen coordinate system centered on its own internal coordinate system
xvl xvc xvr
yvt
yvc
yvb
xv
yv
![Page 6: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/6.jpg)
2D Windows
xS
yS
GOAL: Map world window onto the viewport.
xvl xvr
yvt
yvb
xW
yW
xwl xwr
ywt
ywb
![Page 7: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/7.jpg)
2D Windows
xS
GOAL: Map world window onto the viewport.
xv = xe*(xvrxvl)/(xwrxwl) + xvc
yv = ye*(yvtyvb)/(ywtywb) + yvc
where xe = xwxwc ye = ywywc
![Page 8: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/8.jpg)
2D Clipping
World Window xwl xwr
ywt
ywb
xvl xvr
yvt
yvb
ViewportWHERE ?????
![Page 9: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/9.jpg)
2D Clipping
P
Q
PC
QC
(PC,QC) = Clip(P,Q,Window)
![Page 10: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/10.jpg)
2D Clipping
P
Q
PC
QCP
Q
P
Q
Cases:
I. Trivial Accept
II. Trivial Reject
III. Clip
I
IIIII
Clipping Philosophy: any algorithm should be fast for cases I and II
![Page 11: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/11.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
xb = window edge
(x1,y1)
(x2,y2)
y = (y2y1)/(x2x1)*(xx1) + y1
Let x = xb and compute y
![Page 12: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/12.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
xb = window edge
(x1,y1)
(x2,y2)
Integer Arithmetic – Midpoint Subdivision
repeat { xm = (x1+x2)/2;ym =(y1+y2)/2; if (xm>xb) { x2 = xm; y2 = ym;} else {x1 = xm; y1 = ym;} } until (x1==xb||x2 == xb)
if (x1==xb) y = y1 else y = y2;
![Page 13: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/13.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
xb = window edge
(x1,y1)
(x2,y2)
Integer Arithmetic – Midpoint Subdivision
repeat { xm = (x1+x2)/2;ym =(y1+y2)/2; if (xm>xb) { x2 = xm; y2 = ym;} else {x1 = xm; y1 = ym;} } until (x1==xb||x2 == xb)
if (x1==xb) y = y1 else y = y2;
![Page 14: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/14.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
xb = window edge
(x1,y1)
(x2,y2)
Integer Arithmetic – Midpoint Subdivision
repeat { xm = (x1+x2)/2;ym =(y1+y2)/2; if (xm>xb) { x2 = xm; y2 = ym;} else {x1 = xm; y1 = ym;} } until (x1==xb||x2 == xb)
if (x1==xb) y = y1 else y = y2;
![Page 15: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/15.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
xb = window edge
(x1,y1)
(x2,y2)
Integer Arithmetic – Midpoint Subdivision
repeat { xm = (x1+x2)/2;ym =(y1+y2)/2; if (xm>xb) { x2 = xm; y2 = ym;} else {x1 =xm; y1 = ym;} } until (x1==xb||x2 == xb)
if (x1==xb) y = y1 else y = y2;
![Page 16: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/16.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
yt
yb
xl xr
1010 1000 1001
0010 0000 0001
0110 0100 0101
yt yb xl xr
4 bit code
bit i of Code(P) = 0 if point P on same side of line i as window else = 1
![Page 17: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/17.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
yt
yb
xl xr
1010 1000 1001
0010 0000 0001
0110 0100 0101
& = bitwise logical and
if Code(P) & Code(Q) != 0000then reject
if (Code(P)==0000) &&(Code(Q)== 0000)then accept
P
P
Q
Q
![Page 18: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/18.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
P
Q
QC
Far(P,Q,W) returns the point in the window W farthest from P along line segment PQ. If there is no farthest point it returns P.
P
Q
![Page 19: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/19.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
P
Q
QC
P
Q
Clip(P,Q,W) { QC = Far(P,Q,W); if (QC==P) return REJECT; else { PC = Far(Q,P,W); return (PC,QC); } }
![Page 20: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/20.jpg)
Clipping in the Viewport The CohenSutherland Algorithm
P
Q
QC
P
Q
Clip(P,Q,W) { QC = Far(P,Q,W); if (QC==P) return REJECT; else { PC = Far(Q,P,W); return (PC,QC); } }
PC
![Page 21: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/21.jpg)
Far(P,Q,W)Far(P,Q,W) { P1 = P; if (Code(Q) == 0000) return Q; else if (Code(P)&Code(Q) != 0000) return P;
![Page 22: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/22.jpg)
Far(P,Q,W)Far(P,Q,W) { P1 = P; if (Code(Q) == 0000) return Q; else if (Code(P)&Code(Q) != 0000) return P; else { quit = false; do { PM = (P+Q)/2; if (Code(PM)&Code(Q)!= 0000) if (Code(PM)&Code(P) != 0000) { quit = true; Q = P1; }
P
Q
PM
![Page 23: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/23.jpg)
Far(P,Q,W)Far(P,Q,W) { P1 = P; if (Code(Q) == 0000) return Q; else if (Code(P)&Code(Q) != 0000) return P; else { quit = false; do { PM = (P+Q)/2; if (Code(PM)&Code(Q)!= 0000) if (Code(PM)&Code(P) != 0000) { quit = true; Q = P1; } else Q = PM;
P
Q
PM
![Page 24: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/24.jpg)
Far(P,Q,W)Far(P,Q,W) { P1 = P; if (Code(Q) == 0000) return Q; else if (Code(P)&Code(Q) != 0000) return P; else { quit = false; do { PM = (P+Q)/2; if (Code(PM)&Code(Q)!= 0000) if (Code(PM)&Code(P) != 0000) { quit = true; Q = P1; } else Q = PM; else P = PM;
P
Q
PM
![Page 25: 2D Windows - cs.carleton.edu · 2D Windows World Coordinates: Coordinate system in which objects are described. May be measured in feet, miles, centimeters, etc. xw yw. 2D Windows](https://reader034.vdocuments.mx/reader034/viewer/2022052006/601a805de7839e735b387dfb/html5/thumbnails/25.jpg)
Far(P,Q,W)Far(P,Q,W) { P1 = P; if (Code(Q) == 0000) return Q; else if (Code(P)&Code(Q) != 0000) return P; else { quit = false; do { PM = (P+Q)/2; if (Code(PM)&Code(Q)!= 0000) if (Code(PM)&Code(P) != 0000) { quit = true; Q = P1; } else Q = PM; else P = PM; while (|P-Q| > tolerance || !quit); } }