OpenGL-学习之路-简单多边形显示 及 多边形类型判断 和 凹多边形的切割 (待更新)

这篇博客介绍了使用OpenGL进行多边形处理的方法,包括通过鼠标输入创建多边形数据结构,判断多边形类型,以及对凹多边形进行切割。作者在实践中发现程序对复杂多边形处理存在错误,计划进一步学习和更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

内容:

1.鼠标输入顶点,建立多边形数据结构。

2.判断多边形类型。

3.若是凹多边形,则切割成多个凸多边形。


首先,多边形数据结构:

#include <iostream>
using namespace std;

struct PolygonNode
{
public:
	int x;  //点x坐标
	int y;  //点y坐标
	int SeqNode;  //记录序号,从零开始

	PolygonNode * next;

	PolygonNode(int xPos, int yPos)
	{
		x = xPos;
		y = yPos;
		next = NULL;
	}
	~PolygonNode();

};

class Polygon
{
public:
	PolygonNode *first;
	PolygonNode *last;
	PolygonNode *current;

	int numNode;  //记录顶点数
	int concave;  //记录第几个顶点为凹角

	Polygon()
	{
		last = current = NULL;
	}

	void InsertNode(int xPos, int yPos);  //插入顶点
	void RemoveNode();  //移除顶点
	void pCurrentGoto(int n);  //current指针指向第n个顶点
	int CrossProduct(int n);  //向量叉乘,从第n个顶点起始的向量叉乘于下一个向量
};

void Polygon::InsertNode(int xPos, int yPos)
{
	PolygonNode * newNode = new PolygonNode(xPos, yPos);
	//空链表
	if (current == NULL)
	{
		first = last = current = newNode;
		numNode = 1;
		last->SeqNode = 0;
	}
	else
	{
		last->next = newNode;
		newNode->next = first;
		last = newNode;
		last->SeqNode = numNode;
		numNode++;
	}
};

void Polygon::RemoveNode()
{
	//链头
	if (current == first)
	{
		first = last->next = current->next;
		current->next = NULL;
		current = first;
	}
	//链尾
	else if (current == last)
	{
		pCurrentGoto(current->SeqNode - 1);
		cur
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值