Next Article in Journal
Deep Learning Stranded Neural Network Model for the Detection of Sensory Triggered Events
Next Article in Special Issue
Folding Every Point on a Polygon Boundary to a Point
Previous Article in Journal
On Modeling Antennas Using MoM-Based Algorithms: Wire-Grid versus Surface Triangulation
Previous Article in Special Issue
Higher-Order Curvatures of Plane and Space Parametrized Curves
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Line Clipping in 3D: Overview, Techniques and Algorithms

by
Dimitrios Matthes
and
Vasileios Drakopoulos
*
Department of Computer Science and Biomedical Informatics, University of Thessaly, 35131 Lamia, Greece
*
Author to whom correspondence should be addressed.
Algorithms 2023, 16(4), 201; https://doi.org/10.3390/a16040201
Submission received: 24 December 2022 / Revised: 16 March 2023 / Accepted: 27 March 2023 / Published: 9 April 2023
(This article belongs to the Special Issue Machine Learning in Computational Geometry)

Abstract

:
Clipping algorithms essentially compute the intersection of the clipping object and the subject, so to go from two to three dimensions we replace the two-dimensional clipping object by the three-dimensional one (the view frustum). In three-dimensional graphics, the terminology of clipping can be used to describe many related features. Typically, “clipping” refers to operations in the plane that work with rectangular shapes, and “culling” refers to more general methods to selectively process scene model elements. The aim of this article is to survey important techniques and algorithms for line clipping in 3D, but it also includes some of the latest research performed by the authors.

1. Introduction

In two dimensions, a section of a scene that is selected for display is called a clipping window because all parts of the scene outside the selected section are “clipped” off. In general, a procedure that eliminates portions of an object that are either inside or outside a specified region is referred to as a clipping algorithm or, simply, clipping. The only part of the scene that shows up on the screen is what is inside the clipping window [1]. Usually a clipping region is a rectangle in a standard position, although we could use any shape. In three dimensions, the viewing process is more complicated than its two-dimensional analogue because of the added dimension and, moreover, the fact that display devices are mostly two-dimensional [2]. A two-dimensional clipping window, corresponding to a selected camera lens, is defined on the projection plane, and a three-dimensional clipping region, called the view volume, is established. Depending on the type of projection used, the view volume takes the form of a truncated pyramid or a rectangular parallelepiped and is also known as the (view) frustum.
In the context of vector graphics, an image or an object is composed of straight line segments, and, thus, the type of clipping considered in this article is line clipping (Figure 1 and Figure 2). As large numbers of points or line segments must be clipped for a typical scene or picture, the efficiency of clipping algorithms is very significant. In many cases the large majority of points or line segments are either completely interior or completely exterior to the clipping window or volume. Therefore, it is important to be able to quickly accept or reject a line or a point [3]. This article proposes an algorithm for line clipping against a three-dimensional clipping region. The proposed algorithm is an extension of the algorithm described in [4] to the three-dimensional space.
The article has the following structure. Section 2 explains the concepts of three-dimensional viewing and clipping region; Section 3 presents the classical three-dimensional line-clipping algorithms; Section 4 introduces the fundamental mathematical concepts of the line in the three-dimensional space; Section 5 describes the proposed algorithm in detail; Section 5.4 explains the steps of the algorithm in brief as well as presents a C++-based pseudocode implementation; Section 6 evaluates the proposed algorithm and its experimental results after comparison with other clipping algorithms; and, finally, Section 7 has a brief summary of all the above.

2. Three-Dimensional View Volumes and Clipping Regions

