{"id":133,"date":"2018-07-20T09:47:42","date_gmt":"2018-07-20T09:47:42","guid":{"rendered":"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=133"},"modified":"2018-12-26T12:32:04","modified_gmt":"2018-12-26T12:32:04","slug":"2d-viewing","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/chapter\/2d-viewing\/","title":{"rendered":"2D Viewing"},"content":{"raw":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/2fAmTFv4ZI0\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>Objectives:<\/strong>\r\n<ul>\r\n \t<li>Understand 2D viewing pipeline<\/li>\r\n \t<li>Learn how to perform, window-viewport transformations<\/li>\r\n \t<li>Understand the theory behind clipping in 2D with focus on Point Clipping.<\/li>\r\n<\/ul>\r\n&nbsp;\r\n\r\n<strong>Discussion:<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>2D Viewing Pipeline:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Let\u2019s start our discussion with 2D viewing pipeline. This involves a series of transformations performed, right from creation, till the object is finally seen or displayed at a position or a viewing region on a display device like monitor. Each transformation step performed converts data from one coordinate system to the other. From the figure below (Recollect discussion from the first module),<\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-136 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-84.png\" alt=\"\" width=\"483\" height=\"224\" \/>\r\n\r\n&nbsp;\r\n\r\nThe sequence of steps in the 2D viewing Pipeline are\r\n\r\n&nbsp;\r\n\r\n<strong>MC <\/strong><strong>-&gt;<\/strong><strong> WC-&gt;<\/strong><strong>VC-&gt;<\/strong><strong>\u00a0CC-&gt;<\/strong><strong>NVC-&gt;<\/strong><strong>\u00a0DC<\/strong>\r\n\r\nwhere\r\n\r\nMC \u2013 Modeling Coordinates (Modeling or Local Coordinate system)\r\n\r\nWC \u2013 World coordinates (World Coordinate system)\r\n\r\nVC \u2013 viewing coordinates (Viewing coordinate system)\r\n\r\nCC \u2013 Clipping coordinates (Viewing coordinate system)\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">NVC \u2013 Normalized viewing or device independent coordinates (Viewing coordinate system, but normalized)<\/span>\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">DC \u2013 Device coordinates (Device coordinate system specific to every device)<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">For conversion from MC to WC we perform a transformation called <em>Modeling<\/em> Transformation (MT), from WC to VC we perform <em>Viewing<\/em> Transformation (VT), From VC to NVC we perform <em>window-viewport<\/em> transformation (WV), From NVC to DC we perform <em>Device<\/em> <em>coordinate system <\/em>transformation (DT). When the object is first created it assumes MC and a Modeling Transformation is applied to convert to WC, which is in the world coordinate system. Then a viewing coordinate system is set up and data is now converted from WC to VC (recall discussion from the previous module on transformation between coordinate systems). Later VC are sent for clipping, depending on the window or region of interest, to get CC. In many graphics packages, Viewing and Clipping steps are combined to get clipped coordinates straight from world coordinates. Next the CC are converted to NVC, where we simply normalize data in a step called window-Viewport transformation. This step is performed to ensure that the data should be independent of the end display device so that the data can be conveniently mapped to any display device of choice. If this is not done we need to perform a separate transformation for each display device, which is a cumbersome task. Each kind of coordinates belong to a specific coordinate system or reference frame.<\/p>\r\n&nbsp;\r\n\r\n<strong>Window-Viewport Transformation:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In Computer Graphics terminology, a <em>window<\/em> is a rectangular region of interest, and a <em>viewport<\/em> is a display area chosen on the monitor screen for viewing the contents of the window. In short, <em>window<\/em> is \u2018what we want to see\u2019 and <em>viewport<\/em> is \u2018where we want to see\u2019. As shown in the figure below, we can define a rectangular region in the world coordinate system, and call that as <em>window<\/em>. The contents of the <em>window<\/em> are to be mapped to a region or a display area chosen as <em>viewport<\/em>. In a way this is, mapping contents between two rectangular regions of different dimensions. <em>Window<\/em> is generally defined in the world coordinate system, while <em>viewport<\/em> is defined in the end device coordinate system. Since we wish to convert data to <em>device independent<\/em> or <em>normalized<\/em> coordinates, we perform <em>window-viewport <\/em>transformation. So in<em> window-viewport <\/em>transformation contents of the window are mapped to normalized coordinates (coordinates between 0 and 1).<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-137 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-85.png\" alt=\"\" width=\"489\" height=\"217\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">For simplicity, both window and viewport are chosen to be rectangular in shape whose boundaries are aligned with the coordinate axes. Because the dimensions of window and viewport are different, we will be performing a scaling like operation. If the window is bigger in size than the viewport, we perform a scale down operation and vice-versa. As you can notice from the figure above, the boundaries of the window and viewport are defined by four infinitely extending lines parallel to the coordinate axes. The window boundaries are defined by the four lines, xwmin, xwmax, ywmin, yWmax. Where xwmin, xwmax define the two\u00a0<span style=\"font-size: 1em;text-align: initial\">vertical boundaries, while, ywmin and ywmax define the two horizontal boundaries of the window. Similarly the viewport boundaries are defined by four infinitely extending lines, xvmin,\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">xvmax, yvmin, yvmax.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now for a point (xw,yw) in the window, we have to identify an equivalent point in the viewport, say (xv,yv). i.e., for every point in the window, there is an equivalent point in the viewport. The four corner vertices of the window have got their equivalent vertex points in the viewport, which are nothing but the four corner points of the viewport. For the point (xwmin, ywmin) in the window, the equivalent point in the viewport is (xvmin, yvmin) and so on.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-138 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-86.png\" alt=\"\" width=\"474\" height=\"191\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">For any general point in the window, how do we find an equivalent point in the viewport? As we can see, from the figures above, the percentage horizontal distance of the point in the window from its left boundary, should be exactly equal to the percentage horizontal distance of the equivalent point in the viewport from its left boundary. We can apply the same analogy to the vertical distance of the point from its bottom boundary.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-139 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-87.png\" alt=\"\" width=\"639\" height=\"484\" \/>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"size-full wp-image-140 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-88.png\" alt=\"\" width=\"614\" height=\"366\" \/>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\"><span style=\"text-align: justify;font-size: 1em\">Here sy is a ratio and is also the scaling factor along y-direction. If the vertical boundary of the window is larger than that of the viewport then sy &lt;1 (down scaling), otherwise sy &gt;1 (up scaling). If both the boundaries are of same lengths then sy=1 (no scaling).<\/span><\/p>\r\n\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is important to note that the transformation, converts real coordinates to normalized coordinates, which are device independent. Later the device independent coordinates are converted to appropriate screen coordinates as shown in the figure below.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-141 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-89.png\" alt=\"\" width=\"579\" height=\"177\" \/>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>Example:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong>Problem: <\/strong>For a point (1, 2) in the window, find the equivalent point in the viewport. Assume window at [(1,1) and (4,4)] and viewport at [(-1, -1) and (1,1)].<\/p>\r\n&nbsp;\r\n\r\n<strong>Sol:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The point (1, 2) is identified as (<em>xw<\/em>, <em>yw<\/em>) respectively. The aim is to compute the equivalent point (<em>xv<\/em>,<em>yv<\/em>).<\/p>\r\n&nbsp;\r\n\r\n<em>xw<\/em><em>min<\/em>=1,<em> xw<\/em><em>max<\/em>=5,<em> yw<\/em><em>min<\/em>=1,<em> yw<\/em><em>max<\/em>=5,\r\n\r\n<em>xv<\/em><em>min<\/em>=-1,<em> xv<\/em><em>max<\/em>=1,<em> yv<\/em><em>min<\/em>=-1,<em> yv<\/em><em>max<\/em>=1,\r\n\r\nNow compute\u00a0 s<sub>x\u00a0<\/sub> \u00a0 using the relation derived above\r\n\r\n&nbsp;\r\n\r\n<\/div>\r\n<img class=\"size-full wp-image-142 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-90.png\" alt=\"\" width=\"161\" height=\"58\" \/>\r\n\r\n<img class=\"size-full wp-image-143 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-91.png\" alt=\"\" width=\"631\" height=\"275\" \/>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>2D Clipping Algorithm:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In 2D clipping, we choose a rectangular region of interest in the world coordinate system and call that as window or clip window or clip rectangle. The contents inside the window are of interest to us and so to be clipped. So here clipping means select the contents that are inside the clip window region. It is cumbersome and less efficient to consider performing transformations on the regions that are not of interest to us, instead we can consider the inside of the clip window and perform any transformations on that. Thus clipping is \u2018selecting what is of interest to us\u2019 and <strong>not<\/strong> <strong>\u2018<\/strong>discarding what is not of interest to us\u2019.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">For better understanding and simplicity we choose the clip rectangle to be aligned such that its sides are parallel to the coordinate axes. In the most general case we can choose the clip rectangle to be oriented in any direction in 2D space. In the extreme case, the shape of the clip window region need not be rectangular, instead, it can be of any shape of choice.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The region against which the contents are clipped is called \u2018clip window\u2019. Any procedure that identifies those portions of a picture that are either inside or outside of a specified region of space is considered as the \u2018clipping algorithm\u2019. Usually a clipping region is a rectangle in <em>standard position<\/em>. These boundary edges typically correspond to a normalized square in which the x and y values range either from 0 to 1 or from -1 to 1.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-144 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-92.png\" alt=\"\" width=\"209\" height=\"143\" \/>\r\n<p style=\"text-align: justify\">Clipping transformation can be performed either in the world coordinate system or in the viewport coordinate system. Clipping in the World coordinate system involves selecting the contents inside the clip window region and apply transformations only on them. In viewport clipping, the whole of the contents from the world are brought to the viewport and then clipping against the viewport. It is thus more convenient to perform clipping in the world coordinate system.<\/p>\r\n&nbsp;\r\n\r\nThe types of clipping that we are going to learn are\r\n<ul>\r\n \t<li>Point clipping<\/li>\r\n \t<li>Line clipping<\/li>\r\n \t<li>Polygon Clipping<\/li>\r\n \t<li>Text Clipping<\/li>\r\n<\/ul>\r\n<\/div>\r\n&nbsp;\r\n\r\n<strong>Point Clipping:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In point clipping, points that are inside the rectangular region are selected for display and points that are outside the region are discarded. Now the question is, how do we know whether a point is inside or outside a given rectangular region? For this we should perform a test as shown.<\/p>\r\n<img class=\"size-full wp-image-145 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-93.png\" alt=\"\" width=\"227\" height=\"167\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">From the above two equations we can infer that if x and y satisfy the above equations, the point is an inside point, so can be selected for display, otherwise it is an outside point so can be discarded. In the above two equations, there are 4 inequalities,<\/p>\r\n<img class=\"size-full wp-image-146 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-94.png\" alt=\"\" width=\"162\" height=\"95\" \/>\r\n\r\n&nbsp;\r\n\r\n<img class=\"size-full wp-image-147 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-95.png\" alt=\"\" width=\"630\" height=\"350\" \/>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>Summary:<\/strong>\r\n<ul>\r\n \t<li>Understood the steps in 2D viewing pipeline<\/li>\r\n \t<li>Learnt about window-viewport transformation<\/li>\r\n \t<li style=\"text-align: justify\">Also learnt the idea behind clipping, and in particular point clipping<\/li>\r\n<\/ul>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on 2D Viewing<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/2fAmTFv4ZI0\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<img class=\"size-full wp-image-148 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-96.png\" alt=\"\" width=\"638\" height=\"263\" \/>","rendered":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/2fAmTFv4ZI0\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Objectives:<\/strong><\/p>\n<ul>\n<li>Understand 2D viewing pipeline<\/li>\n<li>Learn how to perform, window-viewport transformations<\/li>\n<li>Understand the theory behind clipping in 2D with focus on Point Clipping.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Discussion:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>2D Viewing Pipeline:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Let\u2019s start our discussion with 2D viewing pipeline. This involves a series of transformations performed, right from creation, till the object is finally seen or displayed at a position or a viewing region on a display device like monitor. Each transformation step performed converts data from one coordinate system to the other. From the figure below (Recollect discussion from the first module),<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-136 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-84.png\" alt=\"\" width=\"483\" height=\"224\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-84.png 483w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-84-300x139.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-84-65x30.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-84-225x104.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-84-350x162.png 350w\" sizes=\"auto, (max-width: 483px) 100vw, 483px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The sequence of steps in the 2D viewing Pipeline are<\/p>\n<p>&nbsp;<\/p>\n<p><strong>MC <\/strong><strong>-&gt;<\/strong><strong> WC-&gt;<\/strong><strong>VC-&gt;<\/strong><strong>\u00a0CC-&gt;<\/strong><strong>NVC-&gt;<\/strong><strong>\u00a0DC<\/strong><\/p>\n<p>where<\/p>\n<p>MC \u2013 Modeling Coordinates (Modeling or Local Coordinate system)<\/p>\n<p>WC \u2013 World coordinates (World Coordinate system)<\/p>\n<p>VC \u2013 viewing coordinates (Viewing coordinate system)<\/p>\n<p>CC \u2013 Clipping coordinates (Viewing coordinate system)<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">NVC \u2013 Normalized viewing or device independent coordinates (Viewing coordinate system, but normalized)<\/span><\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">DC \u2013 Device coordinates (Device coordinate system specific to every device)<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">For conversion from MC to WC we perform a transformation called <em>Modeling<\/em> Transformation (MT), from WC to VC we perform <em>Viewing<\/em> Transformation (VT), From VC to NVC we perform <em>window-viewport<\/em> transformation (WV), From NVC to DC we perform <em>Device<\/em> <em>coordinate system <\/em>transformation (DT). When the object is first created it assumes MC and a Modeling Transformation is applied to convert to WC, which is in the world coordinate system. Then a viewing coordinate system is set up and data is now converted from WC to VC (recall discussion from the previous module on transformation between coordinate systems). Later VC are sent for clipping, depending on the window or region of interest, to get CC. In many graphics packages, Viewing and Clipping steps are combined to get clipped coordinates straight from world coordinates. Next the CC are converted to NVC, where we simply normalize data in a step called window-Viewport transformation. This step is performed to ensure that the data should be independent of the end display device so that the data can be conveniently mapped to any display device of choice. If this is not done we need to perform a separate transformation for each display device, which is a cumbersome task. Each kind of coordinates belong to a specific coordinate system or reference frame.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Window-Viewport Transformation:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In Computer Graphics terminology, a <em>window<\/em> is a rectangular region of interest, and a <em>viewport<\/em> is a display area chosen on the monitor screen for viewing the contents of the window. In short, <em>window<\/em> is \u2018what we want to see\u2019 and <em>viewport<\/em> is \u2018where we want to see\u2019. As shown in the figure below, we can define a rectangular region in the world coordinate system, and call that as <em>window<\/em>. The contents of the <em>window<\/em> are to be mapped to a region or a display area chosen as <em>viewport<\/em>. In a way this is, mapping contents between two rectangular regions of different dimensions. <em>Window<\/em> is generally defined in the world coordinate system, while <em>viewport<\/em> is defined in the end device coordinate system. Since we wish to convert data to <em>device independent<\/em> or <em>normalized<\/em> coordinates, we perform <em>window-viewport <\/em>transformation. So in<em> window-viewport <\/em>transformation contents of the window are mapped to normalized coordinates (coordinates between 0 and 1).<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-137 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-85.png\" alt=\"\" width=\"489\" height=\"217\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-85.png 489w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-85-300x133.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-85-65x29.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-85-225x100.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-85-350x155.png 350w\" sizes=\"auto, (max-width: 489px) 100vw, 489px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">For simplicity, both window and viewport are chosen to be rectangular in shape whose boundaries are aligned with the coordinate axes. Because the dimensions of window and viewport are different, we will be performing a scaling like operation. If the window is bigger in size than the viewport, we perform a scale down operation and vice-versa. As you can notice from the figure above, the boundaries of the window and viewport are defined by four infinitely extending lines parallel to the coordinate axes. The window boundaries are defined by the four lines, xwmin, xwmax, ywmin, yWmax. Where xwmin, xwmax define the two\u00a0<span style=\"font-size: 1em;text-align: initial\">vertical boundaries, while, ywmin and ywmax define the two horizontal boundaries of the window. Similarly the viewport boundaries are defined by four infinitely extending lines, xvmin,\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">xvmax, yvmin, yvmax.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now for a point (xw,yw) in the window, we have to identify an equivalent point in the viewport, say (xv,yv). i.e., for every point in the window, there is an equivalent point in the viewport. The four corner vertices of the window have got their equivalent vertex points in the viewport, which are nothing but the four corner points of the viewport. For the point (xwmin, ywmin) in the window, the equivalent point in the viewport is (xvmin, yvmin) and so on.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-138 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-86.png\" alt=\"\" width=\"474\" height=\"191\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-86.png 474w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-86-300x121.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-86-65x26.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-86-225x91.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-86-350x141.png 350w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">For any general point in the window, how do we find an equivalent point in the viewport? As we can see, from the figures above, the percentage horizontal distance of the point in the window from its left boundary, should be exactly equal to the percentage horizontal distance of the equivalent point in the viewport from its left boundary. We can apply the same analogy to the vertical distance of the point from its bottom boundary.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-139 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-87.png\" alt=\"\" width=\"639\" height=\"484\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-87.png 639w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-87-300x227.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-87-65x49.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-87-225x170.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-87-350x265.png 350w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-140 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-88.png\" alt=\"\" width=\"614\" height=\"366\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-88.png 614w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-88-300x179.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-88-65x39.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-88-225x134.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-88-350x209.png 350w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/p>\n<\/div>\n<p style=\"text-align: justify\"><span style=\"text-align: justify;font-size: 1em\">Here sy is a ratio and is also the scaling factor along y-direction. If the vertical boundary of the window is larger than that of the viewport then sy &lt;1 (down scaling), otherwise sy &gt;1 (up scaling). If both the boundaries are of same lengths then sy=1 (no scaling).<\/span><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is important to note that the transformation, converts real coordinates to normalized coordinates, which are device independent. Later the device independent coordinates are converted to appropriate screen coordinates as shown in the figure below.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-141 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-89.png\" alt=\"\" width=\"579\" height=\"177\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-89.png 579w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-89-300x92.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-89-65x20.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-89-225x69.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-89-350x107.png 350w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong>Problem: <\/strong>For a point (1, 2) in the window, find the equivalent point in the viewport. Assume window at [(1,1) and (4,4)] and viewport at [(-1, -1) and (1,1)].<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Sol:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The point (1, 2) is identified as (<em>xw<\/em>, <em>yw<\/em>) respectively. The aim is to compute the equivalent point (<em>xv<\/em>,<em>yv<\/em>).<\/p>\n<p>&nbsp;<\/p>\n<p><em>xw<\/em><em>min<\/em>=1,<em> xw<\/em><em>max<\/em>=5,<em> yw<\/em><em>min<\/em>=1,<em> yw<\/em><em>max<\/em>=5,<\/p>\n<p><em>xv<\/em><em>min<\/em>=-1,<em> xv<\/em><em>max<\/em>=1,<em> yv<\/em><em>min<\/em>=-1,<em> yv<\/em><em>max<\/em>=1,<\/p>\n<p>Now compute\u00a0 s<sub>x\u00a0<\/sub> \u00a0 using the relation derived above<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-142 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-90.png\" alt=\"\" width=\"161\" height=\"58\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-90.png 161w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-90-65x23.png 65w\" sizes=\"auto, (max-width: 161px) 100vw, 161px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-143 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-91.png\" alt=\"\" width=\"631\" height=\"275\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-91.png 631w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-91-300x131.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-91-65x28.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-91-225x98.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-91-350x153.png 350w\" sizes=\"auto, (max-width: 631px) 100vw, 631px\" \/><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>2D Clipping Algorithm:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In 2D clipping, we choose a rectangular region of interest in the world coordinate system and call that as window or clip window or clip rectangle. The contents inside the window are of interest to us and so to be clipped. So here clipping means select the contents that are inside the clip window region. It is cumbersome and less efficient to consider performing transformations on the regions that are not of interest to us, instead we can consider the inside of the clip window and perform any transformations on that. Thus clipping is \u2018selecting what is of interest to us\u2019 and <strong>not<\/strong> <strong>\u2018<\/strong>discarding what is not of interest to us\u2019.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">For better understanding and simplicity we choose the clip rectangle to be aligned such that its sides are parallel to the coordinate axes. In the most general case we can choose the clip rectangle to be oriented in any direction in 2D space. In the extreme case, the shape of the clip window region need not be rectangular, instead, it can be of any shape of choice.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The region against which the contents are clipped is called \u2018clip window\u2019. Any procedure that identifies those portions of a picture that are either inside or outside of a specified region of space is considered as the \u2018clipping algorithm\u2019. Usually a clipping region is a rectangle in <em>standard position<\/em>. These boundary edges typically correspond to a normalized square in which the x and y values range either from 0 to 1 or from -1 to 1.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-144 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-92.png\" alt=\"\" width=\"209\" height=\"143\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-92.png 209w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-92-65x44.png 65w\" sizes=\"auto, (max-width: 209px) 100vw, 209px\" \/><\/p>\n<p style=\"text-align: justify\">Clipping transformation can be performed either in the world coordinate system or in the viewport coordinate system. Clipping in the World coordinate system involves selecting the contents inside the clip window region and apply transformations only on them. In viewport clipping, the whole of the contents from the world are brought to the viewport and then clipping against the viewport. It is thus more convenient to perform clipping in the world coordinate system.<\/p>\n<p>&nbsp;<\/p>\n<p>The types of clipping that we are going to learn are<\/p>\n<ul>\n<li>Point clipping<\/li>\n<li>Line clipping<\/li>\n<li>Polygon Clipping<\/li>\n<li>Text Clipping<\/li>\n<\/ul>\n<\/div>\n<p>&nbsp;<\/p>\n<p><strong>Point Clipping:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In point clipping, points that are inside the rectangular region are selected for display and points that are outside the region are discarded. Now the question is, how do we know whether a point is inside or outside a given rectangular region? For this we should perform a test as shown.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-145 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-93.png\" alt=\"\" width=\"227\" height=\"167\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-93.png 227w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-93-65x48.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-93-225x166.png 225w\" sizes=\"auto, (max-width: 227px) 100vw, 227px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">From the above two equations we can infer that if x and y satisfy the above equations, the point is an inside point, so can be selected for display, otherwise it is an outside point so can be discarded. In the above two equations, there are 4 inequalities,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-146 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-94.png\" alt=\"\" width=\"162\" height=\"95\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-94.png 162w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-94-65x38.png 65w\" sizes=\"auto, (max-width: 162px) 100vw, 162px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-147 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-95.png\" alt=\"\" width=\"630\" height=\"350\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-95.png 630w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-95-300x167.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-95-65x36.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-95-225x125.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-95-350x194.png 350w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li>Understood the steps in 2D viewing pipeline<\/li>\n<li>Learnt about window-viewport transformation<\/li>\n<li style=\"text-align: justify\">Also learnt the idea behind clipping, and in particular point clipping<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on 2D Viewing<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/2fAmTFv4ZI0\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-148 aligncenter\" src=\"http:\/\/csp06.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/52\/2018\/07\/1-96.png\" alt=\"\" width=\"638\" height=\"263\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-96.png 638w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-96-300x124.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-96-65x27.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-96-225x93.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-content\/uploads\/sites\/52\/2018\/07\/1-96-350x144.png 350w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/p>\n","protected":false},"author":3,"menu_order":8,"template":"","meta":{"_acf_changed":false,"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-t-raghuveera"],"pb_section_license":""},"chapter-type":[],"contributor":[59],"license":[],"class_list":["post-133","chapter","type-chapter","status-publish","hentry","contributor-dr-t-raghuveera"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/pressbooks\/v2\/chapters\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/wp\/v2\/users\/3"}],"version-history":[{"count":9,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/pressbooks\/v2\/chapters\/133\/revisions"}],"predecessor-version":[{"id":615,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/pressbooks\/v2\/chapters\/133\/revisions\/615"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/pressbooks\/v2\/chapters\/133\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/pressbooks\/v2\/chapter-type?post=133"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/wp\/v2\/contributor?post=133"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp06\/wp-json\/wp\/v2\/license?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}