Line Clipping in 3D: Overview, Techniques and Algorithms
Abstract
:1. Introduction
2. Three-Dimensional View Volumes and Clipping Regions
3. Line-Clipping Algorithms in Three-Dimensions
3.1. Three-Dimensional Cohen–Sutherland Line Clipping
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. |
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. |
3.2. Three-Dimensional Liang–Barsky Line Clipping
- 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.
- When the line is parallel to a clipping boundary, the p value for that boundary is zero.
- When , as t increases the line goes from the outside to the inside (entering).
- When , the line goes from the inside to the outside (exiting).
- When and , the line is trivially invisible because it is outside the clipping region.
- When and , the line is inside the corresponding clipping region.
- When , is taken.
- When , is taken.
3.3. Three-Dimensional Cyrus–Beck Line Clipping
- 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 (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
4. Mathematical Background
5. The Proposed Method
5.1. Nomenclature
5.2. Description
< AND < | (the line is left of the clipping region); |
> AND > | (the line is right of the clipping region); |
< AND < | (the line is under the clipping region); |
> AND > | (the line is above the clipping region); |
< AND < | (the line is behind the clipping region); |
> AND > | (the line is in front of the clipping region). |
- If < , then
- If , then
- If , then
- If , then
- If , then
- If , then
5.3. Considerations
5.4. The Steps in Brief and the Pseudocode
- 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
7. Summary
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
Funding
Data Availability Statement
Conflicts of Interest
Nomenclature
References
- Hearn, D.; Baker, M.P.; Carithers, W.R. Computer Graphics with Open GL, 4th ed.; Pearson Education Limited: Harlow, UK, 2014. [Google Scholar]
- 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]
- Rogers, D.F. Procedural Elements for Computer Graphics, 2nd ed.; McGraw-Hill, Inc.: New York City, NY, USA, 1997. [Google Scholar]
- 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]
- Liang, Y.D.; Barsky, B.A. A new concept and method for line clipping. TOG 1984, 3, 1–22. [Google Scholar] [CrossRef]
- Cyrus, M.; Beck, J. Generalized two- and three-dimensional clipping. Comput. Graph. 1978, 3, 23–28. [Google Scholar] [CrossRef]
- 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]
- Skala, V. A new approach to line and line segment clipping in homogeneous coordinates. Vis. Comput. 2005, 21, 905–914. [Google Scholar] [CrossRef]
- 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]
- 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]
- Huang, W. The Line Clipping Algorithm Basing on Affine Transformation. Intell. Inf. Manag. 2010, 2, 380–385. [Google Scholar] [CrossRef] [Green Version]
- 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]
- 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]
- Kolingerova, I. 3D-line Clipping Algorithms—A Comparative Study. Vis. Comput. 1994, 11, 96–104. [Google Scholar] [CrossRef]
Execution | CS 3D | LB 3D | CB 3D | KG 3D | Proposed |
---|---|---|---|---|---|
(s) | (s) | (s) | (s) | (s) | |
1 | 0.094 | 0.100 | 0.152 | 0.137 | 0.070 |
2 | 0.114 | 0.103 | 0.145 | 0.136 | 0.069 |
3 | 0.102 | 0.105 | 0.138 | 0.143 | 0.064 |
4 | 0.107 | 0.102 | 0.139 | 0.133 | 0.068 |
5 | 0.116 | 0.106 | 0.149 | 0.140 | 0.066 |
6 | 0.104 | 0.107 | 0.153 | 0.136 | 0.070 |
7 | 0.105 | 0.115 | 0.132 | 0.134 | 0.069 |
8 | 0.115 | 0.090 | 0.137 | 0.135 | 0.064 |
9 | 0.106 | 0.100 | 0.140 | 0.137 | 0.067 |
10 | 0.101 | 0.106 | 0.135 | 0.141 | 0.070 |
Avg. time: | 0.106 | 0.103 | 0.142 | 0.137 | 0.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. |
© 2023 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Matthes, D.; Drakopoulos, V. Line Clipping in 3D: Overview, Techniques and Algorithms. Algorithms 2023, 16, 201. https://doi.org/10.3390/a16040201
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 StyleMatthes, 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 StyleMatthes, D., & Drakopoulos, V. (2023). Line Clipping in 3D: Overview, Techniques and Algorithms. Algorithms, 16(4), 201. https://doi.org/10.3390/a16040201