资源简介
计算机图形学内容,中点画(椭)圆法,Bresenham画(椭)圆法的具体实现代码,内有中文注释。
代码片段和文件信息
#include
#include
#include
#include
#include
int round(double x)
{
double t=x-int(x);;
if(t<0.5) return int(x);
if(t>0.5) return int(x)+1;
if(t==0.5&&int(x)%2==0) return int(x);
if(t==0.5&&int(x)%2!=0) return int(x)+1;
}
void Swap(double xdouble y)
{
double t;
t=x;
x=y;
y=t;
}
int Sign(double x){
if (x>0)return 1;
if (x<0)return -1;
if (x==0)return 0;
}
void CirclePoints(HDC hdcint xint yint xsint ys){ //利用八方对称性画圆上的点
if (x+xs==0){
SetPixel(hdcx+xsy+ysRGB(100100100));
SetPixel(hdcx+xs-y+ysRGB(100100100));
SetPixel(hdc-y+xsx+ysRGB(100100100));
SetPixel(hdcy+xsx+ysRGB(100100100));
}
if(y+ys==0){
SetPixel(hdcx+xsy+ysRGB(100100100));
SetPixel(hdc-x+xsy+ysRGB(100100100));
SetPixel(hdcy+xs-x+ysRGB(100100100));
SetPixel(hdcy+xsx+ysRGB(100100100));
}
if(x+xs==y+ys){
SetPixel(hdcx+xsy+ysRGB(100100100));
SetPixel(hdc-x+xsy+ysRGB(100100100));
SetPixel(hdc-x+xs-y+ysRGB(100100100));
SetPixel(hdcx+xs-y+ysRGB(100100100));
}
if(x+xs==-y+ys){
SetPixel(hdcx+xsy+ysRGB(100100100));
SetPixel(hdc-x+xsy+ysRGB(100100100));
SetPixel(hdc-x+xs-y+ysRGB(100100100));
SetPixel(hdcx+xs-y+ysRGB(100100100));
}
else
{
SetPixel(hdcx+xsy+ysRGB(100100100));
SetPixel(hdc-x+xsy+ysRGB(100100100));
SetPixel(hdc-x+xs-y+ysRGB(100100100));
SetPixel(hdcx+xs-y+ysRGB(100100100));
SetPixel(hdc-y+xsx+ysRGB(100100100));
SetPixel(hdc-y+xs-x+ysRGB(100100100));
SetPixel(hdcy+xs-x+ysRGB(100100100));
SetPixel(hdcy+xsx+ysRGB(100100100));
}
}
void EllipsePoints(HDC hdcint xint yint xsint ys){ //利用椭圆的四方对称性画椭圆上的点
SetPixel(hdcx+xsy+ysRGB(100100100));
SetPixel(hdc-x+xsy+ysRGB(100100100));
SetPixel(hdc-x+xs-y+ysRGB(100100100));
SetPixel(hdcx+xs-y+ysRGB(100100100));
}
void DDALine(HDC hdcdouble xsdouble ysdouble xedouble ye)//DDALine
{
double x;
double y;
if(xs>xe) //确定左右端点
{ double t;
t=xs;
xs=xe;
xe=t;
t=ys;
ys=ye;
ye=t;
}
//垂直X轴
if(xs==xe){
x=round(xs);
y=round(ys);
for(;y<=ye;y++){
SetPixel(hdcxyRGB(100100100));
}
}
//平行X轴
if(ys==ye){
x=round(xs);
y=round(ys);
for(;x<=xe;x++){
SetPixel(hdcxyRGB(100100100));
}
}
if(xs!=xe&&ys!=ye){
double dx=xe-xs;
double dy=ye-ys;
double k=dy/dx;
//|k|<=1
if(k!=0&&k<=1&&k>=-1){
x=round(x);
for(x=xsy=ys;x<=xe;x++){
SetPixel(hdcxround(y)RGB(100100100));
y+=k;
}
}
//|k|>1
if(k>1||k<-1){
if(ys>ye) //确定左右端点
{ double t;
t=xs;
xs=xe;
xe=t;
t=ys;
ys=ye;
ye=t;
}
y=round(ys);
k=dx/dy;
for(x=xsy=ys;y<=ye;y++){
SetPixel(hd
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7790 2009-04-15 23:04 graph.cpp
文件 208984 2009-04-15 23:04 program.exe
----------- --------- ---------- ----- ----
216774 2
评论
共有 条评论