标签:条件 stream lap play 参考 close img 介绍 image
这节简单介绍了梁友栋-Barsky裁剪算法的原理,只有结论并没有过程,看过http://blog.csdn.net/daisy__ben/article/details/51941608这篇文章后,大概有了新的认识。
"
假设点P1P2W1W2的横坐标分别是x1,x2,w1,w2,线段P1P2与蓝色裁剪窗口W1W2(蓝色的线之间)的存在公共部分(可见部分)的充要条件是:
1 #include <GLUT/GLUT.h> 2 #include <iostream> 3 #include "lineliangbarsk.h" 4 #include "linebres.h" 5 6 GLint clipTest (GLfloat p, GLfloat q, GLfloat * u1, GLfloat * u2) 7 { 8 GLfloat r; 9 GLint returnValue = true; 10 11 if(p < 0.0) 12 { 13 r = q / p; 14 if(r > *u2) 15 { 16 returnValue = false; 17 } 18 else 19 { 20 if(r > *u1) 21 { 22 *u1 = r; 23 } 24 } 25 } 26 else 27 { 28 if(p > 0.0) 29 { 30 r = q / p; 31 if(r < *u1) 32 { 33 returnValue = false; 34 } 35 else 36 { 37 if(r < *u2) 38 { 39 *u2 = r; 40 } 41 } 42 } 43 else 44 { 45 if(q < 0.0) 46 { 47 returnValue = false; 48 } 49 } 50 } 51 return returnValue; 52 } 53 54 void lineClipLiangBarsk(wcPt2D winMin, wcPt2D winMax, wcPt2D p1, wcPt2D p2) 55 { 56 GLfloat u1 = 0.0, u2 = 1.0, dx = p2.getx() - p1.getx(), dy; 57 58 if(clipTest(-dx, p1.getx() - winMin.getx(), &u1, &u2)) 59 { 60 if(clipTest(dx, winMax.getx() - p1.getx(), &u1, &u2)) 61 { 62 dy = p2.gety() - p1.gety(); 63 if(clipTest(-dy, p1.gety() - winMin.gety(), &u1, &u2)) 64 { 65 if(clipTest(dy, winMax.gety() - p1.gety(), &u1, &u2)) 66 { 67 if(u2 < 1.0) 68 { 69 p2.setCoords(p1.getx() + u2 * dx, p1.gety() + u2 * dy); 70 } 71 if(u1 > 0.0) 72 { 73 p1.setCoords(p1.getx() + u1 * dx, p1.gety() + u1 * dy); 74 } 75 lineBres(round(p1.getx()), round(p1.gety()), round(p2.getx()), round(p2.gety())); 76 std::cout << "liangbarsk : " << u1 << "," << u2 << std::endl; 77 std::cout << "liangbarsk : " << p1.getx() << "," << p1.gety() << "," << p2.getx() << "," << p2.gety() << std::endl; 78 } 79 } 80 } 81 } 82 }
https://github.com/p0e0o0p0l0e0/Computer_Graphics.git
c05938b3e669c1a04f86a54a69b5e2bb3066bd4e
参考:http://blog.csdn.net/daisy__ben/article/details/51941608
[图形学]Chapter 8.7.2 梁友栋-Barsky线段裁剪算法
标签:条件 stream lap play 参考 close img 介绍 image
原文地址:http://www.cnblogs.com/p0e0o0p0l0e0/p/6918179.html