For two-dimensional graphics, viewing operations convert positions in the world coordinate plane to pixels in a screen or any other output device. Using rectangular boundaries for the clipping window, a clipping process clips a two-dimensional scene and maps it to device coordinates. Three-dimensional viewing operations are more complicated because there is an extra dimension and involves some tasks that are not present in two-dimensional viewing. To create a display of a three-dimensional world coordinate scene, one must first set up a coordinate reference for the viewing parameters (also known as the camera). This coordinate reference defines the position and orientation for a view plane (or projection plane) that corresponds to a camera film plane [1] (see Figure 3). The vertices that make up the object are then converted to the viewing reference coordinates and projected onto the view plane.
Unlike a camera picture, there are different methods for projecting a scene onto the view plane. One method for getting the description of a solid object onto a view plane is to project points on the object’s surface along parallel lines. This technique, called parallel projection, is mostly used in engineering and architectural drawings to represent an object with a set of views that show accurate dimensions of the object. Another method for generating a view of a three-dimensional scene is to project points to the view plane along converging paths. This process, called perspective projection, causes objects farther from the viewing position to be displayed smaller than objects of the same size that are nearer to the viewing position. A scene that is generated using a perspective projection appears more realistic because this is the way that our eyes and a camera lens form images. Parallel lines along the viewing direction appear to converge to a distant point in the background, and objects in the background appear to be smaller than objects in the foreground (see Figure 4).
Most of the time, the view volume is either a rectangular parallelepiped, i.e., a box or a cuboid, or a frustum pyramid. Both of these shapes are six-sided with the following sides: left, right, top, bottom, near (hither), and far (yon); see Figure 5.
After the specification of the type of view volume, various strategies can be used to implement the viewing process depending on the view volume and the 3D scene. A conceptual model could be similar to the one in Figure 6: the view volume is used as a clipping region to discard the unnecessary out-of-boundaries components of the three-dimensional scene. The remaining components are then projected onto the projection plane. Finally, the projection plane is transformed into two-dimensional device coordinates.
Unfortunately, if the viewing is perspective and the volume is a frustum, it can be computationally expensive to check if objects exist inside the boundaries and perform clipping; see Figure 7.
In order to simplify and speed up the clipping process, an extra stage is added to the above model; see Figure 8. Before clipping and projection stages, the frustum is firstly transformed into a normalized canonical view volume. Clipping and hidden surface calculations are then applied (Figure 9).

3. Line-Clipping Algorithms in Three-Dimensions

There are many line-clipping algorithms in two-dimensions such as Cohen–Sutherland, Liang–Barsky [5], Cyrus–Beck [6], Nicholl–Lee–Nicholl [7], midpoint subdivision, Skala 2005 [8], S-Clip E2 [9], Kodituwakku–Wijeweere–Chamikara [10], and affine transormation clipping [11]. Unfortunately, only a few of them can clip lines in three-dimensional space. These algorithms include Cohen–Sutherland, Liang–Barsky, and Cyrus–Beck, which are considered as the classic ones for this purpose. Over the years, other algorithms for clipping a line in three-dimensional space have emerged such as simple and efficient 2D and 3D span clipping algorithms [12], Kodituwakku–Wijeweera–Chamikara 3D [13], and Kolingerova [14], but some of them do not perform clipping correctly (e.g., Kodituwakku–Wijeweera–Chamikara) while some others are hard to implement.

3.1. Three-Dimensional Cohen–Sutherland Line Clipping

The Cohen–Sutherland algorithm is considered a classic line-clipping algorithm in two dimensions. The three-dimensional analogue is very similar to its two-dimensional version but with a few modifications. For an orthogonal clipping region, the three-dimensional space is divided again into regions but this time a 6-bit region code, instead of a four-bit one, is used to classify the lines’ endpoints. These six bits are as in Figure 10.
The regions are related to the space that is in front of the near plane, the space between the near and the far plane, and the space behind the far plane; see Figure 11.
The testing strategy is virtually identical to the two-dimensional case. The bit codes can be set to true (1) or false (0), depending on the test for these equations as follows:
Bit 1: endpoint is in front of the view volume;
Bit 2: endpoint is behind the view volume;
Bit 3: endpoint is above the view volume;
Bit 4: endpoint is below the view volume;
Bit 5: endpoint is right of the view volume;
Bit 6: endpoint is left of the view volume.
To clip a line, the classification of its endpoints with the appropriate region codes is required. The line is as follows:
Visible:  if both endpoints are 000000;
Invisible:  if the bitwise logical AND is not 000000;
A clipping candidate:  if the bitwise logical AND is 000000.
All lines with both endpoints in the [000000] region are trivially accepted. All lines whose endpoints share a common bit in any position are trivially rejected. The clipped line is derived from the parametric equation of the line in three-dimensional space using homogeneous coordinates and by using boundary coordinates whenever it is necessary.

