Polygon ClippingExamine the edges of given poly relative to current clipper and add point to new poly
s
p
outside viewnothing added
Polygon ClippingExamine the edges of given poly relative to current clipper and add point to new poly
s
p
entering viewoutput i and p
i
Polygon ClippingExamine the edges of given poly relative to current clipper and add point to new poly
s
p
inside viewoutput p only
Polygon ClippingExamine the edges of given poly relative to current clipper and add point to new poly
s
p
exiting viewoutput i only
i
Polygon ClippingExamine the edges of given poly relative to current clipper and add point to new poly
s
p
outside viewnothing added
s
p
entering viewoutput i and p
i
s
p
inside viewoutput p only
s
p
exiting viewoutput i only
i
VectorsDescribe a direction in space
all vectors below represent the same direction
represented by the (x, y) coords of the vector anchored at the origin
VectorsVector (direction) defined by two points
vx = P
1(x) – P
0(x) different from v
x = P
0(x) - P
1(x)
vy = P
1(y) – P
0(y) v
y = P
0(y) - P
1(y)
P0
P1v
v
VectorsVector (direction) defined by two points
vx = P
1(x) – P
0(x)
vy = P
1(y) – P
0(y)
In vector form
v = P0P1 = P
1 - P
0P0
P1v
vP0
P1
Vector OperationsLength
|v| = sqrt(vx·v
x + v
y·v
y)
Addition/Subtraction
w = u ± v wx = v
x ± u
x, w
y = v
y ± u
y
Scalar multiplication
u = c·v ux = c·v
x, u
y = c·v
does not change the direction, just the magnitude
Dot product (vector multiplication)
c = u·v = vx·u
x + v
y·u
y = |v|·|u|·cos a
dot product is a scalar (number), not a vector
Vector OperationsDot product is useful for determining angle between vectors
u·v > 0 if angle < 90
u·v = 0 if angle == 90
u·v < 0 if angle > 90
Line / Edge IntersectionParametric line equation given two points P
0 and P
1 on the line
P = P0 + P
0P1·t , t in (-∞ , +∞)
x = P0(x) + P
0P1(x)·t
y = P0(y) + P
0P1(x)·t
t = 0
P0
P1
t = 1
t < 0
for points
behind P0
t > 0
for points
after P1
Line / Edge Intersection
P0
P1
Pi
Given a clipper and an edge (P0,P
1)
decide if P1 is inside the visible area
find the intersection Pi
Line / Edge Intersection
P0
P1
Pe
Pi
Given a clipper and an edge (P0,P
1)
decide if P1 is inside the visible area – N·P
eP1 < 0 means P
1 is inside
pick a point Pe on the clipper
pick a vector perpendicular to clipper
use dot product
N·PeP1 < 0 means P
1 is inside N
Line / Edge Intersection
P0
P1
Pe
Pi
Given a clipper and an edge (P0,P
1)
decide if P1 is inside the visible area – N·P
eP1 < 0 means P
1 is inside
find the intersection Pi
N·PePi = 0 since N
perp. to clipper
N·(Pi-P
e) = 0 rewritten
P = P0 + P
0P1·t line equation of edge
Pi = P
0 + P
0P1·t
isome t
i will give P
i
N·(P0 + P
0P1·t
i - P
e) = 0 replace P
i
N·(P0-P
e + P
0P1·t
i) = 0 rearrange
N·(PeP0 + P
0P1·t
i) = 0
N·PeP0 + N·P
0P1·t
i) = 0
ti = –N·P
eP0 / N·P
0P1
N
PeP1
PePi