⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 这是《C#图形程序设计》这本书的源代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 二维图形几何变换及图形设计
{
	/// <summary>
	/// Class1 的摘要说明。
	/// </summary>
	public class Class1
	{
		public Class1()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		int xmax=360;
		int ymax=280;
		double[,] f=new double[3,3];
		double xx,yy;
		public System.Windows.Forms.PictureBox pictureBox1;
		public float scx(double xj)
		{
			int x;
			x=(int)(xj+xmax/2);
			return(x);
		}
		public float scy(double yj)
		{
			int y;
			y=ymax-(int)(yj+(ymax/2));
			return(y);
		}
		//平移变换
		public void parallel(double dx,double dy)
		{
			f[0,0]=1.0;
			f[0,1]=0.0;
			f[0,2]=0.0;
			f[1,0]=0.0;
			f[1,1]=1.0;
			f[1,2]=0.0;
			f[2,0]=dx;
			f[2,1]=dy;
			f[2,2]=1.0;
		}
		//旋转变换
		public void rotate(double theta)
		{
			double th;
			th=theta/180*3.1415927;
			f[0,0]=Math.Cos(th);
			f[0,1]=Math.Sin(th);
			f[0,2]=0.0;
			f[1,0]=-Math.Sin(th);
			f[1,1]=Math.Cos(th);
			f[1,2]=0.0;
			f[2,0]=0.0;
			f[2,1]=0.0;
			f[2,2]=1.0;
		}
		//比例变换
		public void scale(double s)
		{
			f[0,0]=s;
			f[0,1]=0.0;
			f[0,2]=0.0;
			f[1,0]=0.0;
			f[1,1]=s;
			f[1,2]=0.0;
			f[2,0]=0.0;
			f[2,1]=0.0;
			f[2,2]=1.0;
		}
		//任意直线对称变换
		public void taisho(float aa,float bb,float cc)
		{
			float r,p;
			r=bb*bb-aa*aa;
			p=aa*aa-bb*bb;
			f[0,0]=-r/p;
			f[0,1]=-2*aa*bb/p;
			f[0,2]=0.0;
			f[1,0]=-2*aa*bb/p;
			f[1,1]=-r/p;
			f[1,2]=0.0;
			f[2,0]=-2*aa*cc/p;
			f[2,1]=-2*bb*cc/p;
			f[2,2]=1.0;
		}
		//Y轴对称
		public void taicho_y()
		{
			f[0,0]=1.0;
			f[0,1]=0.0;
			f[0,2]=0.0;
			f[1,0]=0.0;
			f[1,1]=-1.0;
			f[1,2]=0.0;
			f[2,0]=0.0;
			f[2,1]=0.0;
			f[2,2]=1.0;
		}

		public void taisho_y()
		{
			f[0,0]=-1.0;
			f[0,1]=0.0;
			f[0,2]=0.0;
			f[1,0]=0.0;
			f[1,1]=1.0;
			f[1,2]=0.0;
			f[2,0]=0.0;
			f[2,1]=0.0;
			f[2,2]=1.0;
		}
		//原点对称
		public void taisho_0()
		{
			f[0,0]=-1.0;
			f[0,1]=0.0;
			f[0,2]=0.0;
			f[1,0]=0.0;
			f[1,1]=-1.0;
			f[1,2]=0.0;
			f[2,0]=0.0;
			f[2,1]=0.0;
			f[2,2]=1.0;
		}

		public void taisho_xy()
		{
			f[0,0]=0.0;
			f[0,1]=1.0;
			f[0,2]=0.0;
			f[1,0]=1.0;
			f[1,1]=0.0;
			f[1,2]=0.0;
			f[2,0]=0.0;
			f[2,1]=0.0;
			f[2,2]=1.0;
		}
		public void axis()
		{
			Graphics g=pictureBox1.CreateGraphics();
			Color red=Color.FromKnownColor(KnownColor.Red);
			Pen pen=new Pen(Color.Chocolate);
			Pen pen1=new Pen(Color.Blue);
			g.DrawLine(pen,scx(0.0),scy(-ymax/2),scx(0.0),scy(ymax/2));
			g.DrawLine(pen1,scx(-xmax/2),scy(0.0),scx(xmax/2),scy(0.0));
		}
		public void tuoq(double a,double b)
		{
			f[0,0]=1.0;
			f[0,1]=b;
			f[0,2]=1.0;
			f[1,0]=a;
			f[1,1]=1.0;
			f[1,2]=0.0;
			f[2,0]=0.0;
			f[2,1]=0.0;
			f[2,2]=1.0;
		}
		public double affinex(double x,double y,double d)
		{
			xx=x*f[0,0]+y*f[1,0]+d*f[2,0];
			return(xx);
		}
		public double affiney(double x,double y,double d)
		{
			yy=x*f[0,1]+y*f[1,1]+d*f[2,1];
			return(yy);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -