﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Tauruser-随笔分类-计算机图形学</title><link>http://www.cppblog.com/Tauruser/category/1100.html</link><description>Enjoy Every Day</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 17:26:23 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 17:26:23 GMT</pubDate><ttl>60</ttl><item><title>０５年写的直线裁剪算法</title><link>http://www.cppblog.com/Tauruser/archive/2007/01/28/18105.html</link><dc:creator>Tauruser</dc:creator><author>Tauruser</author><pubDate>Sun, 28 Jan 2007 02:28:00 GMT</pubDate><guid>http://www.cppblog.com/Tauruser/archive/2007/01/28/18105.html</guid><wfw:comment>http://www.cppblog.com/Tauruser/comments/18105.html</wfw:comment><comments>http://www.cppblog.com/Tauruser/archive/2007/01/28/18105.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Tauruser/comments/commentRss/18105.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Tauruser/services/trackbacks/18105.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: ０５年上CAD课写的一个直线裁剪程序中的裁剪算法部份，希望对学习图形学要写裁剪算法的同学有参考作用。&nbsp;&nbsp;<a href='http://www.cppblog.com/Tauruser/archive/2007/01/28/18105.html'>阅读全文</a><img src ="http://www.cppblog.com/Tauruser/aggbug/18105.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Tauruser/" target="_blank">Tauruser</a> 2007-01-28 10:28 <a href="http://www.cppblog.com/Tauruser/archive/2007/01/28/18105.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Bresenham画圆法</title><link>http://www.cppblog.com/Tauruser/archive/2006/03/13/4068.html</link><dc:creator>Tauruser</dc:creator><author>Tauruser</author><pubDate>Mon, 13 Mar 2006 01:28:00 GMT</pubDate><guid>http://www.cppblog.com/Tauruser/archive/2006/03/13/4068.html</guid><wfw:comment>http://www.cppblog.com/Tauruser/comments/4068.html</wfw:comment><comments>http://www.cppblog.com/Tauruser/archive/2006/03/13/4068.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/Tauruser/comments/commentRss/4068.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Tauruser/services/trackbacks/4068.html</trackback:ping><description><![CDATA[<P>上个学期考过的CAD，要用C/C++写一个Bresenham画圆算法，结果没看过书，一点都不会，在考场上凭自己对Bresenham是微元法的特例这点理解，乱写一通。考试过后，去图书馆一翻书，才发现我写的和原本的Bresenham完全不一样，Bresenham法画圆是如果的优雅，令我不得不惊叹。<BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;Bresenham_Circle(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;xc,</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;yc,</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;r)<BR><IMG id=Codehighlighter1_43_164_Open_Image onclick="this.style.display='none'; Codehighlighter1_43_164_Open_Text.style.display='none'; Codehighlighter1_43_164_Closed_Image.style.display='inline'; Codehighlighter1_43_164_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_43_164_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_43_164_Closed_Text.style.display='none'; Codehighlighter1_43_164_Open_Image.style.display='inline'; Codehighlighter1_43_164_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_43_164_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_43_164_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;x,y,d;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; y</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">r;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; d</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">r;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp; x</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(x</SPAN><SPAN style="COLOR: #000000">&lt;=</SPAN><SPAN style="COLOR: #000000">y)<BR><IMG id=Codehighlighter1_87_162_Open_Image onclick="this.style.display='none'; Codehighlighter1_87_162_Open_Text.style.display='none'; Codehighlighter1_87_162_Closed_Image.style.display='inline'; Codehighlighter1_87_162_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp; <IMG id=Codehighlighter1_87_162_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_87_162_Closed_Text.style.display='none'; Codehighlighter1_87_162_Open_Image.style.display='inline'; Codehighlighter1_87_162_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_87_162_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_87_162_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plotC(x,y,xc,yc)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(d</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">)<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">x</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">6</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_129_153_Open_Image onclick="this.style.display='none'; Codehighlighter1_129_153_Open_Text.style.display='none'; Codehighlighter1_129_153_Closed_Image.style.display='inline'; Codehighlighter1_129_153_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <IMG id=Codehighlighter1_129_153_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_129_153_Closed_Text.style.display='none'; Codehighlighter1_129_153_Open_Image.style.display='inline'; Codehighlighter1_129_153_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_129_153_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_129_153_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">(x</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">y)</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">y</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">x</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp; }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;plotC(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;x,</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;y,</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;xc,</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;yc)<BR><IMG id=Codehighlighter1_205_375_Open_Image onclick="this.style.display='none'; Codehighlighter1_205_375_Open_Text.style.display='none'; Codehighlighter1_205_375_Closed_Image.style.display='inline'; Codehighlighter1_205_375_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_205_375_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_205_375_Closed_Text.style.display='none'; Codehighlighter1_205_375_Open_Image.style.display='inline'; Codehighlighter1_205_375_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_205_375_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cppblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_205_375_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">x,yc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">y);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">x,yc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">y);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">x,yc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">y);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">x,yc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">y);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">y,yc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">x);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">y,yc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">x);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">y,yc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">x);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; putpixel(xc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">y,yc</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">x);<BR><IMG src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV>其中：(xc,yc)为圆心坐标。r为圆的半径。此算法完全不涉及浮点运算，单是用int的*+-运算就搞掂了一个圆的绘制。<img src ="http://www.cppblog.com/Tauruser/aggbug/4068.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Tauruser/" target="_blank">Tauruser</a> 2006-03-13 09:28 <a href="http://www.cppblog.com/Tauruser/archive/2006/03/13/4068.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>