3.2. Three-Dimensional Liang–Barsky Line Clipping

The Liang–Barsky algorithm is a line-clipping algorithm and is considered more efficient than Cohen–Sutherland [5]. It is considered to be a fast parametric line-clipping algorithm and can be applied to two dimensions as well as to three dimensions. The following concepts are used when three-dimensional clipping is applied:
  • The parametric equation of the line.
  • The inequalities describing each side (boundaries) of the clipping region, which are used to determine the intersections between the line and each side.
The parametric equation of a line can be given by the following equations:
x = x 0 + ( x 1 x 0 ) · t
y = y 0 + ( y 1 y 0 ) · t
z = z 0 + ( z 1 z 0 ) · t
where t is between 0 and 1. The point-clipping conditions in the parametric form are then written as
x m i n x 0 + ( x 1 x 0 ) · t x m a x
y m i n y = y 0 + ( y 1 y 0 ) · t y m a x
z m i n z = z 0 + ( z 1 z 0 ) · t z m a x
and the above six inequalities can be expressed as
p k · t q k ,
where k = 1 , 2 , 3 , 4 , 5 , 6 correspond to the left ( x m i n ), right ( x m a x ), bottom ( y m i n ), top ( y m a x ), far ( z m i n ), and near ( z m a x ) boundaries, respectively. The p and q are defined as follows:
p 1 = ( x 1 x 0 ) , q 1 = ( x 0 x m i n ) ( left boundary ) ; p 2 = ( x 1 x 0 ) , q 2 = ( x m a x x 0 ) ( right boundary ) ; p 3 = ( y 1 y 0 ) , q 3 = ( y 0 y m i n ) ( bottom boundary ) ; p 4 = ( y 1 y 0 ) , q 4 = ( y m a x y 0 ) ( top boundary ) ; p 5 = ( z 1 z 0 ) , q 5 = ( z 0 z m i n ) ( far boundary ) ; p 6 = ( z 1 z 0 ) , q 6 = ( z m a x z 0 ) ( near boundary ) .
Using the following conditions, the position of the line can be determined as follows.
  • When the line is parallel to a clipping boundary, the p value for that boundary is zero.
  • When p k < 0 , as t increases the line goes from the outside to the inside (entering).
  • When p k > 0 , the line goes from the inside to the outside (exiting).
  • When p k = 0 and q k < 0 , the line is trivially invisible because it is outside the clipping region.
  • When p k = 0 and q k > 0 , the line is inside the corresponding clipping region.
Parameters t 1 and t 2 can be calculated to define the part of the line that lies within the clipping region. The following points hold:
  • When p k < 0 , m a x i m u m ( 0 , q k / p k ) is taken.
  • When p k > 0 , m i n i m u m ( 1 , q k / p k ) is taken.
If t 1 > t 2 , the line is completely outside the clipping region and it can be rejected. Otherwise, the endpoints of the clipped line are calculated from the two values of parameter t.

3.3. Three-Dimensional Cyrus–Beck Line Clipping

The Cyrus–Beck algorithm is another classic line-clipping algorithm in two-dimensional space. With simple modifications, it can also clip lines in three-dimensional space. According to the algorithm, a straight line, intersecting the interior of a convex set, can intersect the boundary of the set in, at most, two places. In the case where the convex set is closed and bounded, the straight line will intersect it in exactly two places [6].
Each side of the view volume is considered as a convex polygon in three-dimensional space and it is used as a clipping plane. This means that the algorithm examines all six planes of the view volume and performs clipping when necessary. For each clipping plane, the following steps are applied:
  • The inward normal of the plane (perpendicular vector to the plane) is calculated by using three out of the four known vertices that form the plane.
  • The vector of the clipping line is calculated.
  • The dot product between the difference of one vertex per edge and one selected end point of the clipping line and the normal is calculated (for all edges).
  • The dot product between the vector of the clipping line and the normal is calculated.
  • The former dot product is divided by the latter dot product and multiplied by 1 (this is t).
  • The values of t are classified as entering or exiting (from all edges) by observing their denominators (latter dot product).
  • One value of t is chosen from each group and it is put into the parametric form of a line to calculate the coordinates.
  • If the entering t value is greater than the exiting t value, then the clipping line is rejected.

