dbo:abstract
|
- 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 la línea y el área de recorte. Fue desarrollado por You-Dong Liang y Brian A. Barsky. Basándonos en las siguientes ecuaciones: x=x1 + uΔxy=y1 + uΔy0<=u<=1 Donde Δx= x2-x1 y Δy= y2-y1 Con estas intersecciones se sabe qué porción de la línea debería ser dibujada. Este algoritmo es significativamente más eficiente que el de Cohen-Sutherland. (es)
- In computer graphics, the Liang–Barsky algorithm (named after You-Dong Liang and Brian A. Barsky) is a line clipping algorithm. The Liang–Barsky algorithm uses the parametric equation of a line and inequalities describing the range of the clipping window to determine the intersections between the line and the clip window. With these intersections it knows which portion of the line should be drawn. This algorithm is significantly more efficient than Cohen–Sutherland. The idea of the Liang–Barsky clipping algorithm is to do as much testing as possible before computing line intersections. Consider first the usual parametric form of a straight line: A point is in the clip window, if and which can be expressed as the 4 inequalities where To compute the final line segment: 1.
* A line parallel to a clipping window edge has for that boundary. 2.
* If for that , , then the line is completely outside and can be eliminated. 3.
* When , the line proceeds outside to inside the clip window, and when , the line proceeds inside to outside. 4.
* For nonzero , gives for the intersection point of the line and the window edge (possibly projected). 5.
* The two actual intersections of the line with the window edges, if they exist, are described by and , calculated as follows. For , look at boundaries for which (i.e. outside to inside). Take to be the largest among . For , look at boundaries for which (i.e. inside to outside). Take to be the minimum of . 6.
* If , the line is entirely outside the clip window. If it is entirely inside it.// Liang—Barsky line-clipping algorithm#include#include#includeusing namespace std;// this function gives the maximumfloat maxi(float arr[],int n) { float m = 0; for (int i = 0; i < n; ++i) if (m < arr[i]) m = arr[i]; return m;}// this function gives the minimumfloat mini(float arr[], int n) { float m = 1; for (int i = 0; i < n; ++i) if (m > arr[i]) m = arr[i]; return m;}void liang_barsky_clipper(float xmin, float ymin, float xmax, float ymax, float x1, float y1, float x2, float y2) { // defining variables float p1 = -(x2 - x1); float p2 = -p1; float p3 = -(y2 - y1); float p4 = -p3; float q1 = x1 - xmin; float q2 = xmax - x1; float q3 = y1 - ymin; float q4 = ymax - y1; float posarr[5], negarr[5]; int posind = 1, negind = 1; posarr[0] = 1; negarr[0] = 0; rectangle(xmin, ymin, xmax, ymax); // drawing the clipping window if ((p1 == 0 && q1 < 0) || (p2 == 0 && q2 < 0) || (p3 == 0 && q3 < 0) || (p4 == 0 && q4 < 0)) { outtextxy(80, 80, "Line is parallel to clipping window!"); return; } if (p1 != 0) { float r1 = q1 / p1; float r2 = q2 / p2; if (p1 < 0) { negarr[negind++] = r1; // for negative p1, add it to negative array posarr[posind++] = r2; // and add p2 to positive array } else { negarr[negind++] = r2; posarr[posind++] = r1; } } if (p3 != 0) { float r3 = q3 / p3; float r4 = q4 / p4; if (p3 < 0) { negarr[negind++] = r3; posarr[posind++] = r4; } else { negarr[negind++] = r4; posarr[posind++] = r3; } } float xn1, yn1, xn2, yn2; float rn1, rn2; rn1 = maxi(negarr, negind); // maximum of negative array rn2 = mini(posarr, posind); // minimum of positive array if (rn1 > rn2) { // reject outtextxy(80, 80, "Line is outside the clipping window!"); return; } xn1 = x1 + p2 * rn1; yn1 = y1 + p4 * rn1; // computing new points xn2 = x1 + p2 * rn2; yn2 = y1 + p4 * rn2; setcolor(CYAN); line(xn1, yn1, xn2, yn2); // the drawing the new line setlinestyle(1, 1, 0); line(x1, y1, xn1, yn1); line(x2, y2, xn2, yn2);}int main { cout << "
Liang-barsky line clipping"; cout << "
The system window outlay is: (0,0) at bottom left and (631, 467) at top right"; cout << "
Enter the co-ordinates of the window(wxmin, wymin, wxmax, wymax):"; float xmin, ymin, xmax, ymax; cin >> xmin >> ymin >> xmax >> ymax; cout << "
Enter the end points of the line (x1, y1) and (x2, y2):"; float x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; int gd = DETECT, gm; // using the winbgim library for C++, initializing the graphics mode initgraph(&gd, &gm, ""); liang_barsky_clipper(xmin, ymin, xmax, ymax, x1, y1, x2, y2); getch; closegraph;} (en)
- Algorytm Lianga-Barsky’ego – algorytm obcinania odcinka do prostokątnego okna, stosowany w grafice komputerowej. Nazwa algorytmu pochodzi od nazwisk autorów i , którzy zaproponowali go w swojej pracy. Algorytm wykorzystuje parametryczne równanie odcinka oraz nierówności opisujące prostokątne okno do określenia wartości współczynnika parametrycznego, dla których odcinek przecina się z bokami okna. Na podstawie tak uzyskanych danych można określić, którą część odcinka można narysować. Ten algorytm jest bardziej wydajny niż algorytm Cohena-Sutherlanda w przypadku gdy zachodzi konieczność przycięcia odcinka. Pomysłem w algorytmie Lianga-Barsky’ego jest wykonywanie tylu porównań, na ile jest to możliwe przed właściwym obliczaniem końców przyciętego odcinka. (pl)
- Алгоритм Лианга — Барски — алгоритм, используемый в компьютерной графике для в некоторой прямоугольной области. Был разработан и в 1984 году и усовершенствован в 1992 году. Данный алгоритм использует параметрическое представление линии и неравенства для определения того, какая часть отрезка попадает в заданную прямоугольную область. (ru)
- 梁友栋—柏世奇算法(以梁友栋和的名字命名)是计算机图形学中的一个。梁友栋—柏世奇算法使用直线的参数方程和不等式组来描述线段和裁剪窗口的交集。求解出的交集将被用于获知线的哪些部分是应当绘制在屏幕上的。这一算法比科恩-苏泽兰算法(Cohen-Sutherland algorithm)要更加高效,梁友栋—柏世奇算法的基本思想是:在计算线段与裁剪窗交集之前做尽可能多的判断。 (zh)
- У комп'ютерній графіці, алгоритм Ляна — Барського це алгоритм відсікання відрізків. Цей алгоритм використовує параметричне рівняння прямої і нерівності, що описують вікно відсікання для визначення перетинів між відрізком і вікном відсікання. За цими перетинами визначається, яку частину відрізка потрібно малювати. Алгоритм можна узагальнити до тривимірного випадку. Цей алгоритм значно ефективніший від алгоритму Коена — Сазерленда. Розробили і 1984 року і вдосконалили 1992 року. (uk)
|