using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace LineCut_Cohen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//定义钻石参数
int x0 = 100;
int y0 = 100;
int n = 13;
int r = 50;
int[] x;
int[] y;
//
//计算钻石顶点 by tiantian
//
public void ZuanShi()
{
float t = (float)3.14159 * 2 / n;
x = new int[n];
y = new int[n];
for (int i = 0; i < n; i++)
{
x[i] = (int)(r * Math.Cos(i * t) + x0);
y[i] = (int)(r * Math.Sin(i * t) + y0);
}
}
//
//计算点(x,y)的编码
//
void CompOutCode(int x, int y, Rectangle rect, OutCode outCode)
{
outCode.all = 0;
outCode.top = outCode.bottom = 0;
if (y < rect.Top) //rect类的top相当于我们惯常用的坐标系的bottom by:tiantian
{
outCode.bottom = 1;
outCode.all += 1;
}
else if (y > rect.Bottom)//rect类的bottom相当于我们惯常用的坐标系的top by:tiantian
{
outCode.top = 1;
outCode.all += 1;
}
outCode.right = outCode.left = 0;
if (x > rect.Right)
{
outCode.right = 1;
outCode.all += 1;
}
else if (x < rect.Left)
{
outCode.left = 1;
outCode.all += 1;
}
}
//
//线段裁剪,p0(x0,y0),p1(x1,y1)为待裁剪线断,rect为裁剪窗口
//
bool ChoenSutherlandLineClip(ref int x0, ref int y0, ref int x1, ref int y1, Rectangle rect) //这里必须是引用传递!by:tiantian
{
Boolean accept, done;
OutCode outCode0 = new OutCode();
Ou