3.4. Three-Dimensional Kolingerova Line Clipping

In 1994, Ivana Kolingerova presented a comparative study on 3D line-clipping algorithms. Based on the Cyrus–Beck algorithm, she proposed improvements for increasing its speed. Some of these improvements were related to the way that the algorithm calculated intersection points, e.g., by using orthogonal planes, since the new methods use the fact that each line can be described as the intersection of two planes. Furthermore, unlike Cyrus–Beck, she proposed ways to end the computation earlier when finding the two intersections of the line segment against the clipping volume.

4. Mathematical Background

We consider a line L that passes through two points P 0 ( x 0 , y 0 , z 0 ) and P 1 ( x 1 , y 1 , z 1 ) in three-dimensional space (see Figure 12).
For an arbitrary point P ( x , y , z ) on the line, the parametric equation of the line is
x = x 0 + ( x 1 x 0 ) · t
y = y 0 + ( y 1 y 0 ) · t
z = z 0 + ( z 1 z 0 ) · t .
The equation of the line may also be written symmetrically as
x x 0 x 1 x 0 = y y 0 y 1 y 0 = z z 0 z 1 z 0
and, if we assume that
a = x 1 x 0
b = y 1 y 0
c = z 1 z 0 ,
then the equation of the line can also be written as
x x 0 a = y y 0 b = z z 0 c .

5. The Proposed Method

5.1. Nomenclature

Suppose that we want to clip a line inside the rectangular parallelepiped volume in Figure 13. The dimensions of the volume range from xmin to xmax for the X axis (width), from ymin to ymax for the Y axis (height), and from zmin to zmax for the Z axis (depth). The line L that is going to be clipped has endpoints P0(x0, y0, z0) and P1(x1, y1, z1) (see Figure 14).

5.2. Description

The first step of the algorithm checks, if both of the endpoints are outside the clipping region and at the same time in the same region (left, right, bottom, top, near, far). If one of the following occurs, then the line is being rejected and the algorithm draws nothing; see examples of Figure 15:
x 0 < x m i n AND x 1 < x m i n   (the line is left of the clipping region);
x 0 > x m a x AND x 1 > x m a x   (the line is right of the clipping region);
y 0 < y m i n AND y 1 < y m i n   (the line is under the clipping region);
y 0 > y m a x AND y 1 > y m a x   (the line is above the clipping region);
z 0 < z m i n AND z 1 < z m i n   (the line is behind the clipping region);
z 0 > z m a x AND z 1 > z m a x   (the line is in front of the clipping region).
In the second step, the algorithm compares the coordinates of the two endpoints of the line along with the boundaries of the clipping region. It compares the x 0 and x 1 coordinates with the x m i n and x m a x boundaries, respectively, then it compares the y 0 and y 1 coordinates with the y m i n and y m a x boundaries and, finally, it compares the z 0 and z 1 coordinates with the z m i n and z m a x boundaries. If any of these coordinates are outside the clipping boundary, then the boundary cordinates are used instead for limiting the line inside the volume and achieving clipping (see Figure 16).
For each of the coordinates of the two endpoints, and according to Equations  (2)–(5), the comparisons and the new coordinates are as follows:
  • If x i < x m i n , then
    x m i n x 0 a = y y 0 b y = b a · ( x m i n x 0 ) + y 0 ;
    x m i n x 0 a = z z 0 c z = c a · ( x m i n x 0 ) + z 0 .
  • If x i > x m a x , then
    x m a x x 0 a = y y 0 b y = b a · ( x m a x x 0 ) + y 0 ;
    x m a x x 0 a = z z 0 c z = c a · ( x m a x x 0 ) + z 0 .
  • If y i < y m i n , then
    y m i n y 0 b = x x 0 a x = a b · ( y m i n y 0 ) + x 0 ;
    y m i n y 0 b = z z 0 c z = c b · ( y m i n y 0 ) + z 0 .
  • If y i > y m a x , then
    y m a x y 0 b = x x 0 a x = a b · ( y m a x y 0 ) + x 0 ;
    y m a x y 0 b = z z 0 c z = c b · ( y m a x y 0 ) + z 0 .
  • If z i < z m i n , then
    z m i n z 0 c = x x 0 a x = a c · ( z m i n z 0 ) + x 0 ;
    z m i n z 0 c = y y 0 b y = b c · ( z m i n z 0 ) + y 0 .
  • If z i > z m a x , then
    z m a x z 0 c = x x 0 a x = a c · ( z m a x z 0 ) + x 0 ;
    z m a x z 0 c = y y 0 b y = b c · ( z m a x z 0 ) + y 0 .
In the above we have that i vary from 0 to 1. In the third and final step, the algorithm draws the line between the two endpoints.

5.3. Considerations

If we look carefully at Equation (1), it seems that for certain values a division by zero may occur. Let us examine the case of the x coordinate of an endpoint. According to the second step of the algorithm, the x coordinate is being checked as to whether it is less than x m i n or greater than x m a x . If we replace x = x m i n and solve for y and z the new coordinates will be
x x 0 x 1 x 0 = y y 0 y 1 y 0 y = y 1 y 0 x 1 x 0 · ( x m i n x 0 ) + y 0
x x 0 x 1 x 0 = z z 0 z 1 z 0 z = z 1 z 0 x 1 x 0 · ( x m i n x 0 ) + z 0 .
Likewise, if we replace x = x m a x and solve for y and z the new coordinates will be as follows:
y = y 1 y 0 x 1 x 0 · ( x m a x x 0 ) + y 0
z = z 1 z 0 x 1 x 0 · ( x m a x x 0 ) + z 0 .
Division by zero will occur, only if x 0 = x 1 . However, when x 0 = x 1 and x < x m i n or x > x m a x the line is vertical to the Y axis and is totally outside the clipping region, so division by zero will never occur according to the first step’s condition. On the other hand, if  x m i n x x m a x then there is no need to apply clipping for the specific coordinate, so, again, division by zero will not occur in this range. Similarly, division by zero will never occur for all other coordinates.

5.4. The Steps in Brief and the Pseudocode

The steps of the algorithm are as follows:
  • Check, if both endpoints of the line are outside the same side of the rectangular parallelepiped clipping region. If this is true then stop and draw nothing or else proceed to Step 2.
  • Compare each coordinate of each endpoint of the line along with the boundaries of the clipping region (left, right, top, bottom, near, and far). If a coordinate is outside the clipping boundary, then use the boundary coordinate instead and calculate the other coordinates of the endpoint, respectively.
  • Draw the clipped line between the two endpoints.

6. Evaluation and Experimental Results

To determine the efficiency of the proposed algorithm, we evaluate it against the Cohen–Sutherland, Liang–Barsky, Cyrus–Beck and Kolingerova algorithms. Each algorithm had to clip a large number of arbitrary lines generated in a three-dimensional space. The boundaries of this space were defined by the points (−400, −400, 400) and (400, 400, −400). The clipping region has the following dimensions: 200 pixels width, 150 pixels height, and 100 pixels depth with its centre at the centre of the screen and the start of the axes X, Y, and Z (Figure 17). The lines were randomly generated anywhere in the three-dimensional space and each algorithm drew only the visible part of the lines inside the clipping region. The time that each algorithm needed to clip the lines was recorded in every execution. The whole process was repeated ten times and, in the end, the average time was calculated.
The hardware, as well as the software, specifications for our evaluation were as follows: (a) AMD FX Quad-Core [email protected] GHz CPU, (b) RAM 16 GB, (c) NVIDIA GeForce GTX-1050 GPU, (d) Windows 10 Professional operating system, (e) C++ with OpenGL/FreeGLUT under the Code::Blocks environment. Each algorithm should have clipped and drawn one million lines in every execution. The visual result was a rectangular parallelepiped volume full of clipped lines (Figure 18), whereas the evaluation results are shown in Table 1.
Using the above results, a graph for the clipping times of each algorithm was created (Figure 19).
By using the formula
p r o p o s e d o t h e r p r o p o s e d · 100
we can evaluate the speed of the proposed algorithm in percent compared to the other algorithms. Compared to the Cohen–Sutherland algorithm, the proposed algorithm was faster by 57.16%; compared to the Liang–Barsky algorithm, our algorithm was faster by 52.73%; compared to the Cyrus–Beck algorithm, our algorithm was faster by 109.75%; and compared to the Kolingerova algorithm, our algorithm was faster by 102.66%.
The experiment was also performed for similar types of line segments, e.g., segments that were strictly inside the clipping region and did not intersect it. The results were in accordance with the above results; there were no different running times for all algorithms.

