In computer graphics, wrapping is the process of limiting a position to an area. A good example of wrapping is
wallpaper
Wallpaper is a material used in interior decoration to decorate the interior walls of domestic and public buildings. It is usually sold in rolls and is applied onto a wall using wallpaper paste. Wallpapers can come plain as "lining paper" (so t ...
, a single pattern repeated indefinitely over a
wall
A wall is a structure and a surface that defines an area; carries a load; provides security, shelter, or soundproofing; or, is decorative. There are many kinds of walls, including:
* Walls in buildings that form a fundamental part of the supe ...
. Wrapping is used in
3D computer graphics
3D computer graphics, or “3D graphics,” sometimes called CGI, 3D-CGI or three-dimensional computer graphics are graphics that use a three-dimensional representation of geometric data (often Cartesian) that is stored in the computer for th ...
to repeat a
texture
Texture may refer to:
Science and technology
* Surface texture, the texture means smoothness, roughness, or bumpiness of the surface of an object
* Texture (roads), road surface characteristics with waves shorter than road roughness
* Texture (c ...
over a
polygon
In geometry, a polygon () is a plane figure that is described by a finite number of straight line segments connected to form a closed ''polygonal chain'' (or ''polygonal circuit''). The bounded plane region, the bounding circuit, or the two toge ...
, eliminating the need for large textures or multiple polygons.
To wrap a position ''x'' to an area of width ''w'', calculate the value
.
Implementation
For computational purposes the wrapped value ''x of ''x'' can be expressed as
:
where
is the highest value in the range, and
is the lowest value in the range.
Pseudocode
In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
for wrapping of a value to a range other than 0–1 is
function wrap(X, Min, Max: Real): Real;
X := X - Int((X - Min) / (Max - Min)) * (Max - Min);
if X < 0 then // This corrects the problem caused by using Int instead of Floor
X := X + Max - Min;
return X;
Pseudocode
In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
for wrapping of a value to a
range of 0–1 is
function wrap(X: Real): Real;
X := X - Int(X);
if X < 0 then
X := X + 1;
return X;
Pseudocode
In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
for wrapping of a value to a
range of 0–1 without branching is,
function wrap(X: Real): Real;
return ((X mod 1.0) + 1.0) mod 1.0;
See also text wrapping
*
Clamping
A wheel clamp, also known as wheel boot, parking boot, or Denver boot, is a device that is designed to prevent motor vehicles from being moved. In its most common form, it consists of a clamp that surrounds a vehicle wheel, designed to preven ...
{{DEFAULTSORT:Wrapping (Graphics)
Computer graphics algorithms