Sutherland-Hodgman clipping algorithm

Sutherland-Hodgman clipping algorithm

The Sutherland-Hodgman algorithm is used for clipping polygons. It works by extending each line of the "clip polygon" in turn and selecting only vertices from the "subject polygon" that are on the visible side.

Description

Begin with a set of all verices in the subject polygon. Assuming the clip polygon is a rectangle, start by extending the upper side across the whole of the 2D space we are considering. Next, starting from the first vertex of the subject polygon, follow the path of the polygon to the next vertex in the subject polygon. Create new vertices where the path crosses the extended clip polygon line. Repeat this until we are back at the first subject polygon vertex. Now create a new set of all vertices that are on or beneath the extended clip polygon line, including vertices from the clip polygon that are entirely within the subject polygon.

We then need to repeat this process for each clip polygon side by extending the line and creating new sets of vertices that are on the visible side. Once the process is complete, a set of vertices will define a new single polygon that is entirely visible. However, if the subject polygon was concave at vertices outside the clipping polygon, the new polygon may have coincident (i.e. overlapping) edges - this is acceptable for rendering, but not for other applications such as computing shadows.

The Weiler-Atherton algorithm overcomes this by returning a set of divided polygons, but is more complex and computationally more expensive, so Sutherland-Hodgman is used for many rendering applications. Sutherland-Hodgman can also be extended into 3D space by clipping the polygon paths based on the boundaries of planes defined by the viewing space.

Pseudo Code

Given a specific clip plane and an array containing the vertices of a single polygon, the following procedure clips the polygon against the plane.

arrayLength = array.size vertex S = array [ arrayLength - 1 ] for( j = 0, j < arrayLength, j = j+1 ) { vertex P = array [ j ] if( P is inside clip_plane ) { if( S is not inside clip_plane ) { Output( ComputeIntersection( S, P, clip_plane ) ) } Output( P ) } else if( S is inside clip_plane ) { Output( ComputeIntersection( P, S, clip_plane ) ) } S = P }

Output and ComputeIntersection are functions that have not been implemented here for ease of readability (and they are not very complex).

Output is generally some function or code that adds a vertex to an array.

ComputeIntersection finds the intersection point of a line segment and a clip plane and returns that value (a vertex).

ee also

*Weiler-Atherton clipping algorithm
*Clipping (in rasterisation)

External links

* [http://www.cs.drexel.edu/~david/Classes/CS430/Lectures/L-05_Polygons.6.pdf Polygon clipping and filling] Describes the algorithm using images that are easy to understand.


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Weiler-Atherton clipping algorithm — used in computer graphics.It allows clipping of a subject polygon by an arbitrarily shaped clip polygon . It is generally applicable only in 2D. Description The algorithm requires polygons to be clockwise and not reentrant (self intersecting).… …   Wikipedia

  • Sutherland Hodgman — Der Algorithmus von Sutherland Hodgman ist ein Algorithmus der Computergrafik zum Clipping von Polygonen. Inhaltsverzeichnis 1 Grundversion 2 Erweiterte Version 3 Literatur 4 Weblinks …   Deutsch Wikipedia

  • Algorithmus von Sutherland-Hodgman — Der Algorithmus von Sutherland Hodgman ist ein nach Ivan Sutherland und Gary W. Hodgman benannter Algorithmus der Computergrafik zum Clipping von Polygonen. Inhaltsverzeichnis 1 Grundversion 1.1 Pseudo Code 2 Erweiterte Version …   Deutsch Wikipedia

  • Sutherland-Hodgeman — Der Algorithmus von Sutherland Hodgman ist ein Algorithmus der Computergrafik zum Clipping von Polygonen. Inhaltsverzeichnis 1 Grundversion 2 Erweiterte Version 3 Literatur 4 Weblinks …   Deutsch Wikipedia

  • Clipping (computer graphics) — Any procedure which identifies that portion of a picture which is either inside or outside a picture is referred to as a clipping algorithm or clipping. The region against which an object is to be clipped is called clipping window. Contents 1… …   Wikipedia

  • Algoritmo de Cohen-Sutherland — El algoritmo de Cohen Sutherland es un algoritmo de recorte de líneas usado en gráficos por computadora. Fue desarrollado por Danny Cohen e Ivan Sutherland en 1967. Contenido 1 Introducción 2 Funcionamiento 2.1 Códigos de frontera …   Wikipedia Español

  • Clip coordinates — The clip coordinate system is a homogeneous coordinate system in the graphics pipeline. In OpenGL, clip coordinates are positioned in the pipeline just after eye or camera coordinates and just before normalized device coordinates. Objects are… …   Wikipedia

  • Algoritmo de Liang-Barsky — El algoritmo de Liang Barsky es un algoritmo de recorte de líneas similar al algoritmo de Cohen Sutherland. Usa la ecuación paramétrica de la línea y desigualdades describiendo el rango del área de recorte para determinar las intersecciones entre …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”