7. Summary

Line clipping is a technique that is widely used in computer graphics. The three-dimensional viewing pipeline involves many more complicated stages than its two-dimensional analogue. When a three-dimensional scene is projected onto a two-dimensional plane by using perspective projection, transforming the frustum-shaped view volume into a canonical one (rectangular parallelepiped) is considered good practice and speeds up the process since clipping against a frustum-shaped view volume is computationally expensive. In the present article, an overview of the most common, as well as of the lesser-known, algorithms for clipping a line against a rectangular region in a three-dimensional space was presented. Moreover, a simple and fast algorithm (see Algorithm 1) for clipping a line segment against a rectangular parallelepiped view volume was proposed. The algorithm is straightforward to implement in any programming language.
Algorithm 1 The proposed algorithm
void clip_3d_line(double x[], double y[], double z[], double xmin, double xmax, double
ymin, double ymax, double zmin, double zmax)
{
      if( !((x[0] < xmin && x[1] < xmin) || (x[0] > xmax && x[1] > xmax) ||
            (y[0] < ymin && y[1] < ymin) || (y[0] > ymax && y[1] > ymax) ||
            (z[0] < zmin && z[1] < zmin) || (z[0] > zmax && z[1] > zmax)) )
      {
            double a = x[1] − x[0];
            double b = y[1] − y[0];
            double c = z[1] − z[0];
            for(int i = 0; i <= 1; i++)
            {
                  if(x[i] < xmin)
                  {
                        y[i] = b / a * (xmin − x[0]) + y[0];
                        z[i] = c / a * (xmin − x[0]) + z[0];
                        x[i] = xmin;
                  }
                  else if(x[i] > xmax)
                  {
                        y[i] = b / a * (xmax − x[0]) + y[0];
                        z[i] = c / a * (xmax − x[0]) + z[0];
                        x[i] = xmax;
                  }
                  if(y[i] < ymin)
                  {
                        x[i] = a / b * (ymin − y[0]) + x[0];
                        z[i] = c / b * (ymin − y[0]) + z[0];
                        y[i] = ymin;
                  }
                  else if(y[i] > ymax)
                  {
                        x[i] = a / b * (ymax − y[0]) + x[0];
                        z[i] = c / b * (ymax − y[0]) + z[0];
                        y[i] = ymax;
                  }
                  if(z[i] < zmin)
                  {
                        x[i] = a / c * (zmin − z[0]) + x[0];
                        y[i] = b / c * (zmin − z[0]) + y[0];
                        z[i] = zmin;
                  }
                  else if(z[i] > zmax)
                  {
                        x[i] = a / c * (zmax − z[0]) + x[0];
                        y[i] = b / c * (zmax − z[0]) + y[0];
                        z[i] = zmax;
                  }
            }
      }
      draw_line(x[0], y[0], z[0], x[1], y[1], z[1]);
}

Author Contributions

Conceptualization, V.D.; methodology, D.M. and V.D.; software, D.M.; formal analysis, D.M.; data curation, D.M.; writing–original draft preparation, D.M.; writing–review and editing, V.D.; visualization, D.M.; supervision, V.D. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Data Availability Statement

Not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

Nomenclature

