直线与椭圆画法

本文介绍了直线和椭圆的几种画法,包括BHLine、mpline、DDAline、MDcircle和BHcircle算法。内容包含了可能存在的问题及使用EasyX库进行辅助绘制的说明。
摘要由CSDN通过智能技术生成

画法的原理参考教科书就行,这里给出自己写的代码(可能有BUG)

包含

BHLine(BH直线)

mpline(中点直线)

DDAline(DDA直线,可能有问题,线条不太顺)

MDcircle(中点画圆)

BHcircle(BH画圆)

MDellipse(中点画椭)

除算法本身外的必要函数使用了EasyX库,在此感谢 EasyX 团队。

//#include <stdafx.h>
#include <bits/stdc++.h>
#include <graphics.h>
#include <conio.h>

using namespace std;
const int INF = 0x3f3f3f3f;
void ddaline(int stx, int sty, int enx, int eny, int color) {
	if (stx > enx) swap(stx, enx), swap(sty, eny);
	if (stx == enx) {
		if (sty > eny) swap(sty, eny);
		while (sty <= eny) {
			putpixel(stx, sty, color);
			sty++;
		}
	}
	else if (sty == eny) {
		while (stx <= enx) {
			putpixel(stx, sty, color);
			stx++;
		}
	}
	else {
		double k = (double)(eny - sty) / (enx - stx);
		double y = sty;
		for (; stx <= enx; stx++) {
			putpixel(stx, (int)(y + 0.5), color);
			y += k;
		}
	}
}
void mpline(int stx, int sty, int enx, int eny, int color) {
	if (stx > enx) swap(stx, enx), swap(sty, eny);
	int x = stx, y = sty;
	if (stx == enx) {
		y = min(sty, eny);
		eny = max
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值