├── Bresenham画圆(wrong).cpp ├── Bresenhsm.cpp ├── Cohen-Sutheerland裁剪 ├── Cohen-Sutheerland裁剪.cpp └── DDL_Line.h ├── DDL画线 ├── DDL_Line.h └── DDL画线.cpp ├── README.md ├── bezier.cpp ├── readmeDisplay ├── 0.png ├── 1.png ├── 2.png ├── 3.png ├── 4.png └── 5.png ├── 中点画圆.cpp ├── 中点画线.cpp ├── 多边形扫描填充 ├── AETNET.h ├── POLYGEN.h └── 多边形填充(still have bugs).cpp ├── 多边形种子填充 ├── POLYGEN.h └── 多边形种子填充.cpp └── 椭圆弧扫描转化.cpp /Bresenham画圆(wrong).cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/Bresenham画圆(wrong).cpp -------------------------------------------------------------------------------- /Bresenhsm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/Bresenhsm.cpp -------------------------------------------------------------------------------- /Cohen-Sutheerland裁剪/Cohen-Sutheerland裁剪.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/Cohen-Sutheerland裁剪/Cohen-Sutheerland裁剪.cpp -------------------------------------------------------------------------------- /Cohen-Sutheerland裁剪/DDL_Line.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef DDL_Line_H_ 3 | #define DDL_Line_H_ 4 | 5 | #define WIDTH 500 6 | #define HEIGHT 500 7 | 8 | #include 9 | struct point { 10 | int x; 11 | int y; 12 | point() {} 13 | point(int a, int b) { 14 | x = a; 15 | y = b; 16 | } 17 | }; 18 | 19 | class DDL { 20 | private: 21 | unsigned char* pixels; 22 | void set_pixel(int x, int y) { 23 | int index = y*WIDTH + x; 24 | pixels[index * 3 + 0] = 255; 25 | pixels[index * 3 + 1] = 0; 26 | pixels[index * 3 + 2] = 0; 27 | } 28 | void DDL_init_x(int x1, int y1, int x2, int y2) { 29 | int index; 30 | double k = (y2 - y1) *1.0 / (x2 - x1); 31 | double now_y = y1; 32 | for (int x = x1; x <= x2; x++) { 33 | int y = int(now_y + 0.5); 34 | set_pixel(x, y); 35 | now_y += k; 36 | } 37 | 38 | } 39 | void DDL_init_y(int x1, int y1, int x2, int y2) { 40 | int index; 41 | double k = (x2 - x1) *1.0 / (y2 - y1); 42 | double now_x = x1; 43 | for (int y = y1; y <= y2; y++) { 44 | int x = int(now_x + 0.5); 45 | set_pixel(x, y); 46 | now_x += k; 47 | } 48 | } 49 | void DDL_init(int x1, int y1, int x2, int y2) { 50 | double k = (y2 - y1) *1.0 / (x2 - x1); 51 | if (fabs(k) <= 1) { 52 | if (x1 < x2) { 53 | DDL_init_x(x1, y1, x2, y2); 54 | } 55 | else { 56 | DDL_init_x(x2, y2, x1, y1); 57 | } 58 | } 59 | else { 60 | if (y1 < y2) { 61 | DDL_init_y(x1, y1, x2, y2); 62 | } 63 | else { 64 | DDL_init_y(x2, y2, x1, y1); 65 | } 66 | } 67 | } 68 | 69 | public: 70 | DDL(unsigned char* &p) { 71 | pixels = p; 72 | } 73 | void DDL_drawLine(point x, point y) { 74 | DDL_init(x.x, x.y, y.x, y.y); 75 | } 76 | }; 77 | 78 | 79 | 80 | #endif // !DDL_Line_H_ 81 | -------------------------------------------------------------------------------- /DDL画线/DDL_Line.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef DDL_Line_H_ 3 | #define DDL_Line_H_ 4 | #define WIDTH 500 5 | #define HEIGHT 500 6 | #include 7 | struct point { 8 | int x; 9 | int y; 10 | point() {} 11 | point(int a, int b) { 12 | x = a; 13 | y = b; 14 | } 15 | }; 16 | class DDL { 17 | private: 18 | unsigned char* pixels; 19 | void set_pixel(int x, int y) { 20 | int index = y*WIDTH + x; 21 | pixels[index * 3 + 0] = 255; 22 | pixels[index * 3 + 1] = 0; 23 | pixels[index * 3 + 2] = 0; 24 | } 25 | void DDL_init_x(int x1, int y1, int x2, int y2) { 26 | int index; 27 | double k = (y2 - y1) *1.0 / (x2 - x1); 28 | double now_y = y1; 29 | for (int x = x1; x <= x2; x++) { 30 | int y = int(now_y + 0.5); 31 | set_pixel(x, y); 32 | now_y += k; 33 | } 34 | 35 | } 36 | void DDL_init_y(int x1, int y1, int x2, int y2) { 37 | int index; 38 | double k = (x2 - x1) *1.0 / (y2 - y1); 39 | double now_x = x1; 40 | for (int y = y1; y <= y2; y++) { 41 | int x = int(now_x + 0.5); 42 | set_pixel(x, y); 43 | now_x += k; 44 | } 45 | } 46 | void DDL_init(int x1, int y1, int x2, int y2) { 47 | double k = (y2 - y1) *1.0 / (x2 - x1); 48 | if (fabs(k) <= 1) { 49 | if (x1 < x2) { 50 | DDL_init_x(x1, y1, x2, y2); 51 | } 52 | else { 53 | DDL_init_x(x2, y2, x1, y1); 54 | } 55 | } 56 | else { 57 | if (y1 < y2) { 58 | DDL_init_y(x1, y1, x2, y2); 59 | } 60 | else { 61 | DDL_init_y(x2, y2, x1, y1); 62 | } 63 | } 64 | } 65 | public: 66 | DDL(unsigned char* &p) { 67 | pixels = p; 68 | } 69 | void DDL_drawLine(point x, point y) { 70 | DDL_init(x.x, x.y, y.x, y.y); 71 | } 72 | }; 73 | #endif // !DDL_Line_H_ 74 | -------------------------------------------------------------------------------- /DDL画线/DDL画线.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/DDL画线/DDL画线.cpp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Computer-Graphics 2 | 3 | > Author: Yuchao Gu 4 | 5 | > E-mail: 2015014178@buct.edu.cn 6 | 7 | > Date: 2017-12-27 8 | 9 | >Description: 图形学算法实现 10 | 11 | ## 功能概览 12 | 13 | ### DDL画线 14 | 15 | ![](./readmeDisplay/0.png) 16 | 17 | ### 中点画圆 18 | 19 | ![](./readmeDisplay/1.png) 20 | 21 | ### 中点画椭圆 22 | 23 | ![](./readmeDisplay/2.png) 24 | 25 | ### 填充算法 26 | 27 | ![](./readmeDisplay/4.png) 28 | 29 | ### 裁剪算法 30 | 31 | ![](./readmeDisplay/3.png) 32 | 33 | ### bezier曲线 34 | 35 | ![](./readmeDisplay/5.png) 36 | 37 | ## 环境 38 | 39 | * 系统支持:`windows` 40 | 41 | * 编程环境:`vs2017` -------------------------------------------------------------------------------- /bezier.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/bezier.cpp -------------------------------------------------------------------------------- /readmeDisplay/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/readmeDisplay/0.png -------------------------------------------------------------------------------- /readmeDisplay/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/readmeDisplay/1.png -------------------------------------------------------------------------------- /readmeDisplay/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/readmeDisplay/2.png -------------------------------------------------------------------------------- /readmeDisplay/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/readmeDisplay/3.png -------------------------------------------------------------------------------- /readmeDisplay/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/readmeDisplay/4.png -------------------------------------------------------------------------------- /readmeDisplay/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/readmeDisplay/5.png -------------------------------------------------------------------------------- /中点画圆.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/中点画圆.cpp -------------------------------------------------------------------------------- /中点画线.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/中点画线.cpp -------------------------------------------------------------------------------- /多边形扫描填充/AETNET.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/多边形扫描填充/AETNET.h -------------------------------------------------------------------------------- /多边形扫描填充/POLYGEN.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef POLYGEN_H 3 | #define POLYGEN_H 4 | 5 | #include 6 | #include 7 | struct point { 8 | int x; 9 | int y; 10 | point() {} 11 | point(int a, int b) { 12 | x = a; 13 | y = b; 14 | } 15 | }; 16 | struct edge { 17 | point begin; 18 | point end; 19 | edge(point x, point y) { 20 | begin = x; 21 | end = y; 22 | } 23 | }; 24 | class polygon { 25 | public: 26 | std::vector edge_v; 27 | int min_y=10000; 28 | int max_y = -1; 29 | polygon() { 30 | polygen_init(); 31 | } 32 | void insert_edge(point x, point y) { 33 | edge_v.push_back(edge(x, y)); 34 | min_y = std::min(std::min(min_y, x.y), y.y); 35 | max_y = std::max(std::max(max_y, x.y), y.y); 36 | } 37 | void polygen_init() { 38 | 39 | insert_edge(point(20, 20), point(50, 10)); 40 | insert_edge(point(50, 10), point(110, 30)); 41 | insert_edge(point(110, 30), point(110, 80)); 42 | insert_edge(point(110, 80), point(50, 50)); 43 | insert_edge(point(50, 50), point(20, 70)); 44 | insert_edge(point(20, 70), point(20, 20)); 45 | /* 46 | insert_edge(point(2, 2), point(5, 1)); 47 | insert_edge(point(5, 1), point(11, 3)); 48 | insert_edge(point(11, 3), point(11, 8)); 49 | insert_edge(point(11, 8), point(5, 5)); 50 | insert_edge(point(5, 5), point(2, 7)); 51 | insert_edge(point(2, 7), point(2, 2));*/ 52 | } 53 | }; 54 | 55 | 56 | #endif // !POLYGEN_H 57 | -------------------------------------------------------------------------------- /多边形扫描填充/多边形填充(still have bugs).cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/多边形扫描填充/多边形填充(still have bugs).cpp -------------------------------------------------------------------------------- /多边形种子填充/POLYGEN.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef POLYGEN_H 3 | #define POLYGEN_H 4 | 5 | const int W = 400; 6 | #include 7 | #include 8 | #include 9 | struct point { 10 | int x; 11 | int y; 12 | point() {} 13 | point(int a, int b) { 14 | x = a; 15 | y = b; 16 | } 17 | }; 18 | struct edge { 19 | point begin; 20 | point end; 21 | edge(point x, point y) { 22 | begin = x; 23 | end = y; 24 | } 25 | }; 26 | class polygon { 27 | public: 28 | std::vector edge_v; 29 | std::map is_edge; 30 | point seed; 31 | polygon() { 32 | polygen_init(); 33 | seed = point(40, 50); 34 | 35 | } 36 | void insert_edge(point x, point y) { 37 | DDL_init(x.x,x.y, y.x,y.y); 38 | } 39 | void DDL_init_x(int x1, int y1, int x2, int y2) { 40 | int index; 41 | double k = (y2 - y1) *1.0 / (x2 - x1); 42 | double now_y = y1; 43 | for (int x = x1; x <= x2; x++) { 44 | int y = int(now_y + 0.5); 45 | index = y*W + x; 46 | is_edge[index] = 1; 47 | now_y += k; 48 | } 49 | 50 | } 51 | void DDL_init_y(int x1, int y1, int x2, int y2) { 52 | int index; 53 | double k = (x2 - x1) *1.0 / (y2 - y1); 54 | double now_x = x1; 55 | for (int y = y1; y <= y2; y++) { 56 | int x = int(now_x + 0.5); 57 | index = y*W + x; 58 | is_edge[index] = 1; 59 | now_x += k; 60 | } 61 | } 62 | void DDL_init(int x1, int y1, int x2, int y2) { 63 | double k = (y2 - y1) *1.0 / (x2 - x1); 64 | if (fabs(k) <= 1) { 65 | if (x1 < x2) { 66 | DDL_init_x(x1, y1, x2, y2); 67 | } 68 | else { 69 | DDL_init_x(x2, y2, x1, y1); 70 | } 71 | } 72 | else { 73 | if (y1 < y2) { 74 | DDL_init_y(x1, y1, x2, y2); 75 | } 76 | else { 77 | DDL_init_y(x2, y2, x1, y1); 78 | } 79 | } 80 | } 81 | void polygen_init() { 82 | insert_edge(point(20, 20), point(50, 10)); 83 | insert_edge(point(50, 10), point(110, 30)); 84 | insert_edge(point(110, 30), point(110, 80)); 85 | insert_edge(point(110, 80), point(50, 50)); 86 | insert_edge(point(50, 50), point(20, 70)); 87 | insert_edge(point(20, 70), point(20, 20)); 88 | } 89 | }; 90 | 91 | 92 | #endif // !POLYGEN_H 93 | -------------------------------------------------------------------------------- /多边形种子填充/多边形种子填充.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/多边形种子填充/多边形种子填充.cpp -------------------------------------------------------------------------------- /椭圆弧扫描转化.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/guyuchao/Computer-Graphics/b5c40f12ad69bb3da2538dec47fb704e4d950ba6/椭圆弧扫描转化.cpp --------------------------------------------------------------------------------