References

  1. Hearn, D.; Baker, M.P.; Carithers, W.R. Computer Graphics with Open GL, 4th ed.; Pearson Education Limited: Harlow, UK, 2014. [Google Scholar]
  2. Hughes, J.F.; van Dam, A.; McGuire, M.; Sklar, D.F.; Foley, J.D.; Feiner, S.K.; Akeley, K. Computer Graphics Principles and Practice, 3rd ed.; Addison-Wesley Professional: Boston, MA, USA, 2013. [Google Scholar]
  3. Rogers, D.F. Procedural Elements for Computer Graphics, 2nd ed.; McGraw-Hill, Inc.: New York City, NY, USA, 1997. [Google Scholar]
  4. Matthes, D.; Drakopoulos, V. Another simple but faster method for 2D line clipping. Int. J. Comput. Graph. Animat. 2019, 9, 1–15. [Google Scholar] [CrossRef]
  5. Liang, Y.D.; Barsky, B.A. A new concept and method for line clipping. TOG 1984, 3, 1–22. [Google Scholar] [CrossRef]
  6. Cyrus, M.; Beck, J. Generalized two- and three-dimensional clipping. Comput. Graph. 1978, 3, 23–28. [Google Scholar] [CrossRef]
  7. Nicholl, T.M.; Lee, D.; Nicholl, R.A. An efficient new algorithm for 2-D line clipping: Its development and analysis. Comput. Graph. 1987, 21, 253–262. [Google Scholar] [CrossRef]
  8. Skala, V. A new approach to line and line segment clipping in homogeneous coordinates. Vis. Comput. 2005, 21, 905–914. [Google Scholar] [CrossRef]
  9. Skala, V. S-clip E2: A new concept of clipping algorithms. In Proceedings of the SA ’12: SIGGRAPH Asia, Singapore, 28 November 2012–1 December 2012. [Google Scholar] [CrossRef]
  10. Kodituwakku, S.R.; Wijeweera, K.R.; Chamikara, M.A.P. An efficient algorithm for line clipping in computer graphics programming. Ceylon J. Sci. (Physical Sci.) 2013, 1, 1–7. [Google Scholar]
  11. Huang, W. The Line Clipping Algorithm Basing on Affine Transformation. Intell. Inf. Manag. 2010, 2, 380–385. [Google Scholar] [CrossRef] [Green Version]
  12. Duvanenko, V.J.; Gyurcsik, R.S.; Robbins, W.E. Simple and Efficient 2D and 3D Span Clipping Algorithms. Comput. Graph. 1993, 17, 37–54. [Google Scholar] [CrossRef]
  13. Kodituwakku, S.R.; Wijeweera, K.R.; Chamikara, M.A.P. An efficient line clipping algorithm for 3D space. Int. J. Adv. Res. Comput. Sci. Softw. Eng. 2012, 2, 96–101. [Google Scholar]
  14. Kolingerova, I. 3D-line Clipping Algorithms—A Comparative Study. Vis. Comput. 1994, 11, 96–104. [Google Scholar] [CrossRef]
