这些计算机图形学中的问题,对我这个c语言学的不好的真实很难办到,也学对您来说就是小菜一碟,哪位大哥大姐帮助以下在下不胜感激!!!
哈哈,把我们实验课的成就给你吧,都在实验室里通过的。不过没有你要的全部
#include <stdafx.h>
#include <math.h>
#define ROUND(a) ((int) (a+0.5))
void bresenham(CDC* pdc,int xs,int ys,int xe,int ye,COLORREF color)//直线
{
int dx=xe-xs;
int dy=ye-ys;
int xinc,yinc;
if(dx>0)
xinc=1;
else
xinc=-1;
if(dy>0)
yinc=1;
else
yinc=-1;
dx=abs(dx);dy=abs(dy);
int x=xs,y=ys;
int i=0;
if(dx==0&&dy==0)
pdc->SetPixel(x,y,color);
else if(dx==0)
{
for(i=0;i<dy;i++)
{
pdc->SetPixel(x,y,color);
y+=yinc;
}
}
else if(dy==0)
{
for(i=0;i<dx;i++)
{
pdc->SetPixel(x,y,color);
x+=xinc;
}
}
else if(dx>dy)
{
int p=2*dy-dx;
int inc1=2*dy,inc2=2*(dy-dx);
for(i=0;i<dx;i++)
{
pdc->SetPixel(x,y,color);
x+=xinc;
if(p<0)
p+=inc1;
else
{
y+=yinc;
p+=inc2;
}
}
}
else
{
int p=2*dx-dy;
int inc1=2*dx,inc2=2*(dx-dy);
for(i=0;i<dy;i++)
{
pdc->SetPixel(x,y,color);
y+=yinc;
if(p<0)
p+=inc1;
else
{
x+=xinc;
p+=inc2;
}
}
}
}
中点圆:
#include "stdafx.h"
void circlePlotPoints(CDC *pdc, int xc,int yc,int x,int y,COLORREF color);
void MidpointCircle(CDC* pdc,int xc,int yc,int r,COLORREF color)
{
int x=0;
int y=r;
int p=1-r;
while(x<=y)
{
circlePlotPoints(pdc, xc,yc,x,y,color);
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
}
}
void circlePlotPoints(CDC *pdc, int xc,int yc,int x,int y,COLORREF color)
{
pdc->SetPixel(xc+x,yc+y,color);
pdc->SetPixel(xc+x,yc-y,color);
pdc->SetPixel(xc-x,yc+y,color);
pdc->SetPixel(xc-x,yc-y,color);
pdc->SetPixel(xc+y,yc+x,color);
pdc->SetPixel(xc+y,yc-x,color);
pdc->SetPixel(xc-y,yc+x,color);
pdc->SetPixel(xc-y,yc-x,color);
}
#include <stdafx.h>
#include <math.h>
#define ROUND(a) ((int) (a+0.5))
void bresenham(CDC* pdc,int xs,int ys,int xe,int ye,COLORREF color)//直线
{
int dx=xe-xs;
int dy=ye-ys;
int xinc,yinc;
if(dx>0)
xinc=1;
else
xinc=-1;
if(dy>0)
yinc=1;
else
yinc=-1;
dx=abs(dx);dy=abs(dy);
int x=xs,y=ys;
int i=0;
if(dx==0&&dy==0)
pdc->SetPixel(x,y,color);
else if(dx==0)
{
for(i=0;i<dy;i++)
{
pdc->SetPixel(x,y,color);
y+=yinc;
}
}
else if(dy==0)
{
for(i=0;i<dx;i++)
{
pdc->SetPixel(x,y,color);
x+=xinc;
}
}
else if(dx>dy)
{
int p=2*dy-dx;
int inc1=2*dy,inc2=2*(dy-dx);
for(i=0;i<dx;i++)
{
pdc->SetPixel(x,y,color);
x+=xinc;
if(p<0)
p+=inc1;
else
{
y+=yinc;
p+=inc2;
}
}
}
else
{
int p=2*dx-dy;
int inc1=2*dx,inc2=2*(dx-dy);
for(i=0;i<dy;i++)
{
pdc->SetPixel(x,y,color);
y+=yinc;
if(p<0)
p+=inc1;
else
{
x+=xinc;
p+=inc2;
}
}
}
}
中点圆:
#include "stdafx.h"
void circlePlotPoints(CDC *pdc, int xc,int yc,int x,int y,COLORREF color);
void MidpointCircle(CDC* pdc,int xc,int yc,int r,COLORREF color)
{
int x=0;
int y=r;
int p=1-r;
while(x<=y)
{
circlePlotPoints(pdc, xc,yc,x,y,color);
x++;
if(p<0)
p+=2*x+1;
else
{
y--;
p+=2*(x-y)+1;
}
}
}
void circlePlotPoints(CDC *pdc, int xc,int yc,int x,int y,COLORREF color)
{
pdc->SetPixel(xc+x,yc+y,color);
pdc->SetPixel(xc+x,yc-y,color);
pdc->SetPixel(xc-x,yc+y,color);
pdc->SetPixel(xc-x,yc-y,color);
pdc->SetPixel(xc+y,yc+x,color);
pdc->SetPixel(xc+y,yc-x,color);
pdc->SetPixel(xc-y,yc+x,color);
pdc->SetPixel(xc-y,yc-x,color);
}
温馨提示:答案为网友推荐,仅供参考