计算机图形 直线的裁剪代码,计算机图形学直线裁剪代码.doc

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值