Figure 1. (a) Before and (b) after application of line clipping in two dimensions.
Figure 1. (a) Before and (b) after application of line clipping in two dimensions.
Algorithms 16 00201 g001
Figure 2. A line in the three-dimensional space after clipping.
Figure 2. A line in the three-dimensional space after clipping.
Algorithms 16 00201 g002
Figure 3. Obtaining a selected view of a three-dimensional scene (camera).
Figure 3. Obtaining a selected view of a three-dimensional scene (camera).
Algorithms 16 00201 g003
Figure 4. (a) Line AB and its perspective projection A’B’. (b) Line AB and its parallel projection A’B’.
Figure 4. (a) Line AB and its perspective projection A’B’. (b) Line AB and its parallel projection A’B’.
Algorithms 16 00201 g004
Figure 5. Types of view volume: (a) rectangular parallelepiped, (b) truncated pyramid also known as a frustum.
Figure 5. Types of view volume: (a) rectangular parallelepiped, (b) truncated pyramid also known as a frustum.
Algorithms 16 00201 g005
Figure 6. Conceptual model of the three-dimensional viewing process.
Figure 6. Conceptual model of the three-dimensional viewing process.
Algorithms 16 00201 g006
Figure 7. A frustum-shaped clipping region is computational expensive.
Figure 7. A frustum-shaped clipping region is computational expensive.
Algorithms 16 00201 g007
Figure 8. Implementation of three-dimensional viewing.
Figure 8. Implementation of three-dimensional viewing.
Algorithms 16 00201 g008
Figure 9. Applying clipping using a normalized canonical clipping region.
Figure 9. Applying clipping using a normalized canonical clipping region.
Algorithms 16 00201 g009
Figure 10. Cohen–Sutherland 3D six-bit representation.
Figure 10. Cohen–Sutherland 3D six-bit representation.
Algorithms 16 00201 g010
Figure 11. Three-dimensional six-bit region codes.
Figure 11. Three-dimensional six-bit region codes.
Algorithms 16 00201 g011
Figure 12. Line L passing through points P 0 ( x 0 , y 0 , z 0 ) and P 1 ( x 1 , y 1 , z 1 ) .
Figure 12. Line L passing through points P 0 ( x 0 , y 0 , z 0 ) and P 1 ( x 1 , y 1 , z 1 ) .
Algorithms 16 00201 g012
Figure 13. Rectangular parallelepiped clipping volume.
Figure 13. Rectangular parallelepiped clipping volume.
Algorithms 16 00201 g013
Figure 14. Line L in three-dimensional space.
Figure 14. Line L in three-dimensional space.
Algorithms 16 00201 g014
Figure 15. Rejected lines: line A is left of the clipping region, line B is right of the clipping region, line C is in front of the clipping region, and line D is on the back of the clipping region.
Figure 15. Rejected lines: line A is left of the clipping region, line B is right of the clipping region, line C is in front of the clipping region, and line D is on the back of the clipping region.
Algorithms 16 00201 g015
Figure 16. Using the boundary coordinates for the endpoints of the line.
Figure 16. Using the boundary coordinates for the endpoints of the line.
Algorithms 16 00201 g016
Figure 17. The three-dimensional space used for generating arbitrary lines and setting the clipping volume.
Figure 17. The three-dimensional space used for generating arbitrary lines and setting the clipping volume.
Algorithms 16 00201 g017
Figure 18. One million clipped lines inside the clipping volume.
Figure 18. One million clipped lines inside the clipping volume.
Algorithms 16 00201 g018
Figure 19. Average time of each algorithm when clipping one million lines (lower is better).
Figure 19. Average time of each algorithm when clipping one million lines (lower is better).
Algorithms 16 00201 g019
Table 1. Execution times of each algorithm when clipping one million lines.
Table 1. Execution times of each algorithm when clipping one million lines.
ExecutionCS 3DLB 3DCB 3DKG 3DProposed
(s)(s)(s)(s)(s)
10.0940.1000.1520.1370.070
20.1140.1030.1450.1360.069
30.1020.1050.1380.1430.064
40.1070.1020.1390.1330.068
50.1160.1060.1490.1400.066
60.1040.1070.1530.1360.070
70.1050.1150.1320.1340.069
80.1150.0900.1370.1350.064
90.1060.1000.1400.1370.067
100.1010.1060.1350.1410.070
Avg. time:0.1060.1030.1420.1370.068
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Matthes, D.; Drakopoulos, V. Line Clipping in 3D: Overview, Techniques and Algorithms. Algorithms 2023, 16, 201. https://doi.org/10.3390/a16040201

AMA Style

Matthes D, Drakopoulos V. Line Clipping in 3D: Overview, Techniques and Algorithms. Algorithms. 2023; 16(4):201. https://doi.org/10.3390/a16040201

Chicago/Turabian Style

Matthes, Dimitrios, and Vasileios Drakopoulos. 2023. "Line Clipping in 3D: Overview, Techniques and Algorithms" Algorithms 16, no. 4: 201. https://doi.org/10.3390/a16040201

APA Style

Matthes, D., & Drakopoulos, V. (2023). Line Clipping in 3D: Overview, Techniques and Algorithms. Algorithms, 16(4), 201. https://doi.org/10.3390/a16040201

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop