1.关于任意平行于x轴直线图像的对称
2.关于任意平行于y轴直线图像的对称
3.关于任意点的对称
4.关于直线y=x对称
5.关于直线y=-x对称
编译器:vs2013
1 // x对称.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include<stdio.h> 6 #include"graphics.h" 7 #include<stdlib.h> 8 9 //函数声明 10 void SymmetricalY(int a[], int y);//关于x的直线对称 11 void SymmetricalX(int a[], int x);//关于y的直线对称 12 void Symmetricalxy(int a[], int x, int y);//关于随机点对称 13 void Symmetricaly_x(int a[]);//关于y=x对称 14 void Symmetricaly__x(int a[]); //关于y=-x对称 15 16 int main() 17 { 18 int gdriver = DETECT, gmove; 19 int a[28] = { 100, 100, 150, 150, 250, 150, 250, 0, 350, 150, 450, 150, 500, 200, 450, 250, 350, 250, 250, 400, 250, 250, 150, 250, 100, 300, 100, 100 }; 20 21 //关于x的直线对称 22 /*int x; 23 24 printf("please input the line x= "); 25 scanf_s("%d", &x); 26 27 initgraph(&gdriver, &gmove, ""); 28 29 drawpoly(14, a); 30 31 SymmetricalX(a, x);*/ 32 33 //关于y的直线对称 34 /*int y; 35 36 printf("please input the line y= "); 37 scanf_s("%d", &y); 38 39 initgraph(&gdriver, &gmove, ""); 40 41 drawpoly(14, a); 42 43 SymmetricalY(a, y);*/ 44 45 //关于随机点对称 46 /*int x, y; 47 48 printf("please inout the point: "); 49 scanf_s("%d%d", &x, &y); 50 51 initgraph(&gdriver, &gmove, ""); 52 53 drawpoly(14, a); 54 Symmetricalxy(a, x, y);*/ 55 56 //关于y=x对称 57 /*initgraph(&gdriver, &gmove, ""); 58 drawpoly(14, a); 59 Symmetricaly_x(a);*/ 60 61 //关于y=-x对称 62 initgraph(&gdriver, &gmove, ""); 63 drawpoly(14, a); 64 Symmetricaly__x(a); 65 66 system("pause"); 67 68 closegraph(); 69 70 return 0; 71 } 72 73 //绕任意x直线对称 74 void SymmetricalX(int a[], int x) 75 { 76 int i,b[28]; 77 78 for (i = 0; i < 28; i = i + 2) 79 { 80 b[i] = 2 * x - a[i]; 81 b[i + 1] = a[i + 1]; 82 } 83 84 drawpoly(14,b); 85 } 86 87 //绕任意y直线对称 88 void SymmetricalY(int a[], int y) 89 { 90 int i, b[28]; 91 92 for (i = 0; i < 28; i = i + 2) 93 { 94 b[i+1] = 2 * y - a[i+1]; 95 b[i] = a[i]; 96 } 97 98 drawpoly(14, b); 99 } 100 101 //关于某一点对称 102 void Symmetricalxy(int a[], int x, int y) 103 { 104 int i, b[28]; 105 106 for (i = 0; i < 28; i = i + 2) 107 { 108 //平移至原点 109 b[i] = a[i] - x; 110 b[i + 1] = a[i + 1] - y; 111 //原点的对称变换 112 b[i] = -b[i]; 113 b[i + 1] = -b[i+1]; 114 //平移回去 115 b[i] = b[i] + x; 116 b[i + 1] = b[i + 1] + y; 117 } 118 119 drawpoly(14, b); 120 } 121 122 //关于y=x对称 123 void Symmetricaly_x(int a[]) 124 { 125 int i, b[28]; 126 127 for (i = 0; i < 28; i = i + 2) 128 { 129 //交换xy的坐标值 130 b[i + 1] = a[i]; 131 b[i] = a[i + 1]; 132 } 133 134 drawpoly(14, b); 135 } 136 137 //关于y=-x对称 138 void Symmetricaly__x(int a[]) 139 { 140 int i, b[28]; 141 142 for (i = 0; i < 28; i = i + 2) 143 { 144 //交换负xy的坐标值 145 b[i + 1] = -a[i]; 146 b[i] = -a[i + 1]; 147 } 148 149 drawpoly(14, b); 150 }