基于Weiler-Atherton剪裁布尔运算openGL实现-2D

#pragma once

#ifndef LINE_H
#define LINE_H
#include "Point2.h"
class Line
{
public:
	Line() {};
	~Line() {};
	Line(Point2 A, Point2 B)
		:First(A), Second(B)
	{};
	Point2 First, Second;

};

#endif

#pragma once

#ifndef POINT2_H
#define POINT2_H

class Point2 {
public:
	Point2() {};
	~Point2() {};

	Point2(double x1, double y1)
		:x(x1), y(y1)
	{};
	void set(double x1, double y1)
	{
		x = x1;
		y = y1;
	}
	double x, y;

	Point2 operator - (const Point2 v) const
	{
		return Point2(x - v.x, y - v.y);
	}

	Point2 operator + (const Point2 v) const
	{
		return Point2(x + v.x, y + v.y);
	}

	Point2 operator * (const double k) const
	{
		return Point2(x * k, y * k);
	}


	double dot(const Point2 v) const
	{
		return x*v.x + y*v.y;
	}

	Point2 Vertical() const
	{
		return Point2(y, -x);
	}
};

#endif // !POINT2_H

声明
/*
* 实现二维平面的布尔运算
* Union 并集 intersection 交集 Subtract 减
*/
#pragma once

#ifndef BOOLEAN_H
#define BOOLEAN_H

#include 
  
  
   
   
#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
        
#include 
      
      
        #include "Point2.h" #include "Line.h" using namespace std; class Boolean { public: Boolean(); ~Boolean(); void SetPLane(list 
       
  
   
         A, list 
        
   
    
          B); //输入list数据后 先计算出所有交点 并保存在AList BList void BoolIntersection(list 
         
           &PointInter, list 
          
            &Num); //输出交集的坐标 PointInter表示交集坐标 Num的值表示交集面的坐标个数 Num的size表示交集面的个数 void Display(); private: bool IsInsect(const Point2 A, const Point2 B, const Point2 C,const Point2 D, Point2 &Insect, double &t); // 求直线AB与线段CD交点 若有交点返回true struct InPoint { Point2 Point; int IsIn; //1 为交点 0 为端点 }; list 
           
             AList, BList; }; #endif // !BOOLEAN_H 
            
           
          
        
    
       
   
      
     
     
    
    
   
   
  
  

实现
#include"Boolean.h"

Boolean::Boolean()
{

}

Boolean::~Boolean()
{

}

void Boolean::SetPLane(list
  
  
  
   
   
    A, list
   
   
   
    
    
     B)
{
	list
    
    
    
     
     
     ::iterator ita, itb;
	vector
     
     
      
       t; //保存t
	Point2 tempP2;
	double tempt;
	for (ita = A.begin(); ita != A.end(); ita++
    
   
  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值