HW 2D CGA - PPT 6 - Polygon Clipping
Question 1 |
Solution:
Sutherland-Hodgman MethodWe will be solving this problem with visual clipping so there will be no calculations. Below is the graph of the polygon before any clipping is done:
Polygon before clipping |
First clipping at TOP EDGE |
Second clipping at RIGHT EDGE |
Third clipping at BOTTOM EDGE |
Fourth clipping at LEFT EDGE |
Polygon after clipping |
Weiler-Atherton Method
Below is the graph containing polygon P with it's members p1, p2, p3, p4, p5, p6, p7, p8, and p9. By using Weiler-Atherton Method we first of all need to declare the intersections of all the edges of polygon P with edges of clipping window W. This results in 4 intersections i1, i2, i3, and i4 as stated in the graph below:
Polygon graph |
These are basically the rules to follow to determine the directions of each vertex:
- Start at "entering" intersection.
- Traverse on CLP (black arrow) until encounter "leaving" intersection. Then traverse on blue arrow.
- Traverse on CLW (blue arrow) until encounter "entering" intersection. Then traverse on black arrow.
- Repeat until we reach initial "entering" intersection.
Solution using Weiler-Atherton Method |
- i2 - p4 - i3 - w3 - i2
- i4 - p1 - i1 - w1 - i4
Question 2 |
Solution:
Here's the basic calculations we need down this solution:$$
\begin{array}
aP_1(0, 0), \ P_2(0, 6), \ P_3(6, 6), \ P_4(3, 3), \ P_5(6, 0) \\
W_1(4, 9), \ W_2(12, 1), \ W_3(4, 1)
\end{array}
$$
Next up are the vectors of window clipping edges and their normal
$$
\overrightarrow {E_1} = \overrightarrow {w_1 w_2} = \begin{bmatrix} 12 - 4\\1 - 9 \end{bmatrix} = \begin{bmatrix} 8\\-8 \end{bmatrix}, \overrightarrow {N_1} = \begin{bmatrix} dy\\-dx \end{bmatrix} = \begin{bmatrix} -8\\-8 \end{bmatrix}
$$
Because of dx > 0 and dy < 0, vector \( \overrightarrow {E_1}\) is going downwards right bottom), so \(\overrightarrow {N_1}\) is facing right \( [dy \ -dx]^T \)
$$
\overrightarrow {E_2} = \overrightarrow {w_2 w_3} = \begin{bmatrix} 4 - 12\\1 - 1 \end{bmatrix} = \begin{bmatrix} -8\\0 \end{bmatrix}, \overrightarrow {N_2} = \begin{bmatrix} dy\\-dx \end{bmatrix} = \begin{bmatrix} 0\\8 \end{bmatrix}
$$
Because of dx < 0 and dy = 0, vector \( \overrightarrow {E_2}\) is going left, so \(\overrightarrow {N_2}\) is facing upwards \( [dy \ -dx]^T \)
$$
\overrightarrow {E_3} = \overrightarrow {w_3 w_1} = \begin{bmatrix} 4 - 4\\9 - 1 \end{bmatrix} = \begin{bmatrix} 0\\8 \end{bmatrix}, \overrightarrow {N_2} = \begin{bmatrix} dy\\-dx \end{bmatrix} = \begin{bmatrix} 8\\0 \end{bmatrix}
$$
Because of dx = 0 and dy > 0, vector \( \overrightarrow {E_3}\) is going upwards, so \(\overrightarrow {N_3}\) is facing right \( [dy \ -dx]^T \). After the basics are laid out, we can continue to the first method:
Sutherland-Hodgman Method
This method basically clips the polygon in sequence based on each window clipping edge, so we're going to clip the polygon based on \( \overrightarrow {E_1}, \overrightarrow {E_2}, and \ \overrightarrow {E_3}\) respectively.
Clipping edge \( \overrightarrow {E_1} \)
$$
\begin{align}
\overrightarrow {w_1 p_1} \cdot \overrightarrow {N_1} &= \begin{bmatrix}0-4\\0-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}-4\\-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = 32 + 72 = 104 \\
\overrightarrow {w_1 p_2} \cdot \overrightarrow {N_1} &= \begin{bmatrix}0-4\\6-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}-4\\-3\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = 32 + 24 = 56 \\
\overrightarrow {w_1 p_3} \cdot \overrightarrow {N_1} &= \begin{bmatrix}6-4\\6-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}2\\-3\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = -16 + 24 =8 \\
\overrightarrow {w_1 p_4} \cdot \overrightarrow {N_1} &= \begin{bmatrix}3-4\\3-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}-1\\-6\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = 8 + 48 =56 \\
\overrightarrow {w_1 p_5} \cdot \overrightarrow {N_1} &= \begin{bmatrix}6-4\\0-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}2\\-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = -16 + 72 = 56
\end{align}
$$
From the results above, if it's positive then the point is inside \(\overrightarrow {E_1}\), if negative then the point is outside. Below is the table generated as the result of the calculation above:
$$
\begin{array} {|r|r|}\hline
Edge & p_1 & p_2 & p_3 & p_4 & p_5 \\ \hline
\overrightarrow {E_1} & in & in & in & in & in \\ \hline \end{array}
$$
From the table above we can also assign new points for next clipping edge to process as defined below:
$$
\begin{array} {|r|r|}\hline
Edge & Status & Take & As \\ \hline
\overrightarrow {p_1 p_2} & in \ in & endpoint \ p_2 & q_1(0, 6) \\ \hline
\overrightarrow {p_2 p_3} & in \ in & endpoint \ p_3 & q_2(6, 6) \\ \hline
\overrightarrow {p_3 p_4} & in \ in & endpoint \ p_4 & q_3(3, 3) \\ \hline
\overrightarrow {p_4 p_5} & in \ in & endpoint \ p_5 & q_4(6, 0) \\ \hline
\overrightarrow {p_5 p_1} & in \ in & endpoint \ p_1 & q_5(0, 0) \\ \hline
\end{array}
$$
Clipping edge \( \overrightarrow {E_2} \)
$$
\begin{align}
\overrightarrow {w_2 q_1} \cdot \overrightarrow {N_2} &= \begin{bmatrix}0-12\\6-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-12\\5\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + 40 = 40 \\
\overrightarrow {w_2 q_2} \cdot \overrightarrow {N_2} &= \begin{bmatrix}6-12\\6-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-6\\5\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + 40 = 40 \\
\overrightarrow {w_2 q_3} \cdot \overrightarrow {N_2} &= \begin{bmatrix}3-12\\3-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-9\\2\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + 16 = 16 \\
\overrightarrow {w_2 q_4} \cdot \overrightarrow {N_2} &= \begin{bmatrix}6-12\\0-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-6\\-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + (-8) = -8 \\
\overrightarrow {w_2 q_5} \cdot \overrightarrow {N_2} &= \begin{bmatrix}0-12\\0-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-12\\-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + (-8) = -8
\end{align}
$$
From the results above, if it's positive then the point is inside \(\overrightarrow {E_2}\), if negative then the point is outside. Below is the table generated as the result of the calculation above:
$$
\begin{array} {|r|r|}\hline
Edge & q_1 & q_2 & q_3 & q_4 & q_5 \\ \hline
\overrightarrow {E_2} & in & in & in & out & out \\ \hline \end{array}
$$
From the table above we can also assign new points for next clipping edge to process as defined below:
$$
\begin{array} {|r|r|}\hline
Edge & Status & Take & As \\ \hline
\overrightarrow {q_1 q_2} & in \ in & endpoint \ q_2 & r_1(6, 6) \\ \hline
\overrightarrow {q_2 q_3} & in \ in & endpoint \ q_3 & r_2(3, 3) \\ \hline
\overrightarrow {q_3 q_4} & in \ out & intersection \ i_1 & r_3(..., ...) \\ \hline
\overrightarrow {q_4 q_5} & out \ out & do \ nothing & \\ \hline
\overrightarrow {q_5 q_1} & out \ in & intersection i_2 & r_4(..., ...) \\
&& endpoint \ q_1 & r_5(0, 0) \\ \hline
\end{array}
$$
We must find \(i_1\) and \(i_2\) so we can find out \(r_3\) and \(r_4\)
$$
t_1 = \frac {\overrightarrow {q_3 w_2} \cdot \overrightarrow {N_2}}{\overrightarrow {q_3 q_4} \cdot \overrightarrow {N_2}}= \frac {\begin{bmatrix} 12-3\\1-3 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}} {\begin{bmatrix} 6-3\\0-3 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}}=\frac {\begin{bmatrix} 9\\-2 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}} {\begin{bmatrix} 3\\-3 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}}=\frac{0+(-16)}{0+(-24)}=\frac {2}{3}
$$
We know that \(q_3\)(3, 3) and \(q_4\)(6, 0)
$$
\begin{align}
Ox &= q_3 x + t_1 (q_4 x - q_3 x)\\
&=3 + \frac {2}{3}(6 - 3)\\
&=3 + \frac {2}{3}(3) \\
&=3 + 2\\
Ox &= 5
\end{align}
$$
$$
\begin{align}
Oy &= q_3 y + t_1 (q_4 y - q_3 y)\\
&=3 + \frac {2}{3}(0 - 3)\\
&=3 + \frac {2}{3}(-3) \\
&=3 + (-2)\\
Oy &= 1
\end{align}$$
We got \(i_1\)(5, 1). Now for \(i_2\)
$$
t_2 = \frac {\overrightarrow {q_5 w_2} \cdot \overrightarrow {N_2}}{\overrightarrow {q_5 q_1} \cdot \overrightarrow {N_2}}= \frac {\begin{bmatrix} 12-0\\1-0 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}} {\begin{bmatrix} 0-6\\6-0 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}}=\frac {\begin{bmatrix} 12\\1\end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}} {\begin{bmatrix} 0\\6 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}}=\frac{0+8}{0+48}=\frac {1}{6}
$$
We know that \(q_5\)(0, 0) and \(q_1\)(0, 6)
$$
\begin{align}
Ox &= q_5 x + t_2 (q_1 x - q_5 x)\\
&=0 + \frac {1}{6}(0 - 0)\\
&=\frac {1}{6}(0) \\
Ox &= 0
\end{align}
$$
$$
\begin{align}
Oy &= q_5 y + t_2 (q_1 y - q_5 y)\\
&=0 + \frac {1}{6}(6 - 0)\\
&=\frac {1}{6}(6) \\
Oy &= 1
\end{align}$$
So we've got \(i_2\)(0, 1). \(r_3\) is \(i_1\) so \(r_3\)(5, 1) and \(r_4\) is \(i_2\) so \(r_4\)(0, 1). Below is the final table for \(\overrightarrow {E_2}\) clipping edge
$$
\begin{array} {|r|r|}\hline
Edge & Status & Take & As \\ \hline
\overrightarrow {q_1 q_2} & in \ in & endpoint \ q_2 & r_1(6, 6) \\ \hline
\overrightarrow {q_2 q_3} & in \ in & endpoint \ q_3 & r_2(3, 3) \\ \hline
\overrightarrow {q_3 q_4} & in \ out & intersection \ i_1 & r_3(5, 1) \\ \hline
\overrightarrow {q_4 q_5} & out \ out & do \ nothing & \\ \hline
\overrightarrow {q_5 q_1} & out \ in & intersection i_2 & r_4(0, 1) \\
&& endpoint \ q_1 & r_5(0, 0) \\ \hline
\end{array}
$$
Clipping edge \( \overrightarrow {E_3} \)
$$
\begin{align}
\overrightarrow {w_3 r_1} \cdot \overrightarrow {N_3} &= \begin{bmatrix}6-4\\6-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}2\\5\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = 16 + 0 = 16 \\
\overrightarrow {w_3 r_2} \cdot \overrightarrow {N_3} &= \begin{bmatrix}3-4\\3-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}-1\\2\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = -8 + 0 = -8 \\
\overrightarrow {w_3 r_3} \cdot \overrightarrow {N_3} &= \begin{bmatrix}5-4\\1-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}1\\0\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = 8 + 0 = 8 \\
\overrightarrow {w_3 r_4} \cdot \overrightarrow {N_3} &= \begin{bmatrix}0-4\\1-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}-4\\0\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = -32 + 0 = -32 \\
\overrightarrow {w_3 r_5} \cdot \overrightarrow {N_3} &= \begin{bmatrix}0-4\\6-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}-4\\5\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = -32 + 0 = -32 \\
\end{align}
$$
From the results above, if it's positive then the point is inside \(\overrightarrow {E_3}\), if negative then the point is outside. Below is the table generated as the result of the calculation above:
$$
\begin{array} {|r|r|}\hline
Edge & r_1 & r_2 & r_3 & r_4 & r_5 \\ \hline
\overrightarrow {E_3} & in & out & in & out & out \\ \hline \end{array}
$$
From the table above we can also assign new points for next clipping edge to process as defined below:
$$
\begin{array} {|r|r|}\hline
Edge & Status & Take & As \\ \hline
\overrightarrow {r_1 r_2} & in \ out & intersection \ i_1 & s_1(..., ...) \\ \hline
\overrightarrow {r_2 r_3} & out \ in & intersection \ i_2 & s_2(..., ...) \\
&& endpoint \ r_3 & s_3(5, 1)\\ \hline
\overrightarrow {r_3 r_4} & in \ out & intersection \ i_3 & s_4(..., ...) \\ \hline
\overrightarrow {r_4 r_5} & out \ out & do \ nothing & \\ \hline
\overrightarrow {r_5 r_1} & out \ in & intersection \ i_4 & s_5(..., ...) \\
&& endpoint \ r_1 & s_6(6, 6) \\ \hline
\end{array}
$$
We must find \(i_1\), \(i_2\), \(i_3\), and \(i_4\) so we can find out \(s_1\), \(s_2\), \(s_4\), and \(s_5\)
$$
t_1 = \frac {\overrightarrow {r_1 w_3} \cdot \overrightarrow {N_3}}{\overrightarrow {r_1 r_2} \cdot \overrightarrow {N_3}}= \frac {\begin{bmatrix} 4-6\\1-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} 3-6\\3-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac {\begin{bmatrix} -2\\-5\end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} -3\\-3 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac{-16+0}{-24+0}=\frac {2}{3}
$$
We know that \(r_1\)(6, 6) and \(r_2\)(3, 3)
$$
\begin{align}
Ox &= r_1 x + t_1 (r_2 x - r_1 x)\\
&=6 + \frac {2}{3}(3 - 6)\\
&=6 + \frac {2}{3}(-3) \\
&=6 + (-2)\\
Ox &= 4
\end{align}
$$
$$
\begin{align}
Oy &= r_1 y + t_1 (r_2 y - r_1 y)\\
&=6 + \frac {2}{3}(3 - 6)\\
&=6 + \frac {2}{3}(-3) \\
&=6 + (-2)\\
Oy &= 4
\end{align}$$
We got \(i_1\)(4, 4). Now for \(i_2\)
$$
t_2 = \frac {\overrightarrow {r_2 w_3} \cdot \overrightarrow {N_3}}{\overrightarrow {r_2 r_3} \cdot \overrightarrow {N_3}}= \frac {\begin{bmatrix} 4-3\\1-3 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} 5-3\\1-3 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac {\begin{bmatrix} 1\\-2\end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} 2\\-2 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac{8+0}{16+0}=\frac {1}{2}
$$
We know that \(r_2\)(3, 3) and \(r_3\)(5, 1)
$$
\begin{align}
Ox &= r_2 x + t_2 (r_3 x - r_2 x)\\
&=3 + \frac {1}{2}(5 - 3)\\
&=3 + \frac {1}{2}(2) \\
&=3 + 1\\
Ox &= 4
\end{align}
$$
$$
\begin{align}
Oy &= r_2 y + t_2 (r_3 y - r_2 y)\\
&=3 + \frac {1}{2}(1 - 3)\\
&=3 + \frac {1}{2}(-2) \\
&=3 + (-1)\\
Oy &= 2
\end{align}$$
So we've got \(i_2\)(4, 2). Now for \(i_3\)
$$
t_3 = \frac {\overrightarrow {r_3 w_3} \cdot \overrightarrow {N_3}}{\overrightarrow {r_3 r_4} \cdot \overrightarrow {N_3}}= \frac {\begin{bmatrix}4-5\\1-1 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} 0-5\\1-1 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac {\begin{bmatrix} -1\\0\end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} -5\\0 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac{-8+0}{-40+0}=\frac {1}{5}
$$
We know that \(r_3\)(5, 1) and \(r_4\)(0, 1)
$$
\begin{align}
Ox &= r_3 x + t_3 (r_4 x - r_3 x)\\
&=5 + \frac {1}{5}(0 - 5)\\
&=5 + \frac {1}{5}(-5) \\
&=5 + (-1)\\
Ox &= 4
\end{align}
$$
$$
\begin{align}
Oy &= r_3 y + t_3 (r_4 y - r_3 y)\\
&=1 + \frac {1}{5}(1 - 1)\\
&=1 + \frac {1}{2}(0) \\
&=1 + 0\\
Oy &= 1
\end{align}$$
So we've got \(i_3\)(4, 1). Now for \(i_4\)
$$
t_4 = \frac {\overrightarrow {r_5 w_3} \cdot \overrightarrow {N_3}}{\overrightarrow {r_5 r_1} \cdot \overrightarrow {N_3}}= \frac {\begin{bmatrix}4-0\\1-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} 6-0\\6-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac {\begin{bmatrix} 4\\-5\end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} {\begin{bmatrix} 6\\0 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}=\frac{32+0}{48+0}=\frac {2}{3}
$$
We know that \(r_5\)(0, 6) and \(r_1\)(6, 6)
$$
\begin{align}
Ox &= r_5 x + t_4 (r_1 x - r_5 x)\\
&= 0 + \frac {2}{3}(6 - 0)\\
&= \frac {2}{3}(6) \\
Ox &= 4
\end{align}
$$
$$
\begin{align}
Oy &= r_5 y + t_4 (r_1 y - r_5 y)\\
&=6 + \frac {2}{3}(6 - 6)\\
&=6 + \frac {2}{3}(0) \\
&=6 + 0\\
Oy &= 6
\end{align}$$
So we've got \(i_4\)(4, 6). \(s_1\) is \(i_1\) so \(s_1\)(4, 4), \(s_2\) is \(i_2\) so \(s_2\)(4, 2), \(s_4\) is \(i_3\) so \(s_4\)(4, 1), and \(s_5\) is \(i_4\) so \(s_5\)(4, 6). Below is the final table for \(\overrightarrow {E_3}\) clipping edge
$$
\begin{array} {|r|r|}\hline
Edge & Status & Take & As \\ \hline
\overrightarrow {r_1 r_2} & in \ out & intersection \ i_1 & s_1(4, 4) \\ \hline
\overrightarrow {r_2 r_3} & out \ in & intersection \ i_2 & s_2(4, 2) \\
&& endpoint \ r_3 & s_3(5, 1)\\ \hline
\overrightarrow {r_3 r_4} & in \ out & intersection \ i_3 & s_4(4, 1) \\ \hline
\overrightarrow {r_4 r_5} & out \ out & do \ nothing & \\ \hline
\overrightarrow {r_5 r_1} & out \ in & intersection \ i_4 & s_5(4, 6) \\
&& endpoint \ r_1 & s_6(6, 6) \\ \hline
\end{array}
$$
The result of Sutherland-Hodgman Method for this polygon is \(s_1\)(4, 4), \(s_2\)(4, 2), \(s_3\)(5, 1), \(s_4\)(4, 1), \(s_5\)(4, 6), and \(s_6\)(6, 6).
Weiler-Atherton Method
First of all we need to create the table
$$
\begin{align}
\overrightarrow {w_1 p_1} \cdot \overrightarrow {N_1} &= \begin{bmatrix}0-4\\0-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}-4\\-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = 32 + 72 = 104 \\
\overrightarrow {w_1 p_2} \cdot \overrightarrow {N_1} &= \begin{bmatrix}0-4\\6-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}-4\\-3\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = 32 + 24 = 56 \\
\overrightarrow {w_1 p_3} \cdot \overrightarrow {N_1} &= \begin{bmatrix}6-4\\6-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}2\\-3\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = -16 + 24 = 8 \\
\overrightarrow {w_1 p_4} \cdot \overrightarrow {N_1} &= \begin{bmatrix}3-4\\3-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}-1\\-6\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = 8 + 48 = 56 \\
\overrightarrow {w_1 p_5} \cdot \overrightarrow {N_1} &= \begin{bmatrix}6-4\\0-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = \begin{bmatrix}2\\-9\end{bmatrix} \cdot \begin{bmatrix}-8\\-8\end{bmatrix} = -16 + 72 = 56
\end{align}
$$
$$
\begin{align}
\overrightarrow {w_2 p_1} \cdot \overrightarrow {N_2} &= \begin{bmatrix}0-12\\0-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-12\\-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + (-8) = -8 \\
\overrightarrow {w_2 p_2} \cdot \overrightarrow {N_2} &= \begin{bmatrix}0-12\\6-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-12\\5\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + 40 = 40 \\
\overrightarrow {w_2 p_3} \cdot \overrightarrow {N_2} &= \begin{bmatrix}6-12\\6-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-6\\5\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + 40 = 40 \\
\overrightarrow {w_2 p_4} \cdot \overrightarrow {N_2} &= \begin{bmatrix}3-12\\3-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-9\\2\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + 16 = 16 \\
\overrightarrow {w_2 p_5} \cdot \overrightarrow {N_2} &= \begin{bmatrix}6-12\\0-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = \begin{bmatrix}-6\\-1\end{bmatrix} \cdot \begin{bmatrix}0\\8\end{bmatrix} = 0 + (-8) = -8
\end{align}
$$
$$
\begin{align}
\overrightarrow {w_3 p_1} \cdot \overrightarrow {N_3} &= \begin{bmatrix}0-4\\0-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}-4\\-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = -32 + 0 = -32 \\
\overrightarrow {w_3 p_2} \cdot \overrightarrow {N_3} &= \begin{bmatrix}0-4\\6-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}-4\\5\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = -32 + 0 = -32 \\
\overrightarrow {w_3 p_3} \cdot \overrightarrow {N_3} &= \begin{bmatrix}6-4\\6-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}2\\5\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = 16 + 0 = 16 \\
\overrightarrow {w_3 p_4} \cdot \overrightarrow {N_3} &= \begin{bmatrix}3-4\\3-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}-1\\2\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = -8 + 0 = -8 \\
\overrightarrow {w_3 p_5} \cdot \overrightarrow {N_3} &= \begin{bmatrix}6-4\\0-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = \begin{bmatrix}2\\-1\end{bmatrix} \cdot \begin{bmatrix}8\\0\end{bmatrix} = 16 + 0 = 16 \\
\end{align}
$$
$$
\begin{array} {|r|r|}\hline
Edge & p_1 & p_2 & p_3 & p_4 & p_5 \\ \hline
\overrightarrow {E_1} & in & in & in & in & in \\ \hline
\overrightarrow {E_2} & out & in & in & in & out \\ \hline
\overrightarrow {E_3} & out & out & in & out & in \\ \hline \end{array}
$$
Now we create the intersection table by choosing the edge of a polygon with at least 2 in's for each of their starting and ending points. Intersection occurs whenever the starting point and ending point have different status. See below for the table
$$
\begin{array} {|r|r|}\hline
Edge Poly & Status & Edge Window & Intersection \\ \hline
\overrightarrow {p_2 p_3} & out \ in & \overrightarrow {E_3} \ or \ \overrightarrow {w_3 w_1} & i_1(..., ...) \\ \hline
\overrightarrow {p_3 p_4} & in \ out & \overrightarrow {E_3} \ or \ \overrightarrow {w_3 w_1} & i_2(..., ...) \\ \hline
\overrightarrow {p_4 p_5} & out \ in & \overrightarrow {E_3} \ or \ \overrightarrow {w_3 w_1} & i_3(..., ...) \\ \hline
\overrightarrow {p_4 p_5} & in \ out & \overrightarrow {E_2} \ or \ \overrightarrow {w_2 w_3} & i_4(..., ...) \\ \hline \end{array}
$$
From the table above we can also tell the sequence of polygon including the intersections and window clipping including the intersections.
$$
\begin{array} a
Polygon: \ p_1 \rightarrow p_2 \rightarrow i_1 \rightarrow p_3 \rightarrow i_2 \rightarrow p_4 \rightarrow i_3 \rightarrow i_4 \rightarrow p_5 \rightarrow p_1 \\
Window: \ w_1 \rightarrow w_2 \rightarrow i_4 \rightarrow w_3 \rightarrow i_3 \rightarrow i_2 \rightarrow i_1 \rightarrow w_1
\end{array}
$$
From the pattern we also can see that because of the clockwise direction for each shape (polygon and window clipping) the sequence for intersection for each shape is reversed. Now for finding the intersection of each we'll do some calculation
$$
t_1 = \frac {\overrightarrow {p_2 w_3} \cdot \overrightarrow {N_3}}{\overrightarrow {p_2 p_3} \cdot \overrightarrow {N_3}} = \frac {\begin{bmatrix} 4-0\\1-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}{\begin{bmatrix} 6-0\\6-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} = \frac {\begin{bmatrix} 4\\-5 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}{\begin{bmatrix} 6\\0 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} = \frac {32+0}{48+0}= \frac {2}{3}
$$
We know that \(p_2\)(0, 6) and \(p_3\)(6, 6)
$$
\begin{align}
Ox &= p_2 x + t_1 (p_3 x - p_2 x) \\
&= 0 + \frac {2}{3} (6-0) \\
&= \frac {2}{3}(6) \\
Ox &= 4
\end{align}
$$
$$
\begin{align}
Oy &= p_2 y + t_1 (p_3 y - p_2 y) \\
&= 6 + \frac {2}{3} (6-6) \\
&= 6 + \frac {2}{3}(0) \\
Oy &= 6
\end{align}
$$
So we've got \( i_1 \)(4, 6). Next is \( i_2 \)
$$
t_2 = \frac {\overrightarrow {p_3 w_3} \cdot \overrightarrow {N_3}}{\overrightarrow {p_3 p_4} \cdot \overrightarrow {N_3}} = \frac {\begin{bmatrix} 4-6\\1-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}{\begin{bmatrix} 3-6\\3-6 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} = \frac {\begin{bmatrix} -2\\-5 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}{\begin{bmatrix} -3\\-3 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} = \frac {-16+0}{-24+0}= \frac {2}{3}
$$
We know that \(p_3\)(6, 6) and \(p_4\)(3, 3)
$$
\begin{align}
Ox &= p_3 x + t_2 (p_4 x - p_3 x) \\
&= 6 + \frac {2}{3} (3-6) \\
&= 6 + \frac {2}{3}(-3) \\
&= 6 + (-2) \\
Ox &= 4
\end{align}
$$
$$
\begin{align}
Oy &= p_3 y + t_2 (p_4 y - p_3 y) \\
&= 6 + \frac {2}{3} (3-6) \\
&= 6 + \frac {2}{3}(-3) \\
&= 6 + (-2) \\
Oy &= 4
\end{align}
$$
So we've got \( i_2 \)(4, 4). Next is \( i_3 \)
$$
t_3 = \frac {\overrightarrow {p_4 w_3} \cdot \overrightarrow {N_3}}{\overrightarrow {p_4 p_5} \cdot \overrightarrow {N_3}} = \frac {\begin{bmatrix} 4-3\\1-3 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}{\begin{bmatrix} 6-3\\0-3 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} = \frac {\begin{bmatrix} 1\\-2 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}}{\begin{bmatrix} 3\\-3 \end{bmatrix} \cdot \begin{bmatrix} 8\\0 \end{bmatrix}} = \frac {8+0}{24+0}= \frac {1}{3}
$$
We know that \(p_4\)(3, 3) and \(p_5\)(6, 0)
$$
\begin{align}
Ox &= p_4 x + t_3 (p_5 x - p_4 x) \\
&= 3 + \frac {1}{3} (6-3) \\
&= 3 + \frac {1}{3}(3) \\
&= 3 + 1 \\
Ox &= 4
\end{align}
$$
$$
\begin{align}
Oy &= p_4 y + t_3 (p_5 y - p_4 y) \\
&= 3 + \frac {1}{3} (0-3) \\
&= 3 + \frac {1}{3}(-3) \\
&= 3 + (-1) \\
Oy &= 2
\end{align}
$$
So we've got \( i_3 \)(4, 2). Next is \( i_4 \)
$$
t_4 = \frac {\overrightarrow {p_4 w_2} \cdot \overrightarrow {N_2}}{\overrightarrow {p_4 p_5} \cdot \overrightarrow {N_2}} = \frac {\begin{bmatrix} 12-3\\1-3 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}}{\begin{bmatrix} 6-3\\0-3 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}} = \frac {\begin{bmatrix} 9\\-2 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}}{\begin{bmatrix} 3\\-3 \end{bmatrix} \cdot \begin{bmatrix} 0\\8 \end{bmatrix}} = \frac {0+(-16)}{0+(-24)}= \frac {2}{3}
$$
We know that \(p_4\)(3, 3) and \(p_5\)(6, 0)
$$
\begin{align}
Ox &= p_4 x + t_4 (p_5 x - p_4 x) \\
&= 3 + \frac {2}{3} (6-3) \\
&= 3 + \frac {2}{3}(3) \\
&= 3 + 2 \\
Ox &= 5
\end{align}
$$
$$
\begin{align}
Oy &= p_4 y + t_4 (p_5 y - p_4 y) \\
&= 3 + \frac {2}{3} (0-3) \\
&= 3 + \frac {2}{3}(-3) \\
&= 3 + (-2) \\
Oy &= 1
\end{align}
$$
So we've got \(i_4\)(5, 1). Now let's see what we've got so far, \(i_1\)(4, 6), \(i_2\)(4, 4), \(i_3\)(4, 2), and \(i_4\)(5, 1). Let's put them into this table
$$
\begin{array} {|r|r|}\hline
Edge Poly & Status & Edge Window & Intersection \\ \hline
\overrightarrow {p_2 p_3} & out \ in & \overrightarrow {E_3} \ or \ \overrightarrow {w_3 w_1} & i_1(4, 6) \\ \hline
\overrightarrow {p_3 p_4} & in \ out & \overrightarrow {E_3} \ or \ \overrightarrow {w_3 w_1} & i_2(4, 4) \\ \hline
\overrightarrow {p_4 p_5} & out \ in & \overrightarrow {E_3} \ or \ \overrightarrow {w_3 w_1} & i_3(4, 2) \\ \hline
\overrightarrow {p_4 p_5} & in \ out & \overrightarrow {E_2} \ or \ \overrightarrow {w_2 w_3} & i_4(5, 1) \\ \hline \end{array}
$$
The last step would be to determine the final polygon, we can do that by drawing the graph of Circular List of Polygon (CLP) and Circular List of Window (CLW) based on the sequence we've found earlier, refer to the graph below:
$$
\begin{array} a
Polygon: \ p_1 \rightarrow p_2 \rightarrow i_1 \rightarrow p_3 \rightarrow i_2 \rightarrow p_4 \rightarrow i_3 \rightarrow i_4 \rightarrow p_5 \rightarrow p_1 \\
Window: \ w_1 \rightarrow w_2 \rightarrow i_4 \rightarrow w_3 \rightarrow i_3 \rightarrow i_2 \rightarrow i_1 \rightarrow w_1
\end{array}
$$
From the sequence above we turn it into a graph just like below, and we can determine whether an intersection is entering or leaving from the last table.
Final graph |
- Start at entering \(i\) (double circle)
- Traverse on CLP line until encounter leaving \(i\), and change to CLW line (3)
- Traverse on CLW line until encounter entering \(i\), and change to CLP line (2)
- Repeat until encounter starting \(i\) (1)
From the graph and rules above, we can conclude the output polygons as:
- \(i_1 (4, 6) \rightarrow p_3 (6, 6) \rightarrow i_2 (4, 4) \Rightarrow i_1 (4, 6) \)
- \( i_3 (4, 2) \rightarrow i_4 (5, 1) \Rightarrow w_3 (4, 1) \Rightarrow i_3 (4, 2) \)
Robin hood in real life
ReplyDeletebro thank u banyak sekali
ReplyDelete