中点圆生成算法
因为圆具有对称性,一次性可以画8个点
中点圆生成算法-C++代码
#include<GL\glut.h>
#include<iostream>
#include<cmath>
using namespace std;
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); // Set display-window color to white.
glMatrixMode(GL_PROJECTION); // Set projection parameters.
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}
/*
画点
*/
void setPixel(int x, int y)
{
glColor3f(0.0, 0.0, 1.0); // 蓝色
glPointSize(2.0f);
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
glFlush();
}
/*
8路对称
*/
void Cirpot(int x0, int y0, int x, int y)
{
// 1
setPixel((x0 + x), (y0 + y));
// 2
setPixel((x0 + y), (y0 + x));
// 3
setPixel((x0 + y), (y0 - x));
// 4
setPixel((x0 + x), (y0 - y));
// 5
setPixel((x0 - x), (y0 - y));
// 6
setPixel((x0 - y), (y0 - x));
// 7
setPixel((x0 - y), (y0 + x));
// 8
setPixel((x0 - x), (y0 + y));
}
/*
中点画圆算法
*/
void MidPoint